diff options
Diffstat (limited to 'src/DevHive.Data/Repositories/LanguageRepository.cs')
| -rw-r--r-- | src/DevHive.Data/Repositories/LanguageRepository.cs | 55 |
1 files changed, 31 insertions, 24 deletions
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<Language> { private readonly DevHiveContext _context; @@ -16,7 +16,8 @@ namespace DevHive.Data.Repositories this._context = context; } - //Create + #region Create + public async Task<bool> 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<Language> GetByIdAsync(Guid id) { return await this._context .Set<Language>() .FindAsync(id); } + #endregion - public async Task<bool> DoesLanguageNameExist(string languageName) - { - return await this._context - .Set<Language>() - .AsNoTracking() - .AnyAsync(r => r.Name == languageName); - } - - public async Task<bool> DoesLanguageExist(Guid id) - { - return await this._context - .Set<Language>() - .AsNoTracking() - .AnyAsync(r => r.Id == id); - } + #region Update - //Update public async Task<bool> EditAsync(Language newEntity) { - this._context - .Set<Language>() - .Update(newEntity); + this._context + .Set<Language>() + .Update(newEntity); return await RepositoryMethods.SaveChangesAsync(this._context); } + #endregion + + #region Delete - //Delete public async Task<bool> 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<bool> DoesLanguageNameExistAsync(string languageName) + { + return await this._context.Languages + .AnyAsync(r => r.Name == languageName); + } + + public async Task<bool> DoesLanguageExistAsync(Guid id) + { + return await this._context.Languages + .AnyAsync(r => r.Id == id); + } + #endregion } }
\ No newline at end of file |
