//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Manage loans //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ public int createLoan(int userID, int copyNo, DateTime rentalDate, DateTime duedate, int reserveNo = 0) { int loanID = -1; try { if (findUserByID(userID, UT_USER) == null) { ErrorMessage = "UserID:" + userID + " is not found."; return -1; } BookCopy bookCopy = db.BookCopies.FirstOrDefault(b => b.CopyNumber == copyNo); if (bookCopy == null) { ErrorMessage = "Book copy number:" + copyNo + " is not found."; return -1; } if (bookCopy.status.Trim().Equals(ST_RENTED)) { ErrorMessage = "The book copy (copy No:" + copyNo + ") is already rented!!"; return -1; } bookCopy.status = ST_RENTED; bookCopy.dateDueBackIn = duedate; db.SubmitChanges(); Loan loan = new Loan { UserID = userID, CopyNumber = copyNo, RentalDate = rentalDate, DueDate = duedate }; db.Loans.InsertOnSubmit(loan); db.SubmitChanges(); loanID = loan.LoanID; if (reserveNo > 0) { closeReservation(reserveNo); } } catch (Exception ex) { ErrorMessage = "CreateLoan Error:/n" + ex.Message; return -1; } return loanID; }
public Loan findLoanByID(int id) { Loan rb = new Loan(); bool found = false; var loans = from l in db.Loans where l.LoanID == id select l; foreach (var l in loans) { rb.CopyNumber = l.CopyNumber; rb.UserID = l.UserID; rb.RentalDate = l.RentalDate; rb.DueDate = l.DueDate; found = true; }; if (!found) return null; return rb; }
partial void DeleteLoan(Loan instance);
partial void UpdateLoan(Loan instance);
partial void InsertLoan(Loan instance);
private void detach_Loans(Loan entity) { this.SendPropertyChanging(); entity.User = null; }
private void attach_Loans(Loan entity) { this.SendPropertyChanging(); entity.User = this; }