aboutsummaryrefslogtreecommitdiff
path: root/src/Data/DevHive.Data/Repositories/RoleRepository.cs
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2021-02-16 18:07:51 +0200
committertranstrike <transtrike@gmail.com>2021-02-16 18:07:51 +0200
commit72502154725594cf31878aa944f4bc9d9f3521a3 (patch)
tree6ea1f475f35fba320b32664084d4c39e2d084e49 /src/Data/DevHive.Data/Repositories/RoleRepository.cs
parenta2ca63701b71eed2ffa3fff6de16b9babe8bba08 (diff)
downloadDevHive-72502154725594cf31878aa944f4bc9d9f3521a3.tar
DevHive-72502154725594cf31878aa944f4bc9d9f3521a3.tar.gz
DevHive-72502154725594cf31878aa944f4bc9d9f3521a3.zip
UserManager&RoleManager logic moved to Repo; Password hashing and validation moved to Repo and using ASPNET Core hashing methods; Added Migrations; Fixed Roles not added to user
Diffstat (limited to 'src/Data/DevHive.Data/Repositories/RoleRepository.cs')
-rw-r--r--src/Data/DevHive.Data/Repositories/RoleRepository.cs37
1 files changed, 19 insertions, 18 deletions
diff --git a/src/Data/DevHive.Data/Repositories/RoleRepository.cs b/src/Data/DevHive.Data/Repositories/RoleRepository.cs
index 7d07c1b..99e0634 100644
--- a/src/Data/DevHive.Data/Repositories/RoleRepository.cs
+++ b/src/Data/DevHive.Data/Repositories/RoleRepository.cs
@@ -2,53 +2,54 @@ using System;
using System.Threading.Tasks;
using DevHive.Data.Interfaces;
using DevHive.Data.Models;
+using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
namespace DevHive.Data.Repositories
{
public class RoleRepository : BaseRepository<Role>, IRoleRepository
{
- private readonly DevHiveContext _context;
+ private readonly RoleManager<Role> _roleManager;
- public RoleRepository(DevHiveContext context)
+ public RoleRepository(DevHiveContext context, RoleManager<Role> roleManager)
: base(context)
{
- this._context = context;
+ this._roleManager = roleManager;
}
+ #region Create
+ public override async Task<bool> AddAsync(Role entity)
+ {
+ IdentityResult result = await this._roleManager.CreateAsync(entity);
+
+ return result.Succeeded;
+ }
+ #endregion
+
#region Read
public async Task<Role> GetByNameAsync(string name)
{
- return await this._context.Roles
- .FirstOrDefaultAsync(x => x.Name == name);
+ return await this._roleManager.FindByNameAsync(name);
}
#endregion
public override async Task<bool> EditAsync(Guid id, Role newEntity)
{
- Role role = await this.GetByIdAsync(id);
-
- this._context
- .Entry(role)
- .CurrentValues
- .SetValues(newEntity);
+ newEntity.Id = id;
+ IdentityResult result = await this._roleManager.UpdateAsync(newEntity);
- return await this.SaveChangesAsync();
+ return result.Succeeded;
}
#region Validations
public async Task<bool> DoesNameExist(string name)
{
- return await this._context.Roles
- .AsNoTracking()
- .AnyAsync(r => r.Name == name);
+ return await this._roleManager.RoleExistsAsync(name);
}
public async Task<bool> DoesRoleExist(Guid id)
{
- return await this._context.Roles
- .AsNoTracking()
- .AnyAsync(r => r.Id == id);
+ return await this._roleManager.Roles.AnyAsync(r => r.Id == id);
}
#endregion
}