Example #1
0
        /// <summary>
        /// Extends the room time by the length given
        /// </summary>
        /// <param name="length">the length to extend the room by</param>
        /// <returns>true if the room time has been extended</returns>
        public override bool extendTime(int length)
        {
            if (customerId == 0)
            {
                throw new Exception("Error releasing room: Currently nobody has booked this room.");
            }
            if (length <= 0)
            {
                throw new Exception("You can not extend for minus days");
            }

            DateTime endDate = startDate.AddDays(this.length);

            accessible   = false;
            this.length += length;

            Person person = Library.Get.getPersonById(customerId);

            double amountToPay = PRICE_TABLE.getPriceFor(roomCount, endDate, endDate.AddDays(length));
            double delta       = amountToPay * person.Discount;

            if (person.requestPayment(amountToPay - delta))
            {
                Library.Get.addTransaction(
                    new Transaction(customerId, (amountToPay - delta), endDate, length, roomId));
            }
            else
            {
                return(false);
            }

            return(true);
        }
Example #2
0
        /// <summary>
        /// Books a room for a specific lenght and for a certain amount of guests
        ///
        /// the start date is always today
        /// </summary>
        /// <param name="customerId">The customer id making the booking</param>
        /// <param name="start">The start</param>
        /// <param name="length"></param>
        /// <param name="guests"></param>
        /// <returns>True if the room has been booked successfully. False if it fails</returns>
        public override bool book(int customerId, int length, int guests)
        {
            if (CustomerId != 0)
            {
                throw new Exception("This room is already booked!");
            }
            if (length <= 0)
            {
                throw new Exception("You must book a room for longer than 0 days!");
            }

            this.length = length;
            startDate   = DateTime.Now;

            DateTime endDate = startDate.AddDays(length);

            Person person = Library.Get.getPersonById(customerId);


            double amountToPay = 0;

            try
            {
                amountToPay = PRICE_TABLE.getPriceFor(
                    roomCount, startDate, endDate);
            }

            catch (Exception ex) { throw new Exception(ex.Message); }

            double delta = amountToPay * person.Discount;

            if (person.requestPayment(amountToPay - delta))
            {
                Library.Get.addTransaction(
                    new Transaction(customerId, Math.Round((amountToPay - delta), 3), startDate, length, roomId));

                this.guests     = guests;
                this.accessible = false;
                this.customerId = customerId;
                return(true);
            }
            else
            {
                throw new Exception("This member doesn't have enough money");
            }
        }