public CalendarItemsModel(BookingEvent e) { using (var schManager = new ScheduleManager()) { List <Schedule> schedules = schManager.GetAllSchedulesByEvent(e.Id); eventId = e.Id; title = e.Name + " (" + e.Schedules.First().ByPerson.Person.DisplayName + ")"; start = (from d in schedules select d.StartDate).Min(); end = (from d in schedules select d.EndDate).Max(); color = "#3868c8"; // fix color, maybe later a other solution for the event color } }
private List <BookingEvent> GetAllEventsFiltered(bool byUser, string start_date = null, string end_date = null) { List <BookingEvent> eventList = new List <BookingEvent>(); List <BookingEvent> eventListTmp = new List <BookingEvent>(); using (BookingEventManager eManager = new BookingEventManager()) using (ScheduleManager schManager = new ScheduleManager()) using (SubjectManager subManager = new SubjectManager()) { if (Session["FilterSchedules"] == null) { if (start_date != null && end_date != null) { DateTime startDate = DateTime.Parse(start_date.ToString()); DateTime endDate = DateTime.Parse(end_date.ToString()); eventList = eManager.GetAllEventByTimePeriod(startDate, endDate); } else if (start_date != null && end_date == null) { DateTime startDate = DateTime.Parse(start_date.ToString()); eventList = eManager.GetAllEventByTimePeriod(startDate); } else { eventList = eManager.GetAllBookingEvents().ToList(); } if (byUser == true) { User user = subManager.Subjects.Where(a => a.Name == HttpContext.User.Identity.Name).FirstOrDefault() as User; foreach (BookingEvent e in eventList) { List <Schedule> schedules = schManager.GetAllSchedulesByEvent(e.Id); var s = FilterSchedulesByUser(schedules, user.Id).Concat(FilterSchedulesForUser(schedules, user.Id)).ToList(); if (s.Count > 0) { eventListTmp.Add(e); } } eventList = eventListTmp; } } else { List <Schedule> scheduleList = new List <Schedule>(); scheduleList = Session["FilterSchedules"] as List <Schedule>; // filter list by user if (byUser == true) { User user = subManager.Subjects.Where(a => a.Name == HttpContext.User.Identity.Name).FirstOrDefault() as User; var scheduleListNew = FilterSchedulesByUser(scheduleList, user.Id).Concat(FilterSchedulesForUser(scheduleList, user.Id)).ToList(); scheduleList = scheduleListNew.Distinct().ToList(); } // filter by start and end date if (start_date != null && end_date != null) { DateTime startDate = DateTime.Parse(start_date.ToString()); DateTime endDate = DateTime.Parse(end_date.ToString()); scheduleList = scheduleList.Where(a => ((DateTime)a.StartDate >= startDate && (DateTime)a.EndDate <= endDate) || ((DateTime)a.EndDate >= startDate && (DateTime)a.EndDate <= endDate) || (DateTime)a.StartDate <= startDate && (DateTime)a.EndDate >= endDate).ToList(); } else if (start_date != null && end_date == null) { DateTime startDate = DateTime.Parse(start_date.ToString()); scheduleList = scheduleList.Where(a => ((DateTime)a.EndDate >= startDate)).ToList(); } foreach (Schedule s in scheduleList) { if (!eventList.Select(a => a.Id).ToList().Contains(s.BookingEvent.Id)) { eventList.Add(eManager.GetBookingEventById(s.BookingEvent.Id)); } } } return(eventList); } }