public async Task <IViewComponentResult> InvokeAsync(GetArticleModel articleModel, string imageDataUrl, bool displayText = false) { // TODO: test with deleted boards var getBoardQuery = new GetBoardQuery(articleModel.BoardId); GetBoardModel board = await getBoardQuery.DefaultIfExceptionAsync(_mediator); // TODO: returns null, which throws exception in view, if user is deleted var getuserQuery = new GetPublicUserQuery(articleModel.UserId); GetPublicUserModel user = await getuserQuery.DefaultIfExceptionAsync(_mediator); string jwt = _apiJwtManager.GetToken(); bool loggedIn = false; bool saved = false; bool userUpvoted = false; bool userDownvoted = false; bool userCreatedArticle = false; try { var loggedInUser = await _mediator.Send(new GetAuthenticatedUserQuery()); if (loggedInUser != null) { loggedIn = true; } saved = loggedInUser.SavedArticles.Any(articleId => articleId == articleModel.Id); userUpvoted = loggedInUser.LikedArticles.Any(articleId => articleId == articleModel.Id); userDownvoted = loggedInUser.DislikedArticles.Any(articleId => articleId == articleModel.Id); userCreatedArticle = loggedInUser.ArticleIds.Any(articleId => articleId == articleModel.Id); } catch { } var viewModel = new ArticleCardViewModel { Article = articleModel, Board = board, User = user, Jwt = jwt, LoggedIn = loggedIn, Saved = saved, UserUpvoted = userUpvoted, UserDownvoted = userDownvoted, UserCreatedArticle = userCreatedArticle, ImageDataUrl = imageDataUrl, DisplayText = displayText, BaseUrl = _baseUrl }; return(View(viewModel)); }
public async Task <IViewComponentResult> InvokeAsync(GetCommentModel commentModel) { // TODO: test with deleted boards var getBoardQuery = new GetBoardQuery(commentModel.BoardId); var board = await getBoardQuery.DefaultIfExceptionAsync(_mediator); var getArticleQuery = new GetArticleQuery(commentModel.ParentArticleId); GetArticleModel parentArticle = await getArticleQuery.DefaultIfExceptionAsync(_mediator); var getCommentQuery = new GetCommentQuery(commentModel.ParentCommentId); GetCommentModel parentComment = await getCommentQuery.DefaultIfExceptionAsync(_mediator); // TODO: will most likely return null when user is deleted var getUserQuery = new GetPublicUserQuery(commentModel.UserId); GetPublicUserModel user = await getUserQuery.DefaultIfExceptionAsync(_mediator); string jwt = _apiJwtManager.GetToken(); bool loggedIn = false; bool saved = false; bool userUpvoted = false; bool userDownvoted = false; bool userCreatedComment = false; try { var loggedInUser = await _mediator.Send(new GetAuthenticatedUserQuery()); if (loggedInUser != null) { loggedIn = true; } saved = loggedInUser.SavedComments.Any(commentId => commentId == commentModel.Id); userUpvoted = loggedInUser.LikedComments.Any(commentId => commentId == commentModel.Id); userDownvoted = loggedInUser.DislikedComments.Any(commentId => commentId == commentModel.Id); userCreatedComment = commentModel.UserId == loggedInUser.Id; } catch (System.Exception) { loggedIn = false; } var model = new CommentCardViewModel { Comment = commentModel, Board = board, ParentArticle = parentArticle, ParentComment = parentComment, User = user, Jwt = jwt, LoggedIn = loggedIn, Saved = saved, UserUpvoted = userUpvoted, UserDownvoted = userDownvoted, UserCreatedComment = userCreatedComment }; return(View(model)); }