From 11bd1d9a9760c7bc6a601d78b3d89ec9028647a2 Mon Sep 17 00:00:00 2001 From: transtrike Date: Tue, 12 Jan 2021 13:16:39 +0200 Subject: Language layers refactored; User implements adding & removing Languages; Migrations added --- .../Repositories/LanguageRepository.cs | 55 ++++++++++++---------- 1 file changed, 31 insertions(+), 24 deletions(-) (limited to 'src/DevHive.Data/Repositories/LanguageRepository.cs') diff --git a/src/DevHive.Data/Repositories/LanguageRepository.cs b/src/DevHive.Data/Repositories/LanguageRepository.cs index 243192a..5d8217a 100644 --- a/src/DevHive.Data/Repositories/LanguageRepository.cs +++ b/src/DevHive.Data/Repositories/LanguageRepository.cs @@ -1,13 +1,13 @@ using System; +using System.Linq; using System.Threading.Tasks; using DevHive.Common.Models.Misc; using DevHive.Data.Models; -using DevHive.Data.Repositories.Contracts; using Microsoft.EntityFrameworkCore; namespace DevHive.Data.Repositories { - public class LanguageRepository : ILanguageRepository + public class LanguageRepository : IRepository { private readonly DevHiveContext _context; @@ -16,7 +16,8 @@ namespace DevHive.Data.Repositories this._context = context; } - //Create + #region Create + public async Task AddAsync(Language entity) { await this._context @@ -25,42 +26,32 @@ namespace DevHive.Data.Repositories return await RepositoryMethods.SaveChangesAsync(this._context); } + #endregion + + #region Read - //Read public async Task GetByIdAsync(Guid id) { return await this._context .Set() .FindAsync(id); } + #endregion - public async Task DoesLanguageNameExist(string languageName) - { - return await this._context - .Set() - .AsNoTracking() - .AnyAsync(r => r.Name == languageName); - } - - public async Task DoesLanguageExist(Guid id) - { - return await this._context - .Set() - .AsNoTracking() - .AnyAsync(r => r.Id == id); - } + #region Update - //Update public async Task EditAsync(Language newEntity) { - this._context - .Set() - .Update(newEntity); + this._context + .Set() + .Update(newEntity); return await RepositoryMethods.SaveChangesAsync(this._context); } + #endregion + + #region Delete - //Delete public async Task DeleteAsync(Language entity) { this._context @@ -69,5 +60,21 @@ namespace DevHive.Data.Repositories return await RepositoryMethods.SaveChangesAsync(this._context); } + #endregion + + #region Validations + + public async Task DoesLanguageNameExistAsync(string languageName) + { + return await this._context.Languages + .AnyAsync(r => r.Name == languageName); + } + + public async Task DoesLanguageExistAsync(Guid id) + { + return await this._context.Languages + .AnyAsync(r => r.Id == id); + } + #endregion } } \ No newline at end of file -- cgit v1.2.3