public async Task <IActionResult> CreateBookingRequest([FromBody] BookingRequest_Create bookingRequest) { var customerId = this.UserId(); bookingRequest.CustomerId = customerId; return(new OkObjectResult(await _bookingRequestService.CreateBooking(bookingRequest, this.ClientId()))); }
public async Task CreateBooking_Should_ThrowException_WhenCustomerIdIsNull() { // Arrange var clientId = Guid.NewGuid(); var customerId = Guid.NewGuid(); var sut = new BookingRequestService(repo, customerService); var newBooking = new BookingRequest_Create { Registration = "EF02VCC" }; // Act & Assert await Assert.ThrowsAsync <Exception>(async() => await sut.CreateBooking(newBooking, clientId)); }
public async Task CreateBooking_Should_IncreaseRowCountByOne() { // Arrange var clientId = Guid.NewGuid(); var customerId = Guid.NewGuid(); var beforeCount = (await repo.FindAllByCustomer(customerId, clientId)).Count(); var sut = new BookingRequestService(repo, customerService); var newBooking = new BookingRequest_Create { Registration = "EF02VCC", CustomerId = customerId }; // Act await sut.CreateBooking(newBooking, clientId); // Assert var afterCount = (await repo.FindAllByCustomer(customerId, clientId)).Count(); Assert.Equal(beforeCount + 1, afterCount); }
public async Task <BookingRequest> CreateBooking(BookingRequest_Create req, Guid clientId) { if (req.CustomerId == Guid.Empty) { throw new Exception("CustomerId was not set"); } var customer = await customers.GetById(req.CustomerId.ToString(), clientId.ToString()); var vehicle = customer?.CustomerData?.MyVehicles?.FirstOrDefault(x => x.Registration == req.Registration); try { var booking = new BookingRequest { Registration = req.Registration, MOT = req.MotRequest, Service = req.ServiceRequest, PreferedDate = req.PreferedDate, PreferedTime = req.PreferedTime, Message = req.Message, Confirmed = false, Cancelled = false, ConfirmationEmailSent = false, Vehicle = vehicle, Customer = new BookingCustomer { Id = Guid.Parse(customer.Id), ClientId = Guid.Parse(customer.ClientId.Id), FirstName = customer.FirstName, LastName = customer.LastName, EmailAddress = customer.EmailAddress, ContactNumber = customer.ContactNumber }, RequestDate = DateTime.UtcNow, }; return(await bookings.Create(booking, req.CustomerId, clientId)); } catch (Exception ex) { Debug.WriteLine(ex.Message); throw; } }