aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Data/Repositories/RoleRepository.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/DevHive.Data/Repositories/RoleRepository.cs')
-rw-r--r--src/DevHive.Data/Repositories/RoleRepository.cs58
1 files changed, 9 insertions, 49 deletions
diff --git a/src/DevHive.Data/Repositories/RoleRepository.cs b/src/DevHive.Data/Repositories/RoleRepository.cs
index ca3fb8b..156792d 100644
--- a/src/DevHive.Data/Repositories/RoleRepository.cs
+++ b/src/DevHive.Data/Repositories/RoleRepository.cs
@@ -1,83 +1,43 @@
using System;
using System.Threading.Tasks;
-using DevHive.Common.Models.Misc;
using DevHive.Data.Interfaces.Repositories;
using DevHive.Data.Models;
using Microsoft.EntityFrameworkCore;
namespace DevHive.Data.Repositories
{
- public class RoleRepository : IRoleRepository
+ public class RoleRepository : BaseRepository<Role>, IRoleRepository
{
private readonly DevHiveContext _context;
public RoleRepository(DevHiveContext context)
+ :base(context)
{
this._context = context;
}
- //Create
- public async Task<bool> AddAsync(Role entity)
- {
- await this._context
- .Set<Role>()
- .AddAsync(entity);
-
- return await RepositoryMethods.SaveChangesAsync(this._context);
- }
-
- //Read
- public async Task<Role> GetByIdAsync(Guid id)
- {
- return await this._context
- .Set<Role>()
- .FindAsync(id);
- }
-
+ #region Read
public async Task<Role> GetByNameAsync(string name)
{
- return await this._context
- .Set<Role>()
+ return await this._context.Roles
.FirstOrDefaultAsync(x => x.Name == name);
}
+ #endregion
- //Update
- public async Task<bool> EditAsync(Role newEntity)
- {
- Role role = await this.GetByIdAsync(newEntity.Id);
-
- this._context
- .Entry(role)
- .CurrentValues
- .SetValues(newEntity);
-
- return await RepositoryMethods.SaveChangesAsync(this._context);
- }
-
- //Delete
- public async Task<bool> DeleteAsync(Role entity)
- {
- this._context
- .Set<Role>()
- .Remove(entity);
-
- return await RepositoryMethods.SaveChangesAsync(this._context);
- }
-
+ #region Validations
public async Task<bool> DoesNameExist(string name)
{
- return await this._context
- .Set<Role>()
+ return await this._context.Roles
.AsNoTracking()
.AnyAsync(r => r.Name == name);
}
public async Task<bool> DoesRoleExist(Guid id)
{
- return await this._context
- .Set<Role>()
+ return await this._context.Roles
.AsNoTracking()
.AnyAsync(r => r.Id == id);
}
+ #endregion
}
}