public BOOK EditBook(BOOK eBook) { using (DbLibrary db = new DbLibrary()) { db.Configuration.LazyLoadingEnabled = false; BOOK book = db.BOOKs.Include(b => b.AUTHORs).FirstOrDefault(x => x.ISBN.Equals(eBook.ISBN)); book.AUTHORs.Clear(); db.SaveChanges(); } using (DbLibrary db = new DbLibrary()) { db.Configuration.LazyLoadingEnabled = false; BOOK book = db.BOOKs.Include(b => b.CLASSIFICATION).FirstOrDefault(x => x.ISBN.Equals(eBook.ISBN)); db.Entry(book).CurrentValues.SetValues(eBook); db.ChangeTracker.Entries <CLASSIFICATION>().ToList().ForEach(a => a.State = EntityState.Unchanged); book.AUTHORs = new List <AUTHOR>(); foreach (var author in eBook.AUTHORs) { db.AUTHORs.Attach(author); book.AUTHORs.Add(author); } db.SaveChanges(); return(book); } }
public bool EditAdmin(ADMIN eAdmin) { using (DbLibrary db = new DbLibrary()) { try { db.Entry(db.ADMINS.FirstOrDefault(x => x.Username.Equals(eAdmin.Username))).CurrentValues.SetValues(eAdmin); db.SaveChanges(); return(true); } catch { return(false); } } }
public AUTHOR EditAuthor(AUTHOR eauthor) //Returns the updated author and if failed returns null { using (DbLibrary db = new DbLibrary()) { try { AUTHOR updatedAUTHOR = db.AUTHORs.Find(eauthor.Aid); db.Entry(updatedAUTHOR).CurrentValues.SetValues(eauthor); db.SaveChanges(); return(updatedAUTHOR); } catch { return(null); } } }
public bool EditClassification(CLASSIFICATION eClassification) { using (DbLibrary db = new DbLibrary()) { try { CLASSIFICATION classification = db.CLASSIFICATIONs.FirstOrDefault(x => x.SignId.Equals(eClassification.SignId)); db.Entry(classification).CurrentValues.SetValues(eClassification); db.SaveChanges(); return(true); } catch { return(false); } } }