Beispiel #1
0
 public void AddBook(book newBook)
 {
     using (var dbModel = new LMSDataModelEntities())
     {
         dbModel.books.AddObject(newBook);
         dbModel.ObjectStateManager.ChangeObjectState(newBook, System.Data.EntityState.Added);
         var saveCount = dbModel.SaveChanges();
         if (saveCount < 1)
         {
             throw new Exception("Fail to insert Book " + newBook.Title + " in to DB");
         }
     }
 }
Beispiel #2
0
 public void UpdateBook(book bookToUpdate)
 {
     using (var dbModel = new LMSDataModelEntities())
     {
         bookToUpdate.bookauthors = null;
         bookToUpdate.department = null;
         bookToUpdate.publisher = null;
         bookToUpdate.studentbookloans = null;
         bookToUpdate.systemuser = null;
         dbModel.books.AddObject(bookToUpdate);
         dbModel.ObjectStateManager.ChangeObjectState(bookToUpdate, System.Data.EntityState.Modified);
         var saveCount = dbModel.SaveChanges();
         if (saveCount < 1)
         {
             throw new Exception("Fail to Update Book " + bookToUpdate.Title + "in DB");
         }
     }
 }
        private void Fixupbook(book previousValue)
        {
            if (previousValue != null && previousValue.studentbookloans.Contains(this))
            {
                previousValue.studentbookloans.Remove(this);
            }

            if (book != null)
            {
                if (!book.studentbookloans.Contains(this))
                {
                    book.studentbookloans.Add(this);
                }
                if (BookId != book.Id)
                {
                    BookId = book.Id;
                }
            }
        }