public async Task <ViewModels.Users.UserProfileViewModel> GetUserProfile(string userId) { var user = await _userService.GetUserByIdWithSettings(userId); var currentUser = await _userService.GetUserByName(HttpContext.User.Identity.Name); var result = new ViewModels.Users.UserProfileViewModel(user); result.IsFriend = user.Friends.Any(x => x.FirstUserId == currentUser.Id || x.SecondUserId == currentUser.Id); var userPrivacySetting = user.Settings.FirstOrDefault(x => x.Setting == UserSetting.ProfileVisibility); if (userPrivacySetting != null && userId != currentUser.Id.ToString()) { if (userPrivacySetting.PrivacySetting == PrivacySetting.Friends) { if (!result.IsFriend) { result.IsPrivate = true; } } } if (!result.IsFriend) { result.InvitedByMe = await _friendsInvitationService.IsInvitedByUser(user, currentUser); if (!result.InvitedByMe) { result.InvitedMe = await _friendsInvitationService.IsInvitedByUser(currentUser, user); } } var mainImage = await _userImageService.GetMainImage(user); if (mainImage != null) { result.MainImage = new ViewModels.Users.UserImageViewModel(mainImage); } return(result); }
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); }