Example #1
0
        public BookingEventModel(BookingEvent e)
        {
            Id               = e.Id;
            Name             = e.Name;
            Description      = e.Description;
            Schedules        = new List <ScheduleEventModel>();
            DeletedSchedules = new List <long>();

            EditMode     = false;
            EditAccess   = false;
            DeleteAccess = false;

            using (BookingEventManager em = new BookingEventManager())
            {
                //Get event again as not everything needed already fetched
                var event_ = em.GetBookingEventById(e.Id);


                foreach (Schedule s in event_.Schedules)
                {
                    ScheduleEventModel seM = new ScheduleEventModel(s);
                    seM.Index      = s.Index;
                    seM.EditMode   = false;
                    seM.EventId    = e.Id;
                    seM.Activities = new List <ActivityEventModel>();
                    s.Activities.ToList().ForEach(r => seM.Activities.Add(new ActivityEventModel(r)));
                    Schedules.Add(seM);
                }
            }
        }
Example #2
0
        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);
                    }
        }