Example #1
0
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        // 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;
        }
Example #2
0
 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;
 }
Example #3
0
 partial void DeleteLoan(Loan instance);
Example #4
0
 partial void UpdateLoan(Loan instance);
Example #5
0
 partial void InsertLoan(Loan instance);
Example #6
0
		private void detach_Loans(Loan entity)
		{
			this.SendPropertyChanging();
			entity.User = null;
		}
Example #7
0
		private void attach_Loans(Loan entity)
		{
			this.SendPropertyChanging();
			entity.User = this;
		}