private void OnReportReservationButtonClick(object sender, EventArgs args) { string name = nameTextBox.Text; string description = descriptionTextBox.Text; int facilityListIndex = facilityComboBox.SelectedIndex; DateTime start = fromDatePicker.Value; DateTime end = toDatePicker.Value; ReservationRequestEventArgs eventArgs = new ReservationRequestEventArgs(name, description, facilityListIndex, start, end); ReservationRequest?.Invoke(sender, eventArgs); }
private void ReportReservation(object sender, ReservationRequestEventArgs requestData) { try { model.ReportReservation(requestData); model.UpdateDataGrid(); view.SetDataGridsDataSource(model.DataGridItems); } catch (FacilityNotChoosenException ex) { MessageBox.Show("Musisz wybrać obiekt na którym będą odbywały się zajęcia!"); } catch (InvalidTimePeriodException ex) { MessageBox.Show("Proszę wybrać poprawny przedział czasu!"); } }
public void ReportReservation(ReservationRequestEventArgs requestData) { if (requestData.End < requestData.Start) { throw new InvalidTimePeriodException(); } using (var context = new DatabaseConnection()) { var creator = context.employees.Where(i => i.ACCOUNT_ID == Account.ID).FirstOrDefault(); var training = CreateNewTraining(requestData.Name, requestData.Description); var facility = GetFacility(requestData.FacilityListIndex, context); var coach = context.coaches.Where(i => i.EMPLOYEE_ID == creator.ID).FirstOrDefault(); coach.trainings.Add(training); IEnumerable <reservations> reservationsList = ReservationsCreator.Create(WeekSchedule, requestData, creator, training, facility); foreach (reservations reservation in reservationsList) { context.reservations.Add(reservation); } context.SaveChanges(); } }
public static IEnumerable <reservations> Create(Dictionary <DayOfWeek, Tuple <DateTime, DateTime> > weekSchedule, ReservationRequestEventArgs requestData, employees creator, trainings training, facilities facility) { int[] weekScheduleDaysDistances = ComputeDaysDistances(weekSchedule); List <reservations> reservations = new List <reservations>(); DateTime currentDate = requestData.Start; //set date pointer to first day from weekSchedule while (currentDate.DayOfWeek != weekSchedule.Keys.First() && currentDate <= requestData.End) { try { var timePeriod = weekSchedule[currentDate.DayOfWeek]; reservations.Add(CreateSingleReservation(creator, facility, currentDate, timePeriod, training)); } catch (Exception ex) { //TODO: implement handlers of exceptions occured while inserting to database } finally { currentDate = currentDate.AddDays(1.00); } } int i = 0; //main algorithm while (currentDate <= requestData.End) { try { var timePeriod = weekSchedule[currentDate.DayOfWeek]; reservations.Add(CreateSingleReservation(creator, facility, currentDate, timePeriod, training)); } catch (Exception ex) { //when week schedule doesnt contain key } finally { currentDate = currentDate.AddDays(weekScheduleDaysDistances[i++ % weekScheduleDaysDistances.Length]); } } return(reservations); }