public async Task <IActionResult> AddComment(PostViewModel model) { if (!ModelState.IsValid) { return(RedirectToAction("ImageValidationError", "Home")); } var post = await postRepository.GetByIdAsync(model.Id); var user = await userManager.GetUserAsync(User); var comment = new Comment() { User = user, Post = post, Content = model.NewCommentContent, CreatedOn = DateTime.UtcNow }; if (model.CommentPhoto != null) { comment.PhotoPath = await imageStorage.SaveAsync(model.CommentPhoto); } await postRepository.AddCommentAsync(comment); return(RedirectToAction("Post")); }
public async Task UpdateProfilePicture(ProfilePictureViewModel model) { model.Picture = await _imageStorage.SaveAsync(model); var updateCommand = _mapper.Map <UpdateProfilePictureCommand>(model); await Bus.SendCommand(updateCommand); }
public async Task <IActionResult> UploadFile([FromBody] ProfilePictureViewModel file) { if (!file.FileType.Contains("image")) { NotifyError("Type", "Invalid filetype"); return(Response()); } var user = await _userManager.GetUserAsync(User); user.Picture = await _imageStorage.SaveAsync(file); await _userManager.UpdateAsync(user); return(Response(user.Picture)); }
public async Task <IActionResult> Edit(UserUpdateViewModel model) { if (!ModelState.IsValid) { return(RedirectToAction("Error", "Home")); } var user = await userManager.GetUserAsync(User); user.UserName = model.Name; user.Bio = model.Bio; if (model.Image != null) { user.PhotoPath = await imageStorage.SaveAsync(model.Image); } await userRepository.UpdateAsync(user); return(RedirectToAction("Profile")); }