Esempio n. 1
0
        public IActionResult ViewPost(Guid Id)
        {
            try
            {
                var CurrentUser = _context.Users.Find(userManager.GetUserId(User));
                if (CurrentUser is null)
                {
                    throw new DomainException(ErrorMessages.NotSignedIn);
                }

                var existingAccount = _userStore.GetByIdentityUserId(CurrentUser.Id);
                if (existingAccount.AccountStatus.Equals(Status.Suspended))
                {
                    signInManager.SignOutAsync();
                }

                var existingPost = _postStore.ViewPost(Id);

                if (existingPost is null)
                {
                    throw new DomainException(ErrorMessages.PostDoesNotExist);
                }

                var OwnerOfPost = _userStore.GetByIdentityUserId(existingPost.UserId);

                GetPostDetailsQuery GetPostDetailsQuery = new GetPostDetailsQuery(CurrentUser, OwnerOfPost,
                                                                                  existingPost, _userStore, _commentStore, existingAccount);

                return(View(GetPostDetailsQuery.Handle()));
            }
            catch (DomainException ex)
            {
                _logger.LogError(ex.Message);
                if (ex.Message.Equals(ErrorMessages.NotSignedIn))
                {
                    return(RedirectToAction(ActionName.Login, ControllerName.Accounts));
                }

                return(RedirectToAction(ActionName.NotFound, ControllerName.Accounts));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(RedirectToAction(ActionName.ServerError, ControllerName.Accounts));
            }
        }