public ActionResult Create([Bind(Include = "Id,Body,CreateTime,BlogId,PosterId")] Comment comment) { if (ModelState.IsValid) { db.Comments.Add(comment); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.BlogId = new SelectList(db.Blogs, "Id", "Title", comment.BlogId); ViewBag.PosterId = new SelectList(db.Users, "Id", "UserName", comment.PosterId); return(View(comment)); }
public ActionResult DeleteConfirmed(int id) { Category category = db.Categories.Find(id); db.Categories.Remove(category); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult DeleteConfirmed(int id) { Blog blog = db.Blogs.Find(id); db.Blogs.Remove(blog); db.SaveChanges(); return(RedirectToAction("Index")); }
public void DeleteUserPosts(string userId) { var myPosts = _context.Posts.Where(r => userId.Contains(r.AuthorId)); foreach (var post in myPosts) { _context.Posts.Remove(post); } _context.SaveChanges(); }
public ActionResult Edit(int id, User model) { try { // TODO: Add update logic here using (BlogAppContext context = new BlogAppContext()) { Repository <User> r = new Repository <User>(context); r.Update(model); context.SaveChanges(); } return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create(User model) { try { using (BlogAppContext context = new BlogAppContext()) { Repository <User> r = new Repository <User>(context); r.Insert(model); context.SaveChanges(); } // TODO: Add insert logic here return(RedirectToAction("Index")); } catch { return(View()); } }
public void SaveChanges() { _context.SaveChanges(); }
public void SaveChanges() { m_Context.SaveChanges(); }