示例#1
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");
         }
     }
 }
 public ActionResult ReturnProcessor(studentbookloan loanDetails)
 {
     loanDetails = DBManager.Instance.GetStudentBookLoanByID(loanDetails.id);
     var returnedBook = loanDetails.book;
     var regId = loanDetails.student.RegistrationID;
     returnedBook.Available = true;
     loanDetails.ReturnDate = DateTime.Now;
     try
     {
         DBManager.Instance.UpdateBook(returnedBook);
         DBManager.Instance.UpdateStudentBookLoan(loanDetails);
     }
     catch(Exception ex)
     {
         return View(new ReturnBookModel { ReturnSuccess = false, StudentReg = regId });
     }
     return View(new ReturnBookModel { ReturnSuccess = true, StudentReg = regId });
 }
        public ActionResult Index(LoanBookModel loanBookModel)
        {
            if (loanBookModel.IsInitial)
            {
               ModelState.Clear();
               ViewData["InitialCall"] = 1 ;
               return View(new LoanBookModel {BookId = loanBookModel.BookId, BookIsbn = loanBookModel.BookIsbn,BookTitle = loanBookModel.BookTitle, IsInitial = false});
            }
            ViewData["InitialCall"] = 0;
            var loanbook = DBManager.Instance.GetAvailableBookByID(loanBookModel.BookId);
            var loanee = DBManager.Instance.GetStudentByRegNo(loanBookModel.StudentReg);
            //TODO: Check Max Books Held;
            if (loanee == null)
            {
                ViewData["LoanSuccess"] = 0;
                return View(loanBookModel);
            }

            var bookLoanData = new studentbookloan
                                               {
                                                   BookId = loanBookModel.BookId,
                                                   DueDate = DateTime.Now.AddDays(7),
                                                   // Make Configurable parameter
                                                   ReturnDate = DateTime.MinValue,
                                                   IssuerID = 1,
                                                   StudentID = loanee.Id,
                                                   IssueDate = DateTime.Now
                                               };
            //Add Book Loan Data
            DBManager.Instance.AddStudentBookLoan(bookLoanData);

            loanbook.Available = false;

            //Update Book
            DBManager.Instance.UpdateBook(loanbook);

            ViewData["LoanSuccess"] = 1;

            return View(loanBookModel);
        }
示例#4
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");
         }
     }
 }