Example #1
0
        public async Task <ViewModels.Users.UserProfileViewModel> UpdateProfile([FromBody] UserProfileViewModel model)
        {
            var currentUser = await _userService.GetUserByName(HttpContext.User.Identity.Name);

            if (!currentUser.Id.ToString().Equals(model.Id))
            {
                throw new InvalidOperationException("You can't edit other user profile info.");
            }

            var user = await _userProfileService.UpdateProfile(model);

            var mainImage = await _userImageService.GetMainImage(user);

            var result = new ViewModels.Users.UserProfileViewModel(user);

            if (mainImage != null)
            {
                result.MainImage = new ViewModels.Users.UserImageViewModel(mainImage);
            }

            return(result);
        }