From 58178d5036f65bb4896fea08bbec9388a8ab8c20 Mon Sep 17 00:00:00 2001 From: transtrike Date: Thu, 21 Jan 2021 19:41:28 +0200 Subject: Code cleanup & consistency --- src/DevHive.Data/Repositories/RoleRepository.cs | 33 ++++++++++++------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'src/DevHive.Data/Repositories/RoleRepository.cs') 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 AddAsync(Role entity) { - await this._context - .Set() + await this._context.Roles .AddAsync(entity); return await this.SaveChangesAsync(this._context); } + #endregion - //Read + #region Read public async Task GetByIdAsync(Guid id) { - return await this._context - .Set() + return await this._context.Roles .FindAsync(id); } public async Task GetByNameAsync(string name) { - return await this._context - .Set() + return await this._context.Roles .FirstOrDefaultAsync(x => x.Name == name); } + #endregion - //Update + #region Update public async Task 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 DeleteAsync(Role entity) { - this._context - .Set() + this._context.Roles .Remove(entity); return await this.SaveChangesAsync(this._context); } + #endregion + #region Validations public async Task DoesNameExist(string name) { - return await this._context - .Set() + return await this._context.Roles .AsNoTracking() .AnyAsync(r => r.Name == name); } public async Task DoesRoleExist(Guid id) { - return await this._context - .Set() + return await this._context.Roles .AsNoTracking() .AnyAsync(r => r.Id == id); } + #endregion } } -- cgit v1.2.3