public async Task <ActionResult <UserPostsWithPostToAdd> > Index()
        {
            try
            {
                List <Post> posts = await _postApiAccess.GetLatestPosts(_userId);

                UserPostsWithPostToAdd userToView = new UserPostsWithPostToAdd()
                {
                    NewPost = new PostWithImageToAdd()
                };

                foreach (var post in posts)
                {
                    userToView.UserWithPosts.Add(new BasicUserWithPost
                    {
                        Post = post,
                        User = _mapper.Map <BasicUserData>(await _userApiAccess.GetUser(post.UserId.ToString()))
                    });
                }
                userToView.BasicUser = _mapper.Map <BasicUserData>(await _userApiAccess.GetUser(_userId.ToString()));
                ViewData["userId"]   = _userId.ToString();
                return(View(userToView));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Something went wrong during loading user: {_userId} main view page");
                _logger.LogError($"Exception info: {ex.Message} {ex.Source}");
                return(RedirectToAction("Error", "Error"));
            }
        }
        public async Task <ActionResult <PagedList <Message> > > Conversation([FromQuery] string friendId)
        {
            var s = friendId.ToString();

            try
            {
                if (!string.IsNullOrWhiteSpace(s))
                {
                    PagedList <Message> messages = await _messageApiService.GetMessagesWith(_userId, s, new PaginationParams { PageNumber = 0, PageSize = 10 });

                    var friend = await _userApiAccess.GetUser(s);

                    ViewData["friendId"] = friendId;
                    ViewData["userId"]   = _userId.ToString();
                    if (friend != null)
                    {
                        ViewData["friendFirstName"] = friend.FirstName;
                        ViewData["friendLastName"]  = friend.LastName;
                    }
                    return(View(messages));
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Something went wrong during loading messages with: {friendId} by user {_userId}");
                _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"));
            }
        }
        public async Task <IViewComponentResult> InvokeAsync()
        {
            if (string.IsNullOrWhiteSpace(_userId))
            {
                throw new ArgumentNullException(nameof(_userId));
            }
            UserToReturnWithCounters bacisUserCounters = await _userApiAccess.GetUser(_userId);

            return(View(bacisUserCounters));
        }
Exemple #5
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"));
            }
        }