public async Task <IActionResult> Comment(NewsCommentViewModel vm, [FromServices] GetOneNews getOneNews, [FromServices] CreateComment createComment) { if (!ModelState.IsValid) { var singleNews = getOneNews.Do(vm.NewsId); return(RedirectToAction("SingleNewsDisplay", new { id = singleNews.Id })); } var news = getOneNews.Do(vm.NewsId); if (vm.NewsMainCommentId == 0) { await createComment.CreateMainComment(new CreateComment.MainCommentRequest { OneNewsId = news.Id, Created = DateTime.Now, Creator = "", Message = vm.Message, }); } else { await createComment.CreateSubComment(new CreateComment.SubCommentRequest { NewsMainCommentId = vm.NewsMainCommentId, Created = DateTime.Now, Creator = "", Message = vm.Message, }); } return(RedirectToAction("SingleNewsDisplay", new { id = news.Id })); }
public IActionResult SingleNewsDisplay(int id, [FromServices] GetOneNews getOneNews) { var singleNews = getOneNews.Do(id); return(View(new NewsViewModel { Id = singleNews.Id, Title = singleNews.Title, Body = singleNews.Body, ImagePath = singleNews.Image, Created = singleNews.Created, Description = singleNews.Description, Tags = singleNews.Tags, Category = singleNews.Category, MainComments = singleNews.MainComments?.Select(comment => new NewsCommentViewModel { Id = comment.Id, Created = comment.Created, Creator = comment.Creator, Message = comment.Message, SubComments = comment.SubComments?.Select(subComment => new NewsCommentViewModel { Id = subComment.Id, Created = subComment.Created, Creator = subComment.Creator, Message = subComment.Message, NewsMainCommentId = subComment.NewsMainCommentId, }).ToList() }).ToList(), })); }
public async Task <IActionResult> Edit(int?id, [FromServices] GetOneNews getOneNews) { if (id == null) { return(View(new NewsViewModel())); } else { var singleNews = await Task.Run(() => getOneNews.Do((int)id)); return(View(new NewsViewModel { Id = singleNews.Id, Title = singleNews.Title, Body = singleNews.Body, ImagePath = singleNews.Image, Description = singleNews.Description, Tags = singleNews.Tags, Category = singleNews.Category })); } }