public async Task <ActionResult <OrderDto> > CreateOrderAsync(CarOrderDto carOrder) { if (string.IsNullOrEmpty(carOrder.PlateNumber) || string.IsNullOrEmpty(carOrder.ParkingLotName)) { return(BadRequest("Plate Number and Parking Lot Name cannot be null.")); } if (!await parkingLotService.IsParkingLotExistedAsync(carOrder.ParkingLotName)) { return(NotFound("ParkingLot not existed.")); } if (await IsParkingLotFullAsync(carOrder.ParkingLotName)) { return(BadRequest("The parking lot is full")); } if (await orderService.IsCarExisted(carOrder.PlateNumber)) { return(BadRequest("The car already existed.")); } var order = await orderService.CreateOrderAsync(carOrder.ParkingLotName, carOrder.PlateNumber); return(CreatedAtAction(nameof(GetByOrderNumber), new { orderNumber = order.OrderNumber }, order)); }
public async Task <ActionResult <int> > DeleteParkingLotAsync(string name) { if (!await parkingLotService.IsParkingLotExistedAsync(name)) { return(NotFound("The parking lot is not existed.")); } if (await orderService.GetOrderOpenedInParkingLotAsync(name) != 0) { return(BadRequest("The Parking Lot is not empty.")); } await parkingLotService.DeleteParkingLotByIdAsync(name); return(NoContent()); }