public void Update(BOOK bookObj) { using (var db = new swagbaseEntities1()) { BOOK dummyBook = db.BOOKs.Include("AUTHORs").FirstOrDefault(a => a.ISBN == bookObj.ISBN); db.BOOKs.Attach(dummyBook); db.CLASSIFICATIONs.Attach(db.CLASSIFICATIONs.Find(bookObj.SignId)); dummyBook.pages = bookObj.pages; dummyBook.Title = bookObj.Title; dummyBook.publicationinfo = bookObj.publicationinfo; dummyBook.PublicationYear = bookObj.PublicationYear; dummyBook.ISBN = bookObj.ISBN; dummyBook.AUTHORs.Clear(); List <int> authorsToDummy = bookObj.AUTHORs.Select(a => a.Aid).ToList(); foreach (int auth in authorsToDummy) { db.AUTHORs.Attach(db.AUTHORs.Find(auth)); dummyBook.AUTHORs.Add(db.AUTHORs.Find(auth)); } dummyBook.pages = bookObj.pages; dummyBook.Title = bookObj.Title; dummyBook.publicationinfo = bookObj.publicationinfo; dummyBook.PublicationYear = bookObj.PublicationYear; dummyBook.SignId = bookObj.SignId; //dummyBook.CLASSIFICATION = bookObj.CLASSIFICATION; db.SaveChanges(); } }
public void Add(CLASSIFICATION classiObj) { using (var db = new swagbaseEntities1()) { db.CLASSIFICATIONs.Add(classiObj); db.SaveChanges(); } }
public void Add(AUTHOR authorObj) { using (var db = new swagbaseEntities1()) { db.AUTHORs.Add(authorObj); db.SaveChanges(); } }
public void Delete(CLASSIFICATION classiObj) { using (var db = new swagbaseEntities1()) { CLASSIFICATION csignID = db.CLASSIFICATIONs.Find(classiObj.SignId); db.CLASSIFICATIONs.Remove(csignID); db.SaveChanges(); } }
public void Update(CLASSIFICATION classiObj) { using (var db = new swagbaseEntities1()) { db.CLASSIFICATIONs.Attach(classiObj); db.Entry(classiObj).State = EntityState.Modified; db.SaveChanges(); } }
public void Delete(AUTHOR authorObj) { using (var db = new swagbaseEntities1()) { AUTHOR athID = db.AUTHORs.Find(authorObj.Aid); db.AUTHORs.Remove(athID); db.SaveChanges(); } }
public void Delete(BOOK bookObj) { using (var db = new swagbaseEntities1()) { BOOK bISBN = db.BOOKs.Find(bookObj.ISBN); db.BOOKs.Remove(bISBN); db.SaveChanges(); } }
public void Update(AUTHOR authorObj) { using (var db = new swagbaseEntities1()) { AUTHOR dummyAuthor = db.AUTHORs.Include("BOOKs").FirstOrDefault(a => a.Aid == authorObj.Aid); db.AUTHORs.Attach(dummyAuthor); dummyAuthor.BirthYear = authorObj.BirthYear; dummyAuthor.FirstName = authorObj.FirstName; dummyAuthor.LastName = authorObj.LastName; //dummyAuthor.BOOKs.Clear(); //AUTHOR booksToDummy = authorObj.BOOKs.Select db.Entry(dummyAuthor).State = EntityState.Modified; db.SaveChanges(); } }
public void Add(BOOK bookObj) { using (var db = new swagbaseEntities1()) { List <AUTHOR> auths = bookObj.AUTHORs.ToList(); bookObj.AUTHORs = null; bookObj.CLASSIFICATION = null; db.BOOKs.Add(bookObj); foreach (AUTHOR a in auths) { db.AUTHORs.Attach(a); a.BOOKs.Add(bookObj); db.Entry(a).State = EntityState.Modified; } db.SaveChanges(); } }