Exemple #1
0
 public void AddBookAuthor(bookauthor newBookAuthor)
 {
     using (var dbModel = new LMSDataModelEntities())
     {
         dbModel.bookauthors.AddObject(newBookAuthor);
         dbModel.ObjectStateManager.ChangeObjectState(newBookAuthor, System.Data.EntityState.Added);
         var saveCount = dbModel.SaveChanges();
         if (saveCount < 1)
         {
             throw new Exception("Fail to insert new book author " + newBookAuthor.author.FirstName + " " +newBookAuthor.book.Title + " into DB");
         }
     }
 }
Exemple #2
0
 public void AddBookLoan(studentbookloan newBookLoan)
 {
     using (var dbModel = new LMSDataModelEntities())
     {
         dbModel.studentbookloans.AddObject(newBookLoan);
         dbModel.ObjectStateManager.ChangeObjectState(newBookLoan, System.Data.EntityState.Added);
         var saveCount = dbModel.SaveChanges();
         if (saveCount < 1)
         {
             throw new Exception("Fail to insert new book loan " + newBookLoan.book.Title + " into DB");
         }
     }
 }
Exemple #3
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");
         }
     }
 }
Exemple #4
0
 public void AddDepartment(department newDepartment)
 {
     using (var dbModel = new LMSDataModelEntities())
     {
         dbModel.departments.AddObject(newDepartment);
         dbModel.ObjectStateManager.ChangeObjectState(newDepartment, System.Data.EntityState.Added);
         var saveCount = dbModel.SaveChanges();
         if (saveCount < 1)
         {
             throw new Exception("Fail to insert new department " + newDepartment.Name + " into DB");
         }
     }
 }
Exemple #5
0
 public void UpdateStudentBookLoan(studentbookloan loanToUpdate)
 {
     using (var dbModel = new LMSDataModelEntities())
     {
         //dbModel.Refresh(RefreshMode.ClientWins, dbModel.studentbookloans);
         loanToUpdate.book = null;
         loanToUpdate.student = null;
         loanToUpdate.systemuser = null;
         dbModel.studentbookloans.AddObject(loanToUpdate);
         dbModel.ObjectStateManager.ChangeObjectState(loanToUpdate, System.Data.EntityState.Modified);
         var saveCount = dbModel.SaveChanges();
         if (saveCount < 1)
         {
             throw new Exception("Fail to Update Loan in DB");
         }
     }
 }
Exemple #6
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");
         }
     }
 }
Exemple #7
0
 public void AddSystemUser(systemuser newUser)
 {
     using (var dbModel = new LMSDataModelEntities())
     {
         dbModel.systemusers.AddObject(newUser);
         dbModel.ObjectStateManager.ChangeObjectState(newUser, System.Data.EntityState.Added);
         var saveCount = dbModel.SaveChanges();
         if (saveCount < 1)
         {
             throw new Exception("Fail to insert system user " + newUser.FirstName + " " + newUser.LastName + " into DB");
         }
     }
 }
Exemple #8
0
 public void AddPublisher(publisher newPublisher)
 {
     using (var dbModel = new LMSDataModelEntities())
     {
         dbModel.publishers.AddObject(newPublisher);
         dbModel.ObjectStateManager.ChangeObjectState(newPublisher, System.Data.EntityState.Added);
         var savecount = dbModel.SaveChanges();
         if (savecount < 1)
         {
             throw new Exception("Fail to insert Publisher " + newPublisher.Name + " into DB");
         }
     }
 }