public ActionResult DetailsByTitle(string slug) { if (string.IsNullOrWhiteSpace(slug)) { return(RedirectToAction(nameof(HomeController.Index))); } var post = DbContext.PostDatabase.FirstOrDefault(p => p.Slug == slug); if (post == null) { return(RedirectToAction(nameof(HomeController.Index))); } var model = new ShowPostsViewModel(); model.PostId = post.PostId; model.Title = post.Title; model.Body = post.Body; model.Comments = post.Comments.Select(p => new ShowCommentViewModel() { Body = p.Body, DateCreated = p.DateCreated, DateUpdated = p.DateUpdated, CommentId = p.CommentId, ReasonOfUpdating = p.ReasonOfUpdating, UserName = p.User.UserName }).ToList(); model.Published = post.Published; model.DateCreated = post.DateCreated; model.MediaUrl = post.MediaUrl; return(View("FullDetail", model)); }
public ActionResult fullDetail(int?id) { if (!id.HasValue) { return(RedirectToAction(nameof(HomeController.Index))); } var post = DbContext.PostDatabase.FirstOrDefault(p => p.PostId == id); if (post == null) { return(RedirectToAction(nameof(HomeController.Index))); } var model = new ShowPostsViewModel() { PostId = id.Value, Title = post.Title, Body = post.Body, Comments = post.Comments.Select(p => new ShowCommentViewModel() { Body = p.Body, CommentId = p.CommentId, UserId = p.UserId, DateCreated = p.DateCreated, DateUpdated = p.DateUpdated, ReasonOfUpdating = p.ReasonOfUpdating, UserName = p.User.UserName }).ToList(), DateCreated = post.DateCreated, MediaUrl = post.MediaUrl }; return(View(model)); }
public ActionResult fullDetail(int?id) { if (!id.HasValue) { return(RedirectToAction(nameof(HomeController.Index))); } var post = DbContext.PostDatabase.FirstOrDefault(p => p.PostId == id); if (post == null) { return(RedirectToAction(nameof(HomeController.Index))); } var model = new ShowPostsViewModel() { Title = post.Title, Body = post.Body, DateCreated = post.DateCreated, MediaUrl = post.MediaUrl }; return(View(model)); }