Ejemplo n.º 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;
        }
Ejemplo n.º 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;
 }
Ejemplo n.º 3
0
 partial void DeleteLoan(Loan instance);
Ejemplo n.º 4
0
 partial void UpdateLoan(Loan instance);
Ejemplo n.º 5
0
 partial void InsertLoan(Loan instance);
Ejemplo n.º 6
0
		private void detach_Loans(Loan entity)
		{
			this.SendPropertyChanging();
			entity.User = null;
		}
Ejemplo n.º 7
0
		private void attach_Loans(Loan entity)
		{
			this.SendPropertyChanging();
			entity.User = this;
		}