diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-01-17 15:30:09 +0200 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-01-17 15:30:09 +0200 |
| commit | 8f6a50566a069c782482a167f601e6eca9588e73 (patch) | |
| tree | f3732aab96e3e9be3180acbe5d0b07216629170c /src/DevHive.Services/Services/UserService.cs | |
| parent | 8d1d0b40d56f90248f948e474330258bf57cf0b6 (diff) | |
| download | DevHive-8f6a50566a069c782482a167f601e6eca9588e73.tar DevHive-8f6a50566a069c782482a167f601e6eca9588e73.tar.gz DevHive-8f6a50566a069c782482a167f601e6eca9588e73.zip | |
User update now updates languages, roles and friends
Diffstat (limited to 'src/DevHive.Services/Services/UserService.cs')
| -rw-r--r-- | src/DevHive.Services/Services/UserService.cs | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/DevHive.Services/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs index 1dc1bd5..3dd030a 100644 --- a/src/DevHive.Services/Services/UserService.cs +++ b/src/DevHive.Services/Services/UserService.cs @@ -13,6 +13,7 @@ using System.Collections.Generic; using DevHive.Common.Models.Identity; using DevHive.Services.Interfaces; using DevHive.Data.Interfaces.Repositories; +using DevHive.Services.Models.Language; namespace DevHive.Services.Services { @@ -139,7 +140,7 @@ namespace DevHive.Services.Services && await this._userRepository.DoesUsernameExistAsync(updateModel.UserName)) throw new ArgumentException("Username already exists!"); - //Add validations for everything else + await this.ValidateUserCollections(updateModel); User user = this._userMapper.Map<User>(updateModel); bool result = await this._userRepository.EditAsync(user); @@ -149,6 +150,36 @@ namespace DevHive.Services.Services return this._userMapper.Map<UserServiceModel>(user); ; } + + private async Task ValidateUserCollections(UpdateUserServiceModel updateUserServiceModel) + { + // Friends + foreach (UpdateUserCollectionServiceModel friend in updateUserServiceModel.Friends) + { + User returnedFriend = await this._userRepository.GetByUsernameAsync(friend.Name); + + if (default(User) == returnedFriend) + throw new ArgumentException($"User {friend.Name} does not exist!"); + } + + // Languages + foreach (UpdateUserCollectionServiceModel language in updateUserServiceModel.Languages) + { + Language returnedLanguage = await this._languageRepository.GetByNameAsync(language.Name); + + if (default(Language) == returnedLanguage) + throw new ArgumentException($"Language {language.Name} does not exist!"); + } + + // Technology + foreach (UpdateUserCollectionServiceModel technology in updateUserServiceModel.Technologies) + { + Technology returnedTechnology = await this._technologyRepository.GetByNameAsync(technology.Name); + + if (default(Technology) == returnedTechnology) + throw new ArgumentException($"Technology {technology.Name} does not exist!"); + } + } #endregion #region Delete |
