public async Task <ViewResult> Me() { GetPrivateUserModel privateModel = await Mediator.Send(new GetAuthenticatedUserQuery()); var pagingParams = new PagingParams { PageNumber = 1, PageSize = 10 }; var articles = await Mediator.Send(new GetArticlesByIdsQuery(privateModel.ArticleIds, pagingParams)); var comments = await Mediator.Send(new GetCommentsByIdsQuery(privateModel.CommentIds, pagingParams)); string imageDataURL = ""; if (privateModel.ProfileImageId > 0) { GetImageModel img = await Mediator.Send(new GetImageByIdQuery(privateModel.ProfileImageId)); imageDataURL = _imageDataHelper.ConvertImageDataToDataUrl(img.ImageData, img.ContentType); } var model = new PrivateUserDetailsViewModel { User = privateModel, ArticlePage = new FrontendPage <GetArticleModel>(articles), CommentPage = new FrontendPage <GetCommentModel>(comments), ImageDataUrl = imageDataURL }; return(View(model)); }
public async Task <ActionResult> Details(int id, PagingParams pagingParams) { GetBoardModel getBoardModel = await Mediator.Send(new GetBoardQuery(id)); var boardArticles = await Mediator.Send(new GetArticlesByIdsQuery(getBoardModel.ArticleIds, pagingParams)); var moderatorPagingParams = new PagingParams { PageNumber = 1, PageSize = 5 }; var boardModerators = await Mediator.Send(new GetPublicUsersByIdsQuery(getBoardModel.ModeratorIds, moderatorPagingParams)); string imageDataURL = ""; if (getBoardModel.BoardImageId > 0) { GetImageModel img = await Mediator.Send(new GetImageByIdQuery(getBoardModel.BoardImageId)); imageDataURL = _imageDataHelper.ConvertImageDataToDataUrl(img.ImageData, img.ContentType); } var model = new BoardDetailsViewModel { Board = getBoardModel, ArticlePage = new FrontendPage <GetArticleModel>(boardArticles), Moderators = new FrontendPage <GetPublicUserModel>(boardModerators), ImageDataUrl = imageDataURL }; return(View(model)); }
public async Task <ViewResult> Details(int id, PagingParams pagingParams) { var articleModel = await Mediator.Send(new GetArticleQuery(id)); var getArticleCommentsQuery = new GetCommentsByIdsQuery(articleModel.CommentIds, pagingParams); var articleComments = await getArticleCommentsQuery.DefaultIfExceptionAsync(Mediator); var getBoardQuery = new GetBoardQuery(articleModel.BoardId); GetBoardModel board = await getBoardQuery.DefaultIfExceptionAsync(Mediator); var getUserQuery = new GetPublicUserQuery(articleModel.UserId); GetPublicUserModel user = await getUserQuery.DefaultIfExceptionAsync(Mediator); var privateUser = await new GetAuthenticatedUserQuery().DefaultIfExceptionAsync(Mediator); var loggedIn = privateUser != null && privateUser.Id != 0; var savedArticle = loggedIn && privateUser.SavedArticles.Contains(id); var wroteArticle = loggedIn && privateUser.ArticleIds.Contains(id); string imageDataURL = ""; if (articleModel.AssociatedImageId > 0) { GetImageModel img = await Mediator.Send(new GetImageByIdQuery(articleModel.AssociatedImageId)); imageDataURL = _imageDataHelper.ConvertImageDataToDataUrl(img.ImageData, img.ContentType); } var viewModel = new ArticleDetailsViewModel { Article = articleModel, Board = board, CommentPage = new FrontendPage <GetCommentModel>(articleComments), LoggedIn = loggedIn, User = user, UserSavedArticle = savedArticle, UserWroteArticle = wroteArticle, AssociatedImageDataUrl = imageDataURL }; return(View(viewModel)); }