private facilities GetFacility(int facilityListIndex, DatabaseConnection context) { try { int facilityId = Facilities[facilityListIndex].ID; facilities facility = context.facilities.Where(i => (i.ID == facilityId)).FirstOrDefault(); return(facility); } catch (ArgumentOutOfRangeException ex) { throw new FacilityNotChoosenException(); } }
public virtual IList <DataGridRow> LoadFromDatabase(DatabaseConnection context, int?creatorId = null) { IList <DataGridRow> rowsList = new List <DataGridRow>(); var reservationList = context.reservations.Where(i => (creatorId != null) ? i.CREATOR_ID == creatorId : true).ToList(); foreach (reservations reservation in reservationList) { trainings training = context.trainings.Where(i => i.ID == reservation.TRAINING_ID).FirstOrDefault(); facilities facility = context.facilities.Where(i => i.ID == reservation.FACILITY_ID).FirstOrDefault(); DataGridRow row = new DataGridRow(id: reservation.ID, facilityName: facility?.NAME, trainingName: training?.NAME, accepted: reservation.ACCEPTED, start: reservation.START, end: reservation.END); rowsList.Add(row); } return(rowsList); }
private static reservations CreateSingleReservation(employees creator, facilities facility, DateTime date, Tuple <DateTime, DateTime> timePeroid = null, trainings training = null, admins admin = null, bool?accepted = null, events orgranisedEvent = null, ICollection <schedules> schedules = null) { reservations newReservation = new reservations(); newReservation.admins = admin; newReservation.employees = creator; newReservation.events = orgranisedEvent; newReservation.facilities = facility; newReservation.schedules = schedules; newReservation.trainings = training; newReservation.START = ((date.AddHours(timePeroid.Item1.Hour)).AddMinutes(timePeroid.Item1.Minute)); newReservation.END = ((date.AddHours(timePeroid.Item2.Hour)).AddMinutes(timePeroid.Item2.Minute)); newReservation.ACCEPTED = accepted; return(newReservation); }
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); }