public static void Delete(this BookmarksDBEntities DB, User user) { if (user != null) { User userToDelete = DB.Users.Find(user.Id); if (userToDelete != null) { foreach (Bookmark bookmark in DB.Bookmarks.Where(b => b.UserId == user.Id)) { DB.Entry(bookmark).State = System.Data.Entity.EntityState.Deleted; } DB.Entry(userToDelete).State = System.Data.Entity.EntityState.Deleted; DB.SaveChanges(); } } }
public static void Delete(this BookmarksDBEntities DB, Category category) { if (category != null) { Category categoryToDelete = DB.Categories.Find(category.Id); if (categoryToDelete != null) { foreach (Bookmark bookmark in DB.Bookmarks.Where(b => b.CategoryId == categoryToDelete.Id)) { bookmark.CategoryId = 0; DB.Entry(bookmark).State = System.Data.Entity.EntityState.Modified; } DB.Entry(categoryToDelete).State = System.Data.Entity.EntityState.Deleted; DB.SaveChanges(); } } }
public static void Delete(this BookmarksDBEntities DB, Bookmark bookmark) { if (bookmark != null) { Bookmark bookmarkToDelete = DB.Bookmarks.Find(bookmark.Id); if (bookmarkToDelete != null) { DB.Entry(bookmarkToDelete).State = System.Data.Entity.EntityState.Deleted; DB.SaveChanges(); } } }
public static User Update(this BookmarksDBEntities DB, User user) { if (user != null) { User userToUpdate = DB.Users.Find(user.Id); if (userToUpdate != null) { userToUpdate.Update(user); DB.Entry(userToUpdate).State = System.Data.Entity.EntityState.Modified; DB.SaveChanges(); return(DB.Users.Find(userToUpdate.Id)); } } return(null); }
public static Category Update(this BookmarksDBEntities DB, Category category) { if (category != null) { Category categoryToUpdate = DB.Categories.Find(category.Id); if (categoryToUpdate != null) { categoryToUpdate.Update(category); DB.Entry(categoryToUpdate).State = System.Data.Entity.EntityState.Modified; DB.SaveChanges(); return(DB.Categories.Find(categoryToUpdate.Id)); } } return(null); }
public static Bookmark Update(this BookmarksDBEntities DB, Bookmark bookmark) { if (bookmark != null) { Bookmark bookmarkToUpdate = DB.Bookmarks.Find(bookmark.Id); if (bookmarkToUpdate != null) { bookmarkToUpdate.Update(bookmark); DB.Entry(bookmarkToUpdate).State = System.Data.Entity.EntityState.Modified; DB.SaveChanges(); return(DB.Bookmarks.Find(bookmarkToUpdate.Id)); } } return(null); }