예제 #1
0
        public Response GetCarSlotsStatus(ParkingSlotType slotStatus)
        {
            if (!CheckIfParkingLotIsCreated())
            {
                throw new ParkingSystemException("Please create parking lot first");
            }

            Response response = new Response();

            StringBuilder       strBuilder   = new StringBuilder();
            IList <ParkingSlot> parkingSlots = null;

            if (slotStatus == ParkingSlotType.Available)
            {
                parkingSlots = _availableParkingSlots.GetAllNodes();
            }
            else if (slotStatus == ParkingSlotType.Occupied)
            {
                parkingSlots = _occupiedParkingSlots.Select(x => x.Value).ToList();
            }

            if (parkingSlots != null)
            {
                // Construct the header
                strBuilder.Append("Slot No.".PadRight(12))
                .Append("Registration No".PadRight(19))
                .AppendLine("Colour");

                for (int i = 0; i < parkingSlots.Count(); i++)
                {
                    if (i == parkingSlots.Count() - 1)
                    {
                        //last record
                        strBuilder.Append(parkingSlots[i].SlotNo.ToString().PadRight(12))
                        .Append(parkingSlots[i].Vehicle.RegistrationNo.PadRight(19))
                        .Append(parkingSlots[i].Vehicle.Color);
                    }
                    else
                    {
                        strBuilder.Append(parkingSlots[i].SlotNo.ToString().PadRight(12))
                        .Append(parkingSlots[i].Vehicle.RegistrationNo.PadRight(19))
                        .Append(parkingSlots[i].Vehicle.Color);

                        strBuilder.Append(Environment.NewLine);
                    }
                }
            }

            response.IsSuccessful = true;
            response.Message      = strBuilder.ToString();

            return(response);
        }
예제 #2
0
 public void AssignedVehicle(Vehicle vehicle, ParkingSlotType status)
 {
     Vehicle = vehicle;
     Status  = status;
 }