Пример #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));
        }
Пример #2
0
        public async Task Should_get_all_parkingOrders_when_get_parkingOrders_via_parkingOrderService()
        {
            // given
            var scope                               = Factory.Services.CreateScope();
            var scopedServices                      = scope.ServiceProvider;
            ParkingLotContext   context             = scopedServices.GetRequiredService <ParkingLotContext>();
            ParkingOrderService parkingOrderService = new ParkingOrderService(context);
            var parkingOrderDtoList                 = GenerateParkingOrderDtoList();

            foreach (var parkingOrderDto in parkingOrderDtoList)
            {
                await parkingOrderService.AddParkingOrder(parkingOrderDto);
            }

            // when
            var allParkingOrders = await parkingOrderService.GetAllParkingOrders();

            // then
            Assert.Equal(5, allParkingOrders.Count());
        }