aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Data
diff options
context:
space:
mode:
Diffstat (limited to 'src/DevHive.Data')
-rw-r--r--src/DevHive.Data/Models/Comment.cs4
-rw-r--r--src/DevHive.Data/Models/Post.cs21
-rw-r--r--src/DevHive.Data/Repositories/CommentRepository.cs62
-rw-r--r--src/DevHive.Data/Repositories/LanguageRepository.cs2
-rw-r--r--src/DevHive.Data/Repositories/PostRepository.cs107
-rw-r--r--src/DevHive.Data/Repositories/RoleRepository.cs2
-rw-r--r--src/DevHive.Data/Repositories/TechnologyRepository.cs2
-rw-r--r--src/DevHive.Data/Repositories/UserRepository.cs2
8 files changed, 134 insertions, 68 deletions
diff --git a/src/DevHive.Data/Models/Comment.cs b/src/DevHive.Data/Models/Comment.cs
index f949a42..8cf848f 100644
--- a/src/DevHive.Data/Models/Comment.cs
+++ b/src/DevHive.Data/Models/Comment.cs
@@ -4,8 +4,8 @@ namespace DevHive.Data.Models
public class Comment : IModel
{
public Guid Id { get; set; }
- public Guid UserId { get; set; }
+ public Guid IssuerId { get; set; }
public string Message { get; set; }
- public DateTime Date { get; set; }
+ public DateTime TimeCreated { get; set; }
}
} \ No newline at end of file
diff --git a/src/DevHive.Data/Models/Post.cs b/src/DevHive.Data/Models/Post.cs
new file mode 100644
index 0000000..a5abf12
--- /dev/null
+++ b/src/DevHive.Data/Models/Post.cs
@@ -0,0 +1,21 @@
+using System;
+using System.ComponentModel.DataAnnotations.Schema;
+
+namespace DevHive.Data.Models
+{
+ [Table("Posts")]
+ public class Post
+ {
+ public Guid Id { get; set; }
+
+ public Guid IssuerId { get; set; }
+
+ public DateTime TimeCreated { get; set; }
+
+ public string Message { get; set; }
+
+ //public File[] Files { get; set; }
+
+ public Comment[] Comments { get; set; }
+ }
+}
diff --git a/src/DevHive.Data/Repositories/CommentRepository.cs b/src/DevHive.Data/Repositories/CommentRepository.cs
deleted file mode 100644
index 5a4ef17..0000000
--- a/src/DevHive.Data/Repositories/CommentRepository.cs
+++ /dev/null
@@ -1,62 +0,0 @@
-using System;
-using System.Threading.Tasks;
-using Data.Models.Interfaces.Database;
-using DevHive.Common.Models.Data;
-using DevHive.Data.Models;
-using Microsoft.EntityFrameworkCore;
-
-namespace DevHive.Data.Repositories
-{
- public class CommentRepository : IRepository<Comment>
- {
- private readonly DevHiveContext _context;
-
- public CommentRepository(DevHiveContext context)
- {
- this._context = context;
- }
-
- public async Task<bool> AddAsync(Comment entity)
- {
- await this._context
- .Set<Comment>()
- .AddAsync(entity);
-
- return await RepositoryMethods.SaveChangesAsync(this._context);
- }
-
- public async Task<Comment> GetByIdAsync(Guid id)
- {
- return await this._context
- .Set<Comment>()
- .FindAsync(id);
- }
-
-
- public async Task<bool> EditAsync(Comment newEntity)
- {
- this._context
- .Set<Comment>()
- .Update(newEntity);
-
- return await RepositoryMethods.SaveChangesAsync(this._context);
- }
-
- public async Task<bool> DoesCommentExist(Guid id)
- {
- return await this._context
- .Set<Comment>()
- .AsNoTracking()
- .AnyAsync(r => r.Id == id);
- }
-
- public async Task<bool> DeleteAsync(Comment entity)
- {
- this._context
- .Set<Comment>()
- .Remove(entity);
-
- return await RepositoryMethods.SaveChangesAsync(this._context);
- }
- }
-} \ No newline at end of file
diff --git a/src/DevHive.Data/Repositories/LanguageRepository.cs b/src/DevHive.Data/Repositories/LanguageRepository.cs
index 6e3a2e3..1ab870a 100644
--- a/src/DevHive.Data/Repositories/LanguageRepository.cs
+++ b/src/DevHive.Data/Repositories/LanguageRepository.cs
@@ -1,7 +1,7 @@
using System;
using System.Threading.Tasks;
using Data.Models.Interfaces.Database;
-using DevHive.Common.Models.Data;
+using DevHive.Common.Models.Misc;
using DevHive.Data.Models;
using Microsoft.EntityFrameworkCore;
diff --git a/src/DevHive.Data/Repositories/PostRepository.cs b/src/DevHive.Data/Repositories/PostRepository.cs
new file mode 100644
index 0000000..5dfee0b
--- /dev/null
+++ b/src/DevHive.Data/Repositories/PostRepository.cs
@@ -0,0 +1,107 @@
+using System;
+using System.Threading.Tasks;
+using Data.Models.Interfaces.Database;
+using DevHive.Common.Models.Misc;
+using DevHive.Data.Models;
+using Microsoft.EntityFrameworkCore;
+
+namespace DevHive.Data.Repositories
+{
+ public class PostRepository : IRepository<Post>
+ {
+ private readonly DevHiveContext _context;
+
+ public PostRepository(DevHiveContext context)
+ {
+ this._context = context;
+ }
+
+ //Create
+ public async Task<bool> AddAsync(Post post)
+ {
+ await this._context
+ .Set<Post>()
+ .AddAsync(post);
+
+ return await RepositoryMethods.SaveChangesAsync(this._context);
+ }
+
+ public async Task<bool> AddCommentAsync(Comment entity)
+ {
+ await this._context
+ .Set<Comment>()
+ .AddAsync(entity);
+
+ return await RepositoryMethods.SaveChangesAsync(this._context);
+ }
+
+ //Read
+ public async Task<Post> GetByIdAsync(Guid id)
+ {
+ return await this._context
+ .Set<Post>()
+ .FindAsync(id);
+ }
+
+ public async Task<Comment> GetCommentByIdAsync(Guid id)
+ {
+ return await this._context
+ .Set<Comment>()
+ .FindAsync(id);
+ }
+
+ //Update
+ public async Task<bool> EditAsync(Post newPost)
+ {
+ this._context
+ .Set<Post>()
+ .Update(newPost);
+
+ return await RepositoryMethods.SaveChangesAsync(this._context);
+ }
+
+ public async Task<bool> EditCommentAsync(Comment newEntity)
+ {
+ this._context
+ .Set<Comment>()
+ .Update(newEntity);
+
+ return await RepositoryMethods.SaveChangesAsync(this._context);
+ }
+
+ //Delete
+ public async Task<bool> DeleteAsync(Post post)
+ {
+ this._context
+ .Set<Post>()
+ .Remove(post);
+
+ return await RepositoryMethods.SaveChangesAsync(this._context);
+ }
+
+ public async Task<bool> DeleteCommentAsync(Comment entity)
+ {
+ this._context
+ .Set<Comment>()
+ .Remove(entity);
+
+ return await RepositoryMethods.SaveChangesAsync(this._context);
+ }
+
+ public async Task<bool> DoesPostExist(Guid postId)
+ {
+ return await this._context
+ .Set<Post>()
+ .AsNoTracking()
+ .AnyAsync(r => r.Id == postId);
+ }
+
+ public async Task<bool> DoesCommentExist(Guid id)
+ {
+ return await this._context
+ .Set<Comment>()
+ .AsNoTracking()
+ .AnyAsync(r => r.Id == id);
+ }
+ }
+} \ No newline at end of file
diff --git a/src/DevHive.Data/Repositories/RoleRepository.cs b/src/DevHive.Data/Repositories/RoleRepository.cs
index 1d6f2da..fd04866 100644
--- a/src/DevHive.Data/Repositories/RoleRepository.cs
+++ b/src/DevHive.Data/Repositories/RoleRepository.cs
@@ -1,7 +1,7 @@
using System;
using System.Threading.Tasks;
using Data.Models.Interfaces.Database;
-using DevHive.Common.Models.Data;
+using DevHive.Common.Models.Misc;
using DevHive.Data.Models;
using Microsoft.EntityFrameworkCore;
diff --git a/src/DevHive.Data/Repositories/TechnologyRepository.cs b/src/DevHive.Data/Repositories/TechnologyRepository.cs
index e2e4257..935582c 100644
--- a/src/DevHive.Data/Repositories/TechnologyRepository.cs
+++ b/src/DevHive.Data/Repositories/TechnologyRepository.cs
@@ -3,7 +3,7 @@ using System.Threading.Tasks;
using Data.Models.Interfaces.Database;
using DevHive.Data.Models;
using Microsoft.EntityFrameworkCore;
-using DevHive.Common.Models.Data;
+using DevHive.Common.Models.Misc;
namespace DevHive.Data.Repositories
{
diff --git a/src/DevHive.Data/Repositories/UserRepository.cs b/src/DevHive.Data/Repositories/UserRepository.cs
index d2a8830..5600451 100644
--- a/src/DevHive.Data/Repositories/UserRepository.cs
+++ b/src/DevHive.Data/Repositories/UserRepository.cs
@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Data.Models.Interfaces.Database;
-using DevHive.Common.Models.Data;
+using DevHive.Common.Models.Misc;
using DevHive.Data.Models;
using Microsoft.EntityFrameworkCore;