aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Data/Repositories/RoleRepository.cs
diff options
context:
space:
mode:
authorDanail Dimitrov <danaildimitrov321@gmail.com>2021-01-21 20:53:13 +0200
committerDanail Dimitrov <danaildimitrov321@gmail.com>2021-01-21 20:53:13 +0200
commitbd67366f41a25e868053bf3c71ed2917f25a8a6f (patch)
treea5754fcf564b09a42f884a58d2fd707e44ab8044 /src/DevHive.Data/Repositories/RoleRepository.cs
parent5e5e2eb2edef88840edbb072597f81f8da3ae929 (diff)
parent78884a445ec3f21d06e5859d03009b7d71bbb784 (diff)
downloadDevHive-bd67366f41a25e868053bf3c71ed2917f25a8a6f.tar
DevHive-bd67366f41a25e868053bf3c71ed2917f25a8a6f.tar.gz
DevHive-bd67366f41a25e868053bf3c71ed2917f25a8a6f.zip
fixing edit methods in repos
Diffstat (limited to 'src/DevHive.Data/Repositories/RoleRepository.cs')
-rw-r--r--src/DevHive.Data/Repositories/RoleRepository.cs33
1 files changed, 16 insertions, 17 deletions
diff --git a/src/DevHive.Data/Repositories/RoleRepository.cs b/src/DevHive.Data/Repositories/RoleRepository.cs
index 684fbd7..25549bf 100644
--- a/src/DevHive.Data/Repositories/RoleRepository.cs
+++ b/src/DevHive.Data/Repositories/RoleRepository.cs
@@ -1,6 +1,5 @@
using System;
using System.Threading.Tasks;
-using DevHive.Common.Models.Misc;
using DevHive.Data.Interfaces.Repositories;
using DevHive.Data.Models;
using Microsoft.EntityFrameworkCore;
@@ -16,32 +15,31 @@ namespace DevHive.Data.Repositories
this._context = context;
}
- //Create
+ #region Create
public async Task<bool> AddAsync(Role entity)
{
- await this._context
- .Set<Role>()
+ await this._context.Roles
.AddAsync(entity);
return await this.SaveChangesAsync(this._context);
}
+ #endregion
- //Read
+ #region Read
public async Task<Role> GetByIdAsync(Guid id)
{
- return await this._context
- .Set<Role>()
+ return await this._context.Roles
.FindAsync(id);
}
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
+ #region Update
public async Task<bool> EditAsync(Role newEntity)
{
Role role = await this.GetByIdAsync(newEntity.Id);
@@ -53,31 +51,32 @@ namespace DevHive.Data.Repositories
return await this.SaveChangesAsync(this._context);
}
+ #endregion
- //Delete
+ #region Delete
public async Task<bool> DeleteAsync(Role entity)
{
- this._context
- .Set<Role>()
+ this._context.Roles
.Remove(entity);
return await this.SaveChangesAsync(this._context);
}
+ #endregion
+ #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
}
}