aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2021-01-22 22:39:23 +0200
committertranstrike <transtrike@gmail.com>2021-01-22 22:39:23 +0200
commit1c91e52c91a1a94616eca632ffdd930ffeb616f4 (patch)
tree64cd9a66608c0f2579cf44d0bcd82b87b6c15d63
parentb24a160bbdb4df529a932b392d7c0d75013b9319 (diff)
downloadDevHive-1c91e52c91a1a94616eca632ffdd930ffeb616f4.tar
DevHive-1c91e52c91a1a94616eca632ffdd930ffeb616f4.tar.gz
DevHive-1c91e52c91a1a94616eca632ffdd930ffeb616f4.zip
Kamen's proposal in Update() at BaseRepo merged
-rw-r--r--src/DevHive.Data/Interfaces/Repositories/IRepository.cs2
-rw-r--r--src/DevHive.Data/Repositories/BaseRepository.cs15
-rw-r--r--src/DevHive.Services/Services/LanguageService.cs2
-rw-r--r--src/DevHive.Services/Services/PostService.cs2
-rw-r--r--src/DevHive.Services/Services/RoleService.cs2
-rw-r--r--src/DevHive.Services/Services/TechnologyService.cs2
-rw-r--r--src/DevHive.Services/Services/UserService.cs2
7 files changed, 11 insertions, 16 deletions
diff --git a/src/DevHive.Data/Interfaces/Repositories/IRepository.cs b/src/DevHive.Data/Interfaces/Repositories/IRepository.cs
index d9f7c7a..0d11cd3 100644
--- a/src/DevHive.Data/Interfaces/Repositories/IRepository.cs
+++ b/src/DevHive.Data/Interfaces/Repositories/IRepository.cs
@@ -13,7 +13,7 @@ namespace DevHive.Data.Repositories.Interfaces
Task<TEntity> GetByIdAsync(Guid id);
//Modify Entity from database
- Task<bool> EditAsync(TEntity newEntity);
+ Task<bool> EditAsync(Guid id, TEntity newEntity);
//Delete Entity from database
Task<bool> DeleteAsync(TEntity entity);
diff --git a/src/DevHive.Data/Repositories/BaseRepository.cs b/src/DevHive.Data/Repositories/BaseRepository.cs
index dabb35b..0a97ac1 100644
--- a/src/DevHive.Data/Repositories/BaseRepository.cs
+++ b/src/DevHive.Data/Repositories/BaseRepository.cs
@@ -32,18 +32,13 @@ namespace DevHive.Data.Repositories
.FindAsync(id);
}
- public virtual async Task<bool> EditAsync(TEntity newEntity)
+ public virtual async Task<bool> EditAsync(Guid id, TEntity newEntity)
{
- // Old way(backup)
- // User user = await this._context.Users
- // .FirstOrDefaultAsync(x => x.Id == entity.Id);
-
- // this._context.Update(user);
- // this._context.Entry(entity).CurrentValues.SetValues(entity);
-
+ TEntity currEnt = await this.GetByIdAsync(id);
this._context
- .Set<TEntity>()
- .Update(newEntity);
+ .Entry(currEnt)
+ .CurrentValues
+ .SetValues(newEntity);
return await this.SaveChangesAsync(_context);
}
diff --git a/src/DevHive.Services/Services/LanguageService.cs b/src/DevHive.Services/Services/LanguageService.cs
index 89df654..a602d43 100644
--- a/src/DevHive.Services/Services/LanguageService.cs
+++ b/src/DevHive.Services/Services/LanguageService.cs
@@ -66,7 +66,7 @@ namespace DevHive.Services.Services
throw new ArgumentException("Language name already exists in our data base!");
Language lang = this._languageMapper.Map<Language>(languageServiceModel);
- return await this._languageRepository.EditAsync(lang);
+ return await this._languageRepository.EditAsync(languageServiceModel.Id, lang);
}
#endregion
diff --git a/src/DevHive.Services/Services/PostService.cs b/src/DevHive.Services/Services/PostService.cs
index 9503b8a..4757937 100644
--- a/src/DevHive.Services/Services/PostService.cs
+++ b/src/DevHive.Services/Services/PostService.cs
@@ -84,7 +84,7 @@ namespace DevHive.Services.Services
throw new ArgumentException("Comment does not exist!");
Post post = this._postMapper.Map<Post>(postServiceModel);
- return await this._postRepository.EditAsync(post);
+ return await this._postRepository.EditAsync(postServiceModel.Id, post);
}
public async Task<bool> UpdateComment(UpdateCommentServiceModel commentServiceModel)
diff --git a/src/DevHive.Services/Services/RoleService.cs b/src/DevHive.Services/Services/RoleService.cs
index 3ebb7c8..896946d 100644
--- a/src/DevHive.Services/Services/RoleService.cs
+++ b/src/DevHive.Services/Services/RoleService.cs
@@ -56,7 +56,7 @@ namespace DevHive.Services.Services
throw new ArgumentException("Role name already exists!");
Role role = this._roleMapper.Map<Role>(updateRoleServiceModel);
- return await this._roleRepository.EditAsync(role);
+ return await this._roleRepository.EditAsync(updateRoleServiceModel.Id, role);
}
public async Task<bool> DeleteRole(Guid id)
diff --git a/src/DevHive.Services/Services/TechnologyService.cs b/src/DevHive.Services/Services/TechnologyService.cs
index 88ed702..c879ad7 100644
--- a/src/DevHive.Services/Services/TechnologyService.cs
+++ b/src/DevHive.Services/Services/TechnologyService.cs
@@ -60,7 +60,7 @@ namespace DevHive.Services.Services
throw new ArgumentException("Technology name already exists!");
Technology technology = this._technologyMapper.Map<Technology>(updateTechnologyServiceModel);
- bool result = await this._technologyRepository.EditAsync(technology);
+ bool result = await this._technologyRepository.EditAsync(updateTechnologyServiceModel.Id, technology);
return result;
}
diff --git a/src/DevHive.Services/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs
index 217154e..533f422 100644
--- a/src/DevHive.Services/Services/UserService.cs
+++ b/src/DevHive.Services/Services/UserService.cs
@@ -152,7 +152,7 @@ namespace DevHive.Services.Services
updateUserServiceModel.Technologies.RemoveWhere(x => x.Id == Guid.Empty);
User user = this._userMapper.Map<User>(updateUserServiceModel);
- bool successful = await this._userRepository.EditAsync(user);
+ bool successful = await this._userRepository.EditAsync(updateUserServiceModel.Id, user);
if (!successful)
throw new InvalidOperationException("Unable to edit user!");