public async Task <IActionResult> AddPost([FromForm] UserPostsWithPostToAdd post) { try { if (post.NewPost != null) { string imagePath = null, fullImagePath = null; if (post.NewPost.Picture != null) { (imagePath, fullImagePath) = await _imagesManager.SaveImage(post.NewPost.Picture); } await _postApiAccess.AddPost(_userId, new PostToAdd { ImageFullPath = fullImagePath, Text = post.NewPost.Text, WhenAdded = DateTime.Now, ImagePath = imagePath }); } return(RedirectToAction(nameof(Index), "Profile")); } catch (Exception ex) { _logger.LogError($"Something went wrong during adding post by user {_userId}"); _logger.LogError($"Exception info: {ex.Message} {ex.Source}"); return(RedirectToAction("Error", "Error")); } }
public async Task <ActionResult <UserPostsWithPostToAdd> > Profile() { try { List <Post> posts = await _postApiAccess.GetPosts(_userId); posts.Reverse(); BasicUserData currentUser = _mapper.Map <BasicUserData> (await _userApiAccess.GetUser(_userId)); UserPostsWithPostToAdd userToView = new UserPostsWithPostToAdd() { NewPost = new PostWithImageToAdd() }; foreach (var post in posts) { userToView.UserWithPosts.Add(new BasicUserWithPost { Post = post, User = currentUser }); } userToView.BasicUser = currentUser; ViewData["userId"] = _userId.ToString(); return(View("Index", userToView)); } catch (Exception ex) { _logger.LogError($"Something went wrong during loading user: {_userId} profile"); _logger.LogError($"Exception info: {ex.Message} {ex.Source}"); return(RedirectToAction("Error", "Error")); } }
public async Task <ActionResult <UserPostsWithPostToAdd> > ViewProfile(Guid friendId) { try { List <Post> posts = await _postApiAccess.GetPosts(friendId.ToString()); posts.Reverse(); var user = _mapper.Map <BasicUserData>(await _userApiAccess.GetUser(friendId.ToString())); UserPostsWithPostToAdd userToView = new UserPostsWithPostToAdd() { NewPost = null }; foreach (var post in posts) { userToView.UserWithPosts.Add(new BasicUserWithPost { Post = post, User = user }); } ViewData["userId"] = _userId.ToString(); return(View(userToView)); } catch (Exception ex) { _logger.LogError($"Something went wrong during loading user profile: {friendId} by user {_userId}"); _logger.LogError($"Exception info: {ex.Message} {ex.Source}"); return(RedirectToAction("Error", "Error")); } }