public BookDeskResult BookDesk(BookDeskRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } var isValid = IsValidRequest(request); var avaiableDesks = _deskRepository.GetAvailableDesks(request.Date); var result = Create <BookDeskResult>(request); if (avaiableDesks.FirstOrDefault() is Desk availableDesk) { var bookDesk = Create <BookDesk>(request); bookDesk.DeskId = availableDesk.Id; var bookingId = _repo.Save(bookDesk); result.ResultCode = DeskBookingResultCode.Success; result.BookingId = bookingId; } else { result.ResultCode = DeskBookingResultCode.NotAvailableDesks; } return(result); }
public DeskBookingResult BookDesk(DeskBookingRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } var result = Create <DeskBookingResult>(request); var availableDesks = _deskRepository.GetAvailableDesks(request.Date); if (availableDesks.Count() > 0) { var availableDesk = availableDesks.First(); var deskBooking = Create <DeskBooking>(request); deskBooking.DeskId = availableDesk.Id; _deskBookingRepository.Save(deskBooking); result.Code = DeskBookingResultCode.Success; } else { result.Code = DeskBookingResultCode.NoDeskAvailable; } return(result); }
public DeskBooking CreateBooking(DeskBookingRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } var availableDesks = _deskRepository.GetAvailableDesks(request.Date); var deskBooking = Create <DeskBooking>(request); deskBooking.DeskId = availableDesks.First().Id; _deskBookingRepository.Save(deskBooking); return(deskBooking); }
public BookDeskRequestResult BookDesk(BookDeskRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } var resultCode = DeskBookingResultCode.NoDeskAvailable; if (deskRepository.GetAvailableDesks(request.Date).FirstOrDefault() is Desk desk) { var booking = Create <DeskBooking>(request); booking.DeskId = desk.Id; deskBookingRepository.Save(booking); resultCode = DeskBookingResultCode.Success; } var result = Create <BookDeskRequestResult>(request); result.ResultCode = resultCode; return(result); }
public DeskBookingResult BookDesk(DeskBookingRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } // Static Create<T> method, create return result. var result = Create <DeskBookingResult>(request); // Determine if booking is available, search by date. var availableDesks = _deskRepository.GetAvailableDesks(request.Date); // Check for return booking. if (availableDesks.FirstOrDefault() is Desk availableDesk) { // Booking is available, create request. var deskBooking = Create <DeskBooking>(request); // Assign booking Id. deskBooking.DeskId = availableDesk.Id; // Save booking. _deskBookingRepository.Save(deskBooking); // Assign booking Id to result. result.DeskBookingId = deskBooking.Id; // Return status code and result. result.Code = DeskBookingResultCode.Success; } else { // Booking not available, return status code. result.Code = DeskBookingResultCode.NoDeskAvailable; } // Return booking result :: status codes "Success" or "NoDeskAvailable". return(result); }
public DeskBookingResult BookDesk(DeskBookingRequest request) { if (request == null) { throw new ArgumentNullException(nameof(DeskBookingRequest)); } var result = Create <DeskBookingResult>(request); if (_deskRepository.GetAvailableDesks(request.Date).FirstOrDefault() is Desk available) { var deskbooking = Create <DeskBooking>(request); deskbooking.DeskId = available.Id; _deskBookingRepository.Save(deskbooking); result.BookingDeskId = deskbooking.Id; result.Code = DeskBookingResultCode.Success; } else { result.Code = DeskBookingResultCode.NoDeskAvailabel; } return(result); }
public async Task <DeskBookingResponse> BookDeskAsync(DeskBookingRequest request) { if (request is null) { throw new ArgumentNullException(nameof(request)); } var desks = await _deskRepository.GetAvailableDesks(request.Date); DeskBookingResponse response = Create <DeskBookingResponse>(request); if (desks.FirstOrDefault() is Desk availableDesks) { var deskBooking = Create <DeskBooking>(request); deskBooking.DeskId = availableDesks.Id; _deskBookingRepository.Save(deskBooking); response.ResultCode = DeskBookingResultCode.Available; response.DeskBookingId = deskBooking.Id; } else { response.ResultCode = DeskBookingResultCode.NotAvailable; } return(response); }