public void CreateBooking(CreateBookingDto createBooking) { try { VehicleBooking vehicle = _mapper.Map <VehicleBooking>(createBooking.vehicleBooking); vehicle.confirmationCode = ConfirmationCode.RandomString(); _repositoryFactory.VehicleBookingRepository.Create(vehicle); SendMail(vehicle); _logger.LogInformation("Vehicle booking created"); List <EquipmentBooking> equipmentBookings = _mapper.Map <List <EquipmentBooking> >(createBooking.equipmentBookings); foreach (var e in equipmentBookings) { e.vehicleBookingId = vehicle.id; } _repositoryFactory.EquipmentBookingRepository.CreateEquipmentBooking(equipmentBookings); _logger.LogInformation("Equipment booking created"); } catch (Exception ex) { _logger.LogWarning(ex.Message); throw ex; } }
public IActionResult CreateBooking([FromBody] CreateBookingDto bookingDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { _bookingService.CreateBooking(bookingDto); return(Ok()); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <ActionResult> CreateBooking(CreateBookingDto dto) { await _bookingService.CreateAsync(dto); foreach (var items in dto.BookingDetails) { var check = await _stockService.CheckIfExist(items.ProductId); if (check != null) { check.TotalPieces -= items.TotalPieces; check.Amount -= items.Amount; await _stockService.UpdateAsync(check); } } return(Ok(dto)); }