aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Data/Repositories
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2021-01-29 20:39:07 +0200
committertranstrike <transtrike@gmail.com>2021-01-29 20:39:07 +0200
commitb38d6693476917972345397298b534af2b8b8f78 (patch)
tree5e62376cf693a7233cec4ab341f658be5d9c4ec2 /src/DevHive.Data/Repositories
parent2417df3ff2939b67695b80905f301ef53c905260 (diff)
downloadDevHive-b38d6693476917972345397298b534af2b8b8f78.tar
DevHive-b38d6693476917972345397298b534af2b8b8f78.tar.gz
DevHive-b38d6693476917972345397298b534af2b8b8f78.zip
File Upload implemented; Post Layers adapted to File Uploading
Diffstat (limited to 'src/DevHive.Data/Repositories')
-rw-r--r--src/DevHive.Data/Repositories/BaseRepository.cs6
-rw-r--r--src/DevHive.Data/Repositories/PostRepository.cs16
2 files changed, 19 insertions, 3 deletions
diff --git a/src/DevHive.Data/Repositories/BaseRepository.cs b/src/DevHive.Data/Repositories/BaseRepository.cs
index f1e6673..cac802e 100644
--- a/src/DevHive.Data/Repositories/BaseRepository.cs
+++ b/src/DevHive.Data/Repositories/BaseRepository.cs
@@ -34,10 +34,10 @@ namespace DevHive.Data.Repositories
public virtual async Task<bool> EditAsync(Guid id, TEntity newEntity)
{
var entry = this._context.Entry(newEntity);
- if (entry.State == EntityState.Detached)
- this._context.Attach(newEntity);
+ if (entry.State == EntityState.Detached)
+ this._context.Attach(newEntity);
- entry.State = EntityState.Modified;
+ entry.State = EntityState.Modified;
return await this.SaveChangesAsync(_context);
}
diff --git a/src/DevHive.Data/Repositories/PostRepository.cs b/src/DevHive.Data/Repositories/PostRepository.cs
index 67988f2..78b40cd 100644
--- a/src/DevHive.Data/Repositories/PostRepository.cs
+++ b/src/DevHive.Data/Repositories/PostRepository.cs
@@ -1,4 +1,6 @@
using System;
+using System.Collections.Generic;
+using System.Linq;
using System.Threading.Tasks;
using DevHive.Data.Interfaces.Repositories;
using DevHive.Data.Models;
@@ -30,6 +32,11 @@ namespace DevHive.Data.Repositories
.FirstOrDefaultAsync(p => p.Creator.Id == creatorId &&
p.TimeCreated == timeCreated);
}
+
+ public async Task<List<string>> GetFileUrls(Guid postId)
+ {
+ return (await this.GetByIdAsync(postId)).FileUrls;
+ }
#endregion
#region Validations
@@ -39,6 +46,15 @@ namespace DevHive.Data.Repositories
.AsNoTracking()
.AnyAsync(r => r.Id == postId);
}
+
+ public async Task<bool> DoesPostHaveFiles(Guid postId)
+ {
+ return await this._context.Posts
+ .AsNoTracking()
+ .Where(x => x.Id == postId)
+ .Select(x => x.FileUrls)
+ .AnyAsync();
+ }
#endregion
}
}