예제 #1
0
        public async Task <IActionResult> UpdateImage([FromForm] UpdateProfileImageDTO profileImageDto)
        {
            _logger.LogInfo($"Updating profile with username {profileImageDto.UserId}...");

            if (profileImageDto.ProfileImage == null)
            {
                return(BadRequest());
            }

            await this._profileService.UpdateProfileImage(profileImageDto.UserId, profileImageDto);

            _logger.LogInfo($"Profile with id: {profileImageDto.UserId} successfully updated.");

            return(NoContent());
        }
예제 #2
0
        public async Task UpdateProfileImage(string id, UpdateProfileImageDTO profile, bool skipMethodForTest = false)
        {
            var dbUser = this._userRepository
                         .All()
                         .Single(x => x.Id == id);


            string profileImage = "";

            if (!skipMethodForTest)
            {
                profileImage = this._imageService.AddToCloudinaryAndReturnProfileImageUrl(profile.ProfileImage);
            }

            if (profile.ProfileImage == null)
            {
                throw new InvalidOperationException("Invalid image file.");
            }

            dbUser.ProfileImage = profileImage;

            var activity = new UserActivity
            {
                Action       = "Update profile image",
                RegisteredOn = DateTime.Now,
                UserId       = id,
            };

            if (!skipMethodForTest)
            {
                await this._hubContext.Clients.All.UpdateProfileImage(dbUser.ProfileImage);
            }

            await this._userActivityRepository.AddAsync(activity);

            dbUser.Activity.Add(activity);

            await this._userRepository.SaveChangesAsync();
        }