public ActionResult Create([Bind(Include = "Id,Title,Content,Image,CreationDate,Author")] Entry entry) { if (ModelState.IsValid) { db.Entry.Add(entry); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(entry)); }
public ActionResult Comment(int id, string name, string email, string body) { Post post = GetPost(id); Comment comment = new Comment(); //Point the comment at the post comment.Post = post; comment.DateTime = DateTime.Now; comment.Name = name; comment.Email = email; comment.Body = body; model.AddToComments(comment); model.SaveChanges(); return(RedirectToAction("Details", new { id = id })); }
public ActionResult Update(int?id, string title, string body, DateTime dateTime, string tags) { if (!IsAdmin) { return(RedirectToAction("Index")); } Post post = GetPost(id); post.Title = title; post.Body = body; post.DateTime = dateTime; post.Tag.Clear(); tags = tags ?? string.Empty; string[] tagNames = tags.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); foreach (string tagName in tagNames) { post.Tag.Add(GetTag(tagName)); } if (!id.HasValue) { model.AddToPosts(post); } model.SaveChanges(); return(RedirectToAction("Details", new { id = post.ID })); }
public void Insert(Entry entry) { using (BlogModel ctx = new BlogModel()) { ctx.Entry.Add(entry); ctx.SaveChanges(); } }
// POST: Update Post Action. public ActionResult Edit([Bind(Include = "Id, Title, Content, TypeOfPost")] Post post) { var current = HttpContext.User.Identity.Name; var original = db.Posts.Where(i => i.Id == post.Id).FirstOrDefault(); if (ModelState.IsValid && current == original.AccountEmail) { original.Title = post.Title; original.Content = post.Content; original.TypeOfPost = post.TypeOfPost; db.SaveChanges(); return(RedirectToAction("Detail", "Posts", new { id = post.Id })); } return(View(post)); }
public int Complete() { return(_context.SaveChanges()); }