public async Task <IActionResult> AddProfilePic(string id)
        {
            UserToReturnWithCounters user = await _userApiAccess.GetUser(_userId);

            Post post = await _postApiAccess.GetPost(_userId, id);

            string imagePath = _imagesManager.ResizeImage(post.ImagePath, 50, 50);
            await _userApiAccess.AddProfilePic(_userId.ToString(), imagePath);

            return(RedirectToAction(nameof(Profile)));
        }
Example #2
0
        public async Task <ActionResult <PostWithCommentToAdd> > ShowComments(string userId, string postId)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(userId) || string.IsNullOrWhiteSpace(postId))
                {
                    return(NotFound());
                }
                Post post = await _postApiAccess.GetPost(userId, postId);

                if (post == null)
                {
                    return(NotFound());
                }

                ViewData["currentUserProfileId"] = userId.ToString();
                ViewData["loggedUserId"]         = _userId.ToString();

                List <BasicUserData> user = new List <BasicUserData>();
                foreach (PostComment userPost in post.PostComments)
                {
                    user.Add(_mapper.Map <BasicUserData>(await _userApiAccess.GetUser(userPost.FromWho.ToString())));
                }
                PostWithCommentToAdd postToReturn = new PostWithCommentToAdd
                {
                    Post  = post,
                    Text  = string.Empty,
                    Users = user,
                    User  = _mapper.Map <BasicUserData>(await _userApiAccess.GetUser(userId))
                };

                return(View(postToReturn));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Something went wrong during loading comments on post: {postId} by user {_userId}");
                _logger.LogError($"Exception info: {ex.Message} {ex.Source}");
                return(RedirectToAction("Error", "Error"));
            }
        }