public async Task <IActionResult> AddPreBooking(PreBookingForAdd model) { if (!ModelState.IsValid) { return(BadRequest()); } var dateTimePickUpArray = model.PickUpDate.Split(" "); var dateTimeReturnArray = model.ReturnDate.Split(" "); var dateTimePickUp = dateTimePickUpArray[1] + " " + dateTimePickUpArray[2] + " " + dateTimePickUpArray[3] + " " + dateTimePickUpArray[4]; var dateTimeReturn = dateTimeReturnArray[1] + " " + dateTimeReturnArray[2] + " " + dateTimeReturnArray[3] + " " + dateTimeReturnArray[4]; var dateTimePickUpFinal = Convert.ToDateTime(dateTimePickUp); var dateTimeReturnFinal = Convert.ToDateTime(dateTimeReturn); var preBooking = new PreBooking(); preBooking.PickLocationId = model.PickUpLocationId; preBooking.ReturnLocationId = model.ReturnLocationId; preBooking.PickDate = dateTimePickUpFinal; preBooking.ReturnDate = dateTimeReturnFinal; preBooking.AgeOfUser = model.DriverAge; preBooking.CreateOnDate = DateTime.Now; preBooking.IsDeleted = false; await _preBookingService.AddPreBooking(preBooking); await _preBookingService.SaveChanges(); return(Ok(new { message = "PreBooking added successfully", pb = preBooking.Id, car = model.CarId })); }
public async Task <IActionResult> GetPreBookingById(int id) { if (id == 0) { return(BadRequest("PreBooking not found")); } var preBooking = await _preBookingService.GetPreBookingByIdAsync(id); var model = new PreBookingForAdd { Id = preBooking.Id, DriverAge = (int)preBooking.AgeOfUser, PickUpDateReal = (DateTime)preBooking.PickDate, PickUpLocationId = preBooking.PickLocationId, ReturnDateReal = (DateTime)preBooking.ReturnDate, ReturnLocationId = preBooking.ReturnLocationId, }; return(Ok(model)); }