aboutsummaryrefslogtreecommitdiff
path: root/src/Data/DevHive.Data/Repositories/RoleRepository.cs
diff options
context:
space:
mode:
authorKamen Mladenov <kamen.d.mladenov@protonmail.com>2021-04-09 19:51:35 +0300
committerGitHub <noreply@github.com>2021-04-09 19:51:35 +0300
commit233f38915ba0079079233eff55434ef349c05c45 (patch)
tree6c5f69017865bcab87355e910c87339453da1406 /src/Data/DevHive.Data/Repositories/RoleRepository.cs
parentf4a70c6430db923af9fa9958a11c2d6612cb52cc (diff)
parenta992357efcf1bc1ece81b95ecee5e05a0b73bfdc (diff)
downloadDevHive-main.tar
DevHive-main.tar.gz
DevHive-main.zip
Merge pull request #28 from Team-Kaleidoscope/devHEADv0.2mainheroku/main
Second stage: Complete
Diffstat (limited to 'src/Data/DevHive.Data/Repositories/RoleRepository.cs')
-rw-r--r--src/Data/DevHive.Data/Repositories/RoleRepository.cs56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/Data/DevHive.Data/Repositories/RoleRepository.cs b/src/Data/DevHive.Data/Repositories/RoleRepository.cs
new file mode 100644
index 0000000..99e0634
--- /dev/null
+++ b/src/Data/DevHive.Data/Repositories/RoleRepository.cs
@@ -0,0 +1,56 @@
+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 RoleManager<Role> _roleManager;
+
+ public RoleRepository(DevHiveContext context, RoleManager<Role> roleManager)
+ : base(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._roleManager.FindByNameAsync(name);
+ }
+ #endregion
+
+ public override async Task<bool> EditAsync(Guid id, Role newEntity)
+ {
+ newEntity.Id = id;
+ IdentityResult result = await this._roleManager.UpdateAsync(newEntity);
+
+ return result.Succeeded;
+ }
+
+ #region Validations
+ public async Task<bool> DoesNameExist(string name)
+ {
+ return await this._roleManager.RoleExistsAsync(name);
+ }
+
+ public async Task<bool> DoesRoleExist(Guid id)
+ {
+ return await this._roleManager.Roles.AnyAsync(r => r.Id == id);
+ }
+ #endregion
+ }
+}