private void button_Click(object sender, RoutedEventArgs e) { var preReservation = new PreReservationViewModel { FromWhatTime = TimeSpan.Parse(ComboBoxGodzinaOdPreRezerwacji.Text), ToWhatTime = TimeSpan.Parse(ComboBoxGodzinaDoPreRezerwacji.Text), HowManyPeoples = int.Parse(TextBoxPreReservationIloscOsob.Text), ReservationDate = DatePickerDataPreRezerwacji.SelectedDate.Value }; try { if (_serviceReservationOperation.CheckPreReservation(preReservation)) { _outputCalendar.MessageForAvailableTable(ComunicationLabel); } else { _outputCalendar.MessageForNpotaAvailableTable(ComunicationLabel); } } catch (Exception) { _outputCalendar.MessageForErrorDuringReserwation(ComunicationLabel); } }
public RequestAvaibility Check(PreReservationViewModel preReservation) { var result = new RequestAvaibility(); var freeTables = GetAvailable(preReservation); AddTables(ref freeTables, preReservation.HowManyPeoples, ref result); return(result); }
private static bool CheckIfFree(this IEnumerable <Model.Models.Reservation> reservations, PreReservationViewModel preReservation) { if (reservations.Any()) { var available = reservations.Where(r => r.ReservationDate == preReservation.ReservationDate & !(r.FromWhatTime >= preReservation.ToWhatTime || r.ToWhatTime <= preReservation.FromWhatTime)).ToList(); return(available.Count == 0); } return(true); }
public void WhenCheckingPreReservation_ThenReturnTwotables(int howmanyPeoples) { var preReservation = new PreReservationViewModel { FromWhatTime = new TimeSpan(12, 0, 0), ToWhatTime = new TimeSpan(13, 30, 0), HowManyPeoples = howmanyPeoples, ReservationDate = new DateTime(2018, 9, 19) }; IServiceReservation service = new ReservationService(); var check = service.GetAvailable(preReservation); }
public void WhenCheckingPreReservation_ThenReturnFalse(int howmanyPeoples) { var preReservation = new PreReservationViewModel { FromWhatTime = new TimeSpan(12, 0, 0), ToWhatTime = new TimeSpan(13, 30, 0), HowManyPeoples = howmanyPeoples, ReservationDate = new DateTime(2018, 9, 19) }; IServiceReservation service = new ReservationService(); var check = service.CheckPreReservation(preReservation); Assert.IsFalse(check); }
public bool CheckPreReservation(PreReservationViewModel preReservation) { return(Check(preReservation).IsAvailable); }
public List <Table> GetAvailable(PreReservationViewModel preReservation) { var tables = _tableRepository.TablesEager().GetFree(preReservation); return(tables); }
public static List <Table> GetFree(this List <Table> tables, PreReservationViewModel preReservation) { return(tables.Where(t => t.Reservation.CheckIfFree(preReservation)).ToList()); }