示例#1
0
 public Loan(IBook book, IMember borrower, DateTime borrowDate, DateTime dueDate, int id)
 {
     if (!sane(book, borrower, borrowDate, dueDate, id))
     {
         throw new ArgumentException("Loan: constructor : bad parameters");
     }
     this.book = book;
     this.borrower = borrower;
     this.borrowDate = borrowDate;
     this.dueDate = dueDate;
     this.id = id;
     this.state = LoanConstants.LoanState.PENDING;
 }
示例#2
0
 public bool CheckOverDue(DateTime currentDate)
 {
     if (!(state == LoanConstants.LoanState.CURRENT || state == LoanConstants.LoanState.OVERDUE))
     {
         throw new ApplicationException(
                 String.Format("Loan : checkOverDue : incorrect state transition  :{0} -> {1}\n",
                         state, LoanConstants.LoanState.OVERDUE));
     }
     if (DateTime.Compare(currentDate, dueDate) > 0)
     {
         state = LoanConstants.LoanState.OVERDUE;
     }
     return IsOverDue;
 }
示例#3
0
 public void Complete()
 {
     if (!(state == LoanConstants.LoanState.CURRENT ||
           state == LoanConstants.LoanState.OVERDUE))
     {
         throw new ApplicationException(
                 String.Format("Loan : complete : incorrect state transition  : {0} -> {1}\n",
                         state, LoanConstants.LoanState.COMPLETE));
     }
     state = LoanConstants.LoanState.COMPLETE;
 }
示例#4
0
 public void Commit()
 {
     if (!(state == LoanConstants.LoanState.PENDING))
     {
         throw new ApplicationException(
                 String.Format("Loan : commit : incorrect state transition  : {0} -> {1}\n",
                         state, LoanConstants.LoanState.CURRENT));
     }
     state = LoanConstants.LoanState.CURRENT;
 }
示例#5
0
文件: Loan.cs 项目: juzzbott/itc515
        /// <summary>
        /// Creates a new instance of the Loan object.
        /// </summary>
        /// <param name="book">The IBook object being loaned.</param>
        /// <param name="borrower">The IMember who is initiating the loan.</param>
        /// <param name="borrowDate">The date and time that the book is being borrowed.</param>
        /// <param name="dueDate">The date ad time that the book is due.</param>
        /// <param name="loanId">The Id of the loan object.</param>
        public Loan(IBook book, IMember borrower, DateTime borrowDate, DateTime dueDate, int loanId)
        {
            // Validate the book parameter
            if (book == null)
            {
                throw new ArgumentNullException("book", "The 'book' parameter cannot be null.");
            }

            // Validate the member parameter
            if (borrower == null)
            {
                throw new ArgumentNullException("borrower", "The 'borrower' parameter cannot be null.");
            }

            // Ensure the borrowDate is valid
            if (borrowDate == DateTime.MinValue)
            {
                throw new ArgumentOutOfRangeException("borrowDate", "The borrowDate cannot be the default DateTime value.");
            }

            // Ensure the borrowDate is valid
            if (dueDate == DateTime.MinValue)
            {
                throw new ArgumentOutOfRangeException("dueDate", "The dueDate cannot be the default DateTime value.");
            }

            // Ensure the due date is not < borrowDate
            if (dueDate < borrowDate)
            {
                throw new ArgumentOutOfRangeException("dueDate", "The dueDate value cannot be less than the borrowDate.");
            }

            // Ensure the loanId is a positive integer
            if (loanId <= 0)
            {
                throw new ArgumentOutOfRangeException("loanId", "The 'loanId' parameter must be a positive integer value.");
            }

            // Set the fields of the Loan class
            this._book = book;
            this._borrower = borrower;
            this._id = loanId;

            // Use the Date property to get the midnight value for the current date
            this._borrowDate = borrowDate.Date;

            // Add 1 day to the Date property, and then subtract 1 second to get 23:59:59 on the due date
            this._dueDate = dueDate.Date.AddDays(1).AddSeconds(-1);

            // Set the initial state for the loan object
            this._loanState = LoanConstants.LoanState.PENDING;
        }
示例#6
0
文件: Loan.cs 项目: juzzbott/itc515
        /// <summary>
        /// Completes the loan by setting the loan state to complete.
        /// </summary>
        /// <exception cref="System.ApplicationException">ApplicationException is thrown if the current loan is not in the CURRENT or OVERDUE states.</exception>
        public void complete()
        {
            // If the loan state is not current or overdue, throw exception
            if (_loanState != LoanConstants.LoanState.CURRENT || _loanState != LoanConstants.LoanState.OVERDUE)
            {
                throw new ApplicationException("The loan can only be completed if it is in the CURRENT or OVERDUE state.");
            }

            // Set the current loan state to current
            _loanState = LoanConstants.LoanState.COMPLETE;
        }
示例#7
0
文件: Loan.cs 项目: juzzbott/itc515
        /// <summary>
        /// Commits the pending loan by setting the loan state to current. 
        /// </summary>
        /// <exception cref="System.ApplicationException">ApplicationException is thrown if the current loan is not in the PENDING state.</exception>
        public void commit()
        {
            // If the loan state is not pending, throw exception
            if (_loanState != LoanConstants.LoanState.PENDING)
            {
                throw new ApplicationException("The loan can only be commited if it is in the PENDING state.");
            }

            // Set the current loan state to current
            _loanState = LoanConstants.LoanState.CURRENT;
        }
示例#8
0
文件: Loan.cs 项目: juzzbott/itc515
        /// <summary>
        /// Checks to see if the loan is overdue by ensuring the currentDate is less than or equal to the loan due date.
        /// </summary>
        /// <param name="currentDate">The current date to check if the loan is overdue.</param>
        /// <returns>True if the loan is in the OVERDUE state, otherwise false.</returns>
        /// <exception cref="System.ApplicationException">ApplicationException is thrown if the current loan is not in the CURRENT or OVERDUE states.</exception>
        public bool checkOverDue(DateTime currentDate)
        {
            // If the loan state is not current or overdue, throw exception
            if (_loanState != LoanConstants.LoanState.CURRENT || _loanState != LoanConstants.LoanState.OVERDUE)
            {
                throw new ApplicationException("The loan can only be completed if it is in the CURRENT or OVERDUE state.");
            }

            // Checks if the current date (midnight of that date so that the full day is valid) is greater than than loan due date.
            // If the currentDate > dueDate, set the loan state to OVERDUE and return true, otherwise return false.
            if (currentDate.Date > _dueDate)
            {
                _loanState = LoanConstants.LoanState.OVERDUE;
                return false;
            }
            else
            {
                return false;
            }
        }