Exemple #1
0
        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();
            }
        }
Exemple #2
0
 public void Add(CLASSIFICATION classiObj)
 {
     using (var db = new swagbaseEntities1())
     {
         db.CLASSIFICATIONs.Add(classiObj);
         db.SaveChanges();
     }
 }
Exemple #3
0
 public void Add(AUTHOR authorObj)
 {
     using (var db = new swagbaseEntities1())
     {
         db.AUTHORs.Add(authorObj);
         db.SaveChanges();
     }
 }
Exemple #4
0
 public void Delete(CLASSIFICATION classiObj)
 {
     using (var db = new swagbaseEntities1())
     {
         CLASSIFICATION csignID = db.CLASSIFICATIONs.Find(classiObj.SignId);
         db.CLASSIFICATIONs.Remove(csignID);
         db.SaveChanges();
     }
 }
Exemple #5
0
 public void Update(CLASSIFICATION classiObj)
 {
     using (var db = new swagbaseEntities1())
     {
         db.CLASSIFICATIONs.Attach(classiObj);
         db.Entry(classiObj).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
Exemple #6
0
 public void Delete(AUTHOR authorObj)
 {
     using (var db = new swagbaseEntities1())
     {
         AUTHOR athID = db.AUTHORs.Find(authorObj.Aid);
         db.AUTHORs.Remove(athID);
         db.SaveChanges();
     }
 }
Exemple #7
0
 public void Delete(BOOK bookObj)
 {
     using (var db = new swagbaseEntities1())
     {
         BOOK bISBN = db.BOOKs.Find(bookObj.ISBN);
         db.BOOKs.Remove(bISBN);
         db.SaveChanges();
     }
 }
Exemple #8
0
        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();
            }
        }
Exemple #9
0
        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();
            }
        }