public async Task <IActionResult> CreateBookingAsync([FromBody] BookingCreateRequest request) { if (!ModelState.IsValid) { throw new ServiceException(400, "Model is invalid"); } //request.MemberName = Request.Headers["X-Forwarded-Username"]; //request.MemberEmail = Request.Headers["X-Forwarded-Email"]; return(Ok(await _bookingService.CreateBookingAsync(request))); }
public async Task <BookingCreateResponse> CreateBookingAsync(BookingCreateRequest request) { if (await IsDuplicate(request.RoomId, request.From, request.To)) { throw new ServiceException(400, "Duplicate Entry"); } var booking = _mapper.Map <Booking>(request); booking.MemberName = _cache.Username; booking.MemberEmail = _cache.Email; _context.Bookings.Add(booking); await _context.SaveChangesAsync(); return(_mapper.Map <BookingCreateResponse>(booking)); }