diff options
Diffstat (limited to 'src/DevHive.Data')
| -rw-r--r-- | src/DevHive.Data/DevHive.Data.csproj | 4 | ||||
| -rw-r--r-- | src/DevHive.Data/Repositories/LanguageRepository.cs | 14 | ||||
| -rw-r--r-- | src/DevHive.Data/Repositories/RoleRepository.cs | 20 | ||||
| -rw-r--r-- | src/DevHive.Data/Repositories/UserRepository.cs | 13 |
4 files changed, 27 insertions, 24 deletions
diff --git a/src/DevHive.Data/DevHive.Data.csproj b/src/DevHive.Data/DevHive.Data.csproj index d472d1c..c1e1592 100644 --- a/src/DevHive.Data/DevHive.Data.csproj +++ b/src/DevHive.Data/DevHive.Data.csproj @@ -16,4 +16,8 @@ </PackageReference>
</ItemGroup>
+ <ItemGroup> + <ProjectReference Include="..\DevHive.Common\DevHive.Common.csproj" /> + </ItemGroup>
+
</Project>
diff --git a/src/DevHive.Data/Repositories/LanguageRepository.cs b/src/DevHive.Data/Repositories/LanguageRepository.cs index 08efd18..a33bd5b 100644 --- a/src/DevHive.Data/Repositories/LanguageRepository.cs +++ b/src/DevHive.Data/Repositories/LanguageRepository.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; using Data.Models.Interfaces.Database; +using DevHive.Common.Models.Data; using DevHive.Data.Models; using Microsoft.EntityFrameworkCore; @@ -22,7 +23,7 @@ namespace DevHive.Data.Repositories .Set<Language>() .AddAsync(entity); - return await this.SaveChangesAsync(); + return await RepositoryMethods.SaveChangesAsync(this._context); } //Read @@ -56,7 +57,7 @@ namespace DevHive.Data.Repositories .Set<Language>() .Update(newEntity); - return await this.SaveChangesAsync(); + return await RepositoryMethods.SaveChangesAsync(this._context); } //Delete @@ -66,14 +67,7 @@ namespace DevHive.Data.Repositories .Set<Language>() .Remove(entity); - return await this.SaveChangesAsync(); + return await RepositoryMethods.SaveChangesAsync(this._context); } - - private async Task<bool> SaveChangesAsync() - { - int result = await this._context.SaveChangesAsync(); - - return result >= 0; - } } }
\ No newline at end of file diff --git a/src/DevHive.Data/Repositories/RoleRepository.cs b/src/DevHive.Data/Repositories/RoleRepository.cs index 9b6cf14..ad9bda0 100644 --- a/src/DevHive.Data/Repositories/RoleRepository.cs +++ b/src/DevHive.Data/Repositories/RoleRepository.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; using Data.Models.Interfaces.Database; +using DevHive.Common.Models.Data; using DevHive.Data.Models; using Microsoft.EntityFrameworkCore; @@ -16,13 +17,13 @@ namespace DevHive.Data.Repositories } //Create - public async Task AddAsync(Role entity) + public async Task<bool> AddAsync(Role entity) { await this._context .Set<Role>() .AddAsync(entity); - await this._context.SaveChangesAsync(); + return await RepositoryMethods.SaveChangesAsync(this._context); } //Read @@ -35,23 +36,26 @@ namespace DevHive.Data.Repositories } //Update - public async Task EditAsync(Role newEntity) + public async Task<bool> EditAsync(Role newEntity) { + Role role = await this.GetByIdAsync(newEntity.Id); + this._context - .Set<Role>() - .Update(newEntity); + .Entry(role) + .CurrentValues + .SetValues(newEntity); - await this._context.SaveChangesAsync(); + return await RepositoryMethods.SaveChangesAsync(this._context); } //Delete - public async Task DeleteAsync(Role entity) + public async Task<bool> DeleteAsync(Role entity) { this._context .Set<Role>() .Remove(entity); - await this._context.SaveChangesAsync(); + return await RepositoryMethods.SaveChangesAsync(this._context); } public async Task<bool> DoesNameExist(string name) diff --git a/src/DevHive.Data/Repositories/UserRepository.cs b/src/DevHive.Data/Repositories/UserRepository.cs index 714218d..f5a074b 100644 --- a/src/DevHive.Data/Repositories/UserRepository.cs +++ b/src/DevHive.Data/Repositories/UserRepository.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Data.Models.Interfaces.Database; +using DevHive.Common.Models.Data; using DevHive.Data.Models; using Microsoft.EntityFrameworkCore; @@ -18,13 +19,13 @@ namespace DevHive.Data.Repositories } //Create - public async Task AddAsync(User entity) + public async Task<bool> AddAsync(User entity) { await this._context .Set<User>() .AddAsync(entity); - await this._context.SaveChangesAsync(); + return await RepositoryMethods.SaveChangesAsync(this._context); } //Read @@ -51,7 +52,7 @@ namespace DevHive.Data.Repositories } //Update - public async Task EditAsync(User newEntity) + public async Task<bool> EditAsync(User newEntity) { User user = await this.GetByIdAsync(newEntity.Id); @@ -60,17 +61,17 @@ namespace DevHive.Data.Repositories .CurrentValues .SetValues(newEntity); - await this._context.SaveChangesAsync(); + return await RepositoryMethods.SaveChangesAsync(this._context); } //Delete - public async Task DeleteAsync(User entity) + public async Task<bool> DeleteAsync(User entity) { this._context .Set<User>() .Remove(entity); - await this._context.SaveChangesAsync(); + return await RepositoryMethods.SaveChangesAsync(this._context); } //Validations |
