public async Task CreateBooking_Success() { await _repository.CreateBooking(1, 0); Booking booking = _context.Booking.First(); Assert.IsNotNull(booking); Assert.AreEqual(1, booking.CustomerId); Assert.AreEqual(0, booking.FlightNumber); }
public ActionResult CreateBooking(BookingViewModel model) { using (var repo = new BookingRepository()) { //Double check no new booking was made while user captured data var available = new BookingChecker().CheckBookingAvailable(model.Date, repo); if (!available) { string message = $"There are no more bookings available for the selected date {model.Date.ToShortDateString()}"; ModelState.AddModelError("Date", message); return(RedirectToAction(nameof(MessageBooking), new { Message = message })); } if (ModelState.IsValid) { var entity = new Booking { Date = model.Date, Name = model.Name, Email = model.Email }; var result = repo.CreateBooking(entity); if (result.ID != 0) { return(RedirectToAction(nameof(MessageBooking), new { Message = $"You're booking was successfully created.{Environment.NewLine}Thank you." })); } } return(View(model)); } }
public BookingAvailability BookRoom(Booking booking, GoogleUserProfile user) { var logger = LogManager.GetLogger("BookingService"); logger.Info($"Executing Booking request for UserId {user.UserId}"); var existingLessons = ClassroomRepository.GetCoursesByRoomAndWeek(booking.Classroom, booking.Week); var blockingLessons = CourseAvailability(existingLessons, booking); logger.Info($"Booking: There are {blockingLessons.Count} blocking lessons"); if (blockingLessons.Count > 0) { logger.Info($"There was already a lesson planned during this time for this booking. {blockingLessons.Count}"); return(Engine.Bookings.BookingAvailability.Scheduled); } var existingBookings = BookingRepository.GetBookingsByRoomAndWeek(booking.Classroom, booking.Week); var blockingBookings = BookingAvailability(existingBookings, booking); logger.Info($"Booking: There are {blockingBookings.Count} blocking bookings"); if (blockingBookings.Count > 0) { logger.Info($"There was already a booking planned during this time for this booking. {blockingBookings.Count}"); return(Engine.Bookings.BookingAvailability.Booked); } logger.Info($"No blocking lessons or bookings. Creating new booking"); booking.Owner = user.UserId; booking.Lokaal = ClassroomRepository.GetClassroomById(booking.Classroom); BookingRepository.CreateBooking(booking); logger.Info($"Booking success"); return(Engine.Bookings.BookingAvailability.Success); }
public async Task <(bool, Exception)> CreateBooking(string customerName, int flightNumber) { try { Customer customer; try { customer = await _customerRepository.GetCustomerByName(customerName); } catch (CustomerNotFoundException) { await _customerRepository.CreateCustomer(customerName); return(await CreateBooking(customerName, flightNumber)); } await _bookingRepository.CreateBooking(customer.CustomerId, flightNumber); return(true, null); } catch (Exception exception) { return(false, exception); } }
public async Task <(bool, Exception)> CreateBooking(string name, int flightNumber) { if (string.IsNullOrEmpty(name) || !flightNumber.IsPositiveInteger()) { return(false, new ArgumentException()); } try { Customer customer = await GetCustomerFromDatabase(name) ?? await AddCustomerToDatabase(name); if (!await FlightExistsInDatabase(flightNumber)) { return(false, new CouldNotAddBookingToDatabaseException()); } await _bookingRepository.CreateBooking(customer.CustomerId, flightNumber); return(true, null); } catch (Exception exception) { return(false, exception); } }
public async Task CreateBooking([FromBody] BookingDto booking) { try { await _bookingRepository.CreateBooking(booking); } catch (Exception ex) { } }
private async void Valider_Clicked(object sender, System.EventArgs e) { Booking b = new Booking { Date = ((ReservationViewModel)this.BindingContext).Date.Date, StartHour = ((ReservationViewModel)this.BindingContext).StartHour.Hours, EndHour = ((ReservationViewModel)this.BindingContext).EndHour.Hours, SpaceId = idSpace, UserId = 2, NbAttendees = ((ReservationViewModel)this.BindingContext).NbAttendees, }; string message = await bookingRepository.CreateBooking(b); await DisplayAlert("Création de l'espace", message, "Ok"); if (!message.Contains("pas disponible") && !message.Contains("Erreur")) { await Navigation.PushAsync(new Reservation(idSpace)); } }
private async void Valider_Clicked(object sender, System.EventArgs e) { Booking b = new Booking { Date = ((ReservationViewModel)this.BindingContext).Date.Date, StartHour = ((ReservationViewModel)this.BindingContext).StartHour.Hours, EndHour = ((ReservationViewModel)this.BindingContext).EndHour.Hours, SpaceId = idSpace, UserId = 2, NbAttendees = ((ReservationViewModel)this.BindingContext).NbAttendees, }; if (await bookingRepository.CreateBooking(b)) { await DisplayAlert("Création de l'espace", "L'espace a bien été créé", "Ok"); await Navigation.PushAsync(new Reservation(idSpace)); } else { await DisplayAlert("Création de l'espace", "Échec de la création de la réservation", "Ok"); } ; }
public void AddBooking(Booking booking) { bookingRepo.CreateBooking(booking); }