protected override void OnInitialized() { var blog1 = new BlogItemDto() { Title = "Titulo 1", Description = "This is a wider card with supporting text below as a natural lead-in to additional content.", Date = DateTime.Now }; var blog2 = new BlogItemDto() { Title = "Titulo 2", Description = "This is a wider card with supporting text below as a natural lead-in to additional content.", Date = new DateTime(2020, 12, 12) }; var blog3 = new BlogItemDto() { Title = "Titulo 3", Description = "This is a wider card with supporting text below as a natural lead-in to additional content.", Date = new DateTime(2020, 07, 31) }; var blog4 = new BlogItemDto() { Title = "Titulo 4", Description = "This is a wider card with supporting text below as a natural lead-in to additional content.", Date = new DateTime(2020, 06, 18) }; var blog5 = new BlogItemDto() { Title = "Titulo 5", Description = "This is a wider card with supporting text below as a natural lead-in to additional content.", Date = new DateTime(2021, 02, 15) }; var blog6 = new BlogItemDto() { Title = "Titulo 6", Description = "This is a wider card with supporting text below as a natural lead-in to additional content.", Date = new DateTime(2020, 04, 05) }; this.BlogItems.Add(blog1); this.BlogItems.Add(blog2); this.BlogItems.Add(blog3); this.BlogItems.Add(blog4); this.BlogItems.Add(blog5); this.BlogItems.Add(blog6); this.BlogItems.OrderByDescending(x => x.Date); }
public IActionResult Create(BlogItemDto blogItemDto) { if (!ModelState.IsValid) { return(View()); } var blogItem = new BlogItem { Title = blogItemDto.Title, Body = blogItemDto.Body, Author = User.Identity.Name, Posted = DateTime.Now }; blogDbContext.BlogItems.Add(blogItem); blogDbContext.SaveChanges(); return(RedirectToAction("Post", "Blog", new { id = blogItem.Id })); }
public BlogItemDto GetBlogDtoById(long id) { BlogPost post = GetById(id); BlogItemDto itemDto = new BlogItemDto { CreatedBy = post.CreatedBy, CreatedDate = post.CreatedDate, Description = post.Description, IsActive = post.IsActive, PostId = post.PostId, Title = post.Title, UpdatedBy = post.UpdatedBy, UpdatedDate = post.UpdatedDate }; if (post.BlogPostComments.Any()) { var existingComments = post.BlogPostComments.ToList(); itemDto.BlogPostComments = new List <BlogItemCommentDto>(); for (int i = 0; i < existingComments.Count; i++) { itemDto.BlogPostComments.Add(new BlogItemCommentDto { Comment = existingComments[i].Comment, CreatedBy = existingComments[i].CreatedBy, CreatedDate = existingComments[i].CreatedDate, ID = existingComments[i].ID, PostID = existingComments[i].PostID, UpdatedBy = existingComments[i].UpdatedBy, UpdatedDate = existingComments[i].UpdatedDate, ParentCommentID = existingComments[i].ParentCommentID }); } } return(itemDto); }
public ActionResult Item(long id) { BlogItemDto itemDto = _blogService.GetBlogDtoById(id); return(View(itemDto)); }