예제 #1
0
        public IActionResult Index(int?year, int?month)
        {
            ViewBag.text       = "Calendar";
            ViewBag.StudioName = _studioDataAccess.GetStudioInfo(GetCurrentStudioId()).Name;
            //calendarHelp.AddDaysToCalendar();
            List <DayVM> days = calendarDataAccess.GetDays();

            var model = new CalendarSearchVM();

            model.Year  = year ?? DateTime.Now.Year;
            model.Month = month ?? DateTime.Now.Month;
            model.Days  = days;

            model.CalendarData = calendarDataAccess.GetAllClassesShedule(model, GetCurrentStudioId());

            return(View("Views/Studio/Calendar.cshtml", model));
        }
        public List <CalendarData> GetAllClassesShedule(CalendarSearchVM calendarSearch, int studioId)
        {
            var calData = new List <CalendarData>();

            List <Class> classes = classDataAccess.GetAllClasses(studioId);

            foreach (var _class in classes)
            {
                List <Shedule>    shedules      = classDataAccess.GetClassShedule(_class.Id);
                List <int>        idInstructors = classDataAccess.GetInstructorsConnectedToClass(_class.Id, studioId);
                List <Instructor> instructors   = new List <Instructor>();

                foreach (var id in idInstructors)
                {
                    instructors.Add(instructorDataAccess.GetInstructorById(id));
                }

                foreach (var s in shedules)
                {
                    List <DayVM> classesDays = new List <DayVM>();
                    foreach (var day in calendarSearch.Days)
                    {
                        if ((day.Day.DayOfWeek.ToString() == s.Day) && _class.StartDay.Date < day.Day.Date)
                        {
                            classesDays.Add(new DayVM {
                                Day = day.Day.Date, WorkDay = day.WorkDay
                            });
                        }
                    }
                    calData.Add(new CalendarData {
                        Hour = s.Hour, Level = _class.Level, Name = _class.Genre, SheduleDays = classesDays, Instructors = instructors, NumberOfStudents = _class.NumberOfStudents
                    });
                }
            }

            return(calData);
        }
 public CalendarEventGenerator(CalendarSearchVM calendarData, DateTime day)
 {
     _calendarData = calendarData;
     _day          = day;
 }