예제 #1
0
        /// <summary>
        /// Returns a rented truck and calculate the costs of the rental.
        /// Only rented trucks can be returned.
        /// </summary>
        /// <param name="returnDate">The date on which the truck is returned.</param>
        /// <param name="kilometers">The total number of kilometers on the counter.</param>
        /// <returns>The cost of the rental,
        ///          or a number less than zero when:
        ///          - the truck was not rented (so it could not be returned)
        ///          - the return date is before the rental date  (so wrong return date was entered)
        ///          - the number of kilometers when returned is less then at the start of the rental.
        /// Please note that returning as number less than zero for error situations is NOT(!!!)
        /// clean coding in this case. Later on you will learn to do this in a better fashion (Exceptions!)
        /// </returns>
        public decimal Return(SimpleDate returnDate, int kilometers)
        {
            if (!IsAvailable)
            {
                int daysRented       = RentalDate.DaysDifference(returnDate);
                int kilometersDriven = kilometers - Kilometers;

                if (daysRented >= 0 && kilometersDriven >= 0)
                {
                    RentalDate = null;       // makes the truck available for renting again
                    Kilometers = kilometers; // update kms for the next rental
                    return(CalculateRentalCosts(daysRented, kilometersDriven));
                }
            }
            return(-1);
        }
예제 #2
0
 public Rental()
 {
     RentalDate = DateTime.Now;
     DueDate    = RentalDate.AddDays(7);
     ReturnDate = DateTime.Now;
 }
예제 #3
0
 public string GetDetails()
 //returns more info about the car including rental dates,dates are formated to short date format
 {
     return(string.Format("Make of Car: {0}" + "\r\n Model: {1}" + "\r\n  Size: {2}" + "\r\n  RentalDate: {3}" + "\r\n  ReturnDate: {4}", Make, Model, Size, RentalDate.ToShortDateString(), ReturnDate.ToShortDateString()));
 }
예제 #4
0
 public override string ToString()
 {
     return(string.Format("BookRental: {{ PrimaryKey: \"{0}\", RentalDate: \"{1}\", RentalDueDate: \"{2}\", RentalReturnDate: \"{3}\", User: \"{4}\" }}",
                          PrimaryKey, RentalDate.ToShortDateString(), RentalDueDate.ToShortDateString(), RentalReturnDate.ToShortDateString(), User.PrimaryKey));
 }
예제 #5
0
 public override string ToString()
 {
     return(ID.ToString() + "; " + Customer.Name + " " + Customer.Surname + "; " + RentalDate.ToString());
 }