// 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(); } } }