aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Services/Services
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2021-01-17 16:26:32 +0200
committertranstrike <transtrike@gmail.com>2021-01-17 16:26:32 +0200
commitf0398cf1b7e6477bbd184e7509a1030054fc1926 (patch)
tree90a5ff56f96972e55f31e4339818aa0af0323b73 /src/DevHive.Services/Services
parent8f6a50566a069c782482a167f601e6eca9588e73 (diff)
downloadDevHive-f0398cf1b7e6477bbd184e7509a1030054fc1926.tar
DevHive-f0398cf1b7e6477bbd184e7509a1030054fc1926.tar.gz
DevHive-f0398cf1b7e6477bbd184e7509a1030054fc1926.zip
Fix lang naming
Diffstat (limited to 'src/DevHive.Services/Services')
-rw-r--r--src/DevHive.Services/Services/UserService.cs23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/DevHive.Services/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs
index 3dd030a..b549b1c 100644
--- a/src/DevHive.Services/Services/UserService.cs
+++ b/src/DevHive.Services/Services/UserService.cs
@@ -131,21 +131,28 @@ namespace DevHive.Services.Services
#region Update
- public async Task<UserServiceModel> UpdateUser(UpdateUserServiceModel updateModel)
+ public async Task<UserServiceModel> UpdateUser(UpdateUserServiceModel updateUserServiceModel)
{
- if (!await this._userRepository.DoesUserExistAsync(updateModel.Id))
+ if (!await this._userRepository.DoesUserExistAsync(updateUserServiceModel.Id))
throw new ArgumentException("User does not exist!");
- if (!this._userRepository.DoesUserHaveThisUsername(updateModel.Id, updateModel.UserName)
- && await this._userRepository.DoesUsernameExistAsync(updateModel.UserName))
+ if (!this._userRepository.DoesUserHaveThisUsername(updateUserServiceModel.Id, updateUserServiceModel.UserName)
+ && await this._userRepository.DoesUsernameExistAsync(updateUserServiceModel.UserName))
throw new ArgumentException("Username already exists!");
- await this.ValidateUserCollections(updateModel);
+ await this.ValidateUserCollections(updateUserServiceModel);
- User user = this._userMapper.Map<User>(updateModel);
- bool result = await this._userRepository.EditAsync(user);
+ //Query proper lang, tech and role and insert the full class in updateUserServiceModel
+ List<Language> properLanguages = new();
+ foreach (UpdateUserCollectionServiceModel lang in updateUserServiceModel.Languages)
+ properLanguages.Add(await this._languageRepository.GetByNameAsync(lang.Name));
- if (!result)
+ User user = this._userMapper.Map<User>(updateUserServiceModel);
+ user.Languages = properLanguages;
+
+ bool success = await this._userRepository.EditAsync(user);
+
+ if (!success)
throw new InvalidOperationException("Unable to edit user!");
return this._userMapper.Map<UserServiceModel>(user); ;