Ejemplo n.º 1
0
 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();
         }
     }
 }
Ejemplo n.º 2
0
 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();
         }
     }
 }
Ejemplo n.º 3
0
 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();
         }
     }
 }
Ejemplo n.º 4
0
 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);
 }
Ejemplo n.º 5
0
 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);
 }
Ejemplo n.º 6
0
 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);
 }