예제 #1
0
        public async Task <ActionResult <ParkingOrderDto> > AddParkingOrder(ParkingOrderDto parkingOrderDto)
        {
            var orderFound = parkingOrderService.GetAllParkingOrders().Result
                             .FirstOrDefault(parkingOrderEntity => parkingOrderEntity.PlateNumber == parkingOrderDto.PlateNumber);

            if (orderFound != null)
            {
                return(BadRequest("car in the lot"));
            }

            var parkingLot = await parkingLotService.GetParkingLotByName(parkingOrderDto.ParkingLotName);

            var capacity = parkingLot.Capacity;
            var occupies = await parkingLotService.GetParkingLotCapacityByName(parkingOrderDto.ParkingLotName);

            if (occupies == -1)
            {
                return(BadRequest("parking lot not found"));
            }

            if (capacity == occupies)
            {
                return(BadRequest("parking lot is full"));
            }

            var parkingOrderNumber = await parkingOrderService.AddParkingOrder(parkingOrderDto);

            return(CreatedAtAction(nameof(GetParkingOrderByOrderNumber), new { orderNumber = parkingOrderNumber }, parkingOrderNumber));
        }