aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Data/Repositories/LanguageRepository.cs
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2021-01-12 13:16:39 +0200
committertranstrike <transtrike@gmail.com>2021-01-12 13:16:39 +0200
commit11bd1d9a9760c7bc6a601d78b3d89ec9028647a2 (patch)
tree4e74a8fc10a07f58e11d3612373b17a246ec2868 /src/DevHive.Data/Repositories/LanguageRepository.cs
parentb14dc0fe3e5ecfca3a7e780a17627f823d59246c (diff)
downloadDevHive-11bd1d9a9760c7bc6a601d78b3d89ec9028647a2.tar
DevHive-11bd1d9a9760c7bc6a601d78b3d89ec9028647a2.tar.gz
DevHive-11bd1d9a9760c7bc6a601d78b3d89ec9028647a2.zip
Language layers refactored; User implements adding & removing Languages; Migrations added
Diffstat (limited to 'src/DevHive.Data/Repositories/LanguageRepository.cs')
-rw-r--r--src/DevHive.Data/Repositories/LanguageRepository.cs55
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