// Method to update the locker of the rental if changed
        public void ChangeBookedLocker(Rental rental, Locker previousLocker)
        {
            Locker locker = Locker.Get(rental.LockerId);

            // Change the locker of the rental
            rental.ChangeLocker();

            // Check if the rental is a started rental.
            if (rental.IsStarted())
            {
                // If yes, release the previous locker
                previousLocker.Reset();

                // Occupy the new locker
                locker.Occupied();

                // Check if the new cabinet is full, if yes set to full
                string lockerSearchCondition = String.Format("cabinet_id = {0} AND status = 'Available'", locker.CabinetId);
                int    noOfEmptyLocker       = Locker.Count(lockerSearchCondition);
                if (noOfEmptyLocker <= 0)
                {
                    Cabinet cabinet = Cabinet.Get(locker.CabinetId);
                    cabinet.Full();
                }

                // Check is the old cabinet full. If yes, set it as available
                Cabinet previousCabinet = Cabinet.Get(previousLocker.CabinetId);
                if (previousCabinet.IsFull())
                {
                    previousCabinet.Restore();
                }
            }
        }
Exemple #2
0
        public void DisableLocker(string lockerCode)
        {
            string        lockerCodeCondition = String.Format("code = '{0}'", lockerCode);
            List <Locker> lockers             = Locker.Where(lockerCodeCondition, 0, 1);
            var           locker = lockers[0];

            if (locker.IsNotAvailable())
            {
                throw new InvalidUserInputException("Disable Error - Locker Disabled");
            }
            else if (Rental.Count(String.Format("locker_id = {0} AND status <> 'Ended'", locker.Id)) > 0)
            {
                throw new InvalidUserInputException("Disable Error - Locker Booked");
            }
            else
            {
                locker.NotAvailable();

                //Check is the cabinet full. If yes, update and insert log.
                int noOfEmptyLocker = Locker.Count(String.Format("cabinet_id = {0} AND status = 'Available'",
                                                                 lockers[0].CabinetId));
                if (noOfEmptyLocker <= 0)
                {
                    var cabinet = Cabinet.Get(lockers[0].CabinetId);
                    cabinet.Full();
                }
            }
        }