diff options
Diffstat (limited to 'src/DevHive.Services/Services/UserService.cs')
| -rw-r--r-- | src/DevHive.Services/Services/UserService.cs | 23 |
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); ; |
