public ActionResult Create([Bind(Include = "Id,Name,Controller,Action,CreateTime,IsRemove")] SideBars sideBars) { if (ModelState.IsValid) { sideBars.Id = Guid.NewGuid(); db.sideBars.Add(sideBars); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(sideBars)); }
public void SaveCategories(BlogContent blog) { if (blog.Category.ToList().Count == 0) { List <Category> categories = new List <Category> { new Category { Name = "Terror" }, new Category { Name = "Romance" }, new Category { Name = "Accion" }, new Category { Name = "Comedia" }, new Category { Name = "Misterio" }, }; blog.Category.AddRange(categories); blog.SaveChanges(); } }
public ActionResult Delete(Post post) { using (var blog = new BlogContent()) { Post pos = blog.Post.Find(post.Id); blog.Post.Remove(pos); blog.SaveChanges(); return(RedirectToAction("Index")); } }
public ActionResult Detail(DetailVM detail) { using (var blog = new BlogContent()) { detail.comment.Date = DateTime.Now; detail.comment.IdPost = detail.post.Id; blog.Comment.Add(detail.comment); blog.SaveChanges(); } return(Detail(detail.post.Id)); }
public ActionResult ManagePost(Post post) { if (ModelState.IsValid) { } using (var blog = new BlogContent()) { if (post.Id == 0) { post.Date = DateTime.Now; blog.Post.Add(post); } else { Post _post = blog.Post.Find(post.Id); _post.Title = post.Title; _post.IdCategory = post.IdCategory; _post.Content = post.Content; } blog.SaveChanges(); return(RedirectToAction("Index")); } }