From 8282f6c3f89ee65be155d453ddd705892b07628e Mon Sep 17 00:00:00 2001 From: transtrike Date: Sun, 28 Mar 2021 19:21:49 +0300 Subject: ProfilePic saved in User fixed --- src/Services/DevHive.Services.Models/User/UserServiceModel.cs | 2 +- src/Services/DevHive.Services/Services/ProfilePictureService.cs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'src/Services') diff --git a/src/Services/DevHive.Services.Models/User/UserServiceModel.cs b/src/Services/DevHive.Services.Models/User/UserServiceModel.cs index ad4e553..f48c703 100644 --- a/src/Services/DevHive.Services.Models/User/UserServiceModel.cs +++ b/src/Services/DevHive.Services.Models/User/UserServiceModel.cs @@ -8,7 +8,7 @@ namespace DevHive.Services.Models.User { public class UserServiceModel : BaseUserServiceModel { - public string ProfilePictureURL { get; set; } = new("/assets/icons/tabler-icon-user.svg"); + public string ProfilePictureURL { get; set; } = new(string.Empty); public HashSet Roles { get; set; } = new(); diff --git a/src/Services/DevHive.Services/Services/ProfilePictureService.cs b/src/Services/DevHive.Services/Services/ProfilePictureService.cs index 7093818..0a4c824 100644 --- a/src/Services/DevHive.Services/Services/ProfilePictureService.cs +++ b/src/Services/DevHive.Services/Services/ProfilePictureService.cs @@ -41,6 +41,7 @@ namespace DevHive.Services.Services await ValidateUserExistsAsync(profilePictureServiceModel.UserId); User user = await this._userRepository.GetByIdAsync(profilePictureServiceModel.UserId); + // if (user.ProfilePicture.PictureURL != ProfilePicture.DefaultURL) if (user.ProfilePicture.Id != Guid.Empty) { List file = new() { user.ProfilePicture.PictureURL }; @@ -76,11 +77,14 @@ namespace DevHive.Services.Services string picUrl = (await this._cloudinaryService.UploadFilesToCloud(file))[0]; ProfilePicture profilePic = new() { PictureURL = picUrl }; + User user = await this._userRepository.GetByIdAsync(profilePictureServiceModel.UserId); + profilePic.UserId = user.Id; + profilePic.User = user; + bool success = await this._profilePictureRepository.AddAsync(profilePic); if (!success) throw new ArgumentException("Unable to upload picture!"); - User user = await this._userRepository.GetByIdAsync(profilePictureServiceModel.UserId); user.ProfilePicture = profilePic; bool userProfilePicAlter = await this._userRepository.EditAsync(user.Id, user); -- cgit v1.2.3