public ActionResult TeachersCalendar()
        {
            GetUIDropdownLists();
            ViewBag.Message = "Teachers Calendar.";
            var calendars = _repositoryServices.GetTeacherCalendar();

            if (calendars == null)
            {
                ModelState.AddModelError("NoTeacherCalendar", "Teacher hasn't a calendar booking");
            }
            if (!ModelState.IsValid)
            {
                return(View());
            }
            var calendarBookingViewModels = new List <CalendarBookingViewModel>();
            var classRooms = _repositoryServices.GetClassrooms();

            if (calendars != null)
            {
                var calendarsLeftJoin = from cal in calendars
                                        join cls in classRooms on
                                        cal.CalendarBookingId equals cls.CalendarId into res
                                        from q in res.DefaultIfEmpty()
                                        select new
                {
                    ClassroomId   = q == null ? null : q.ClassroomId,
                    SubjectId     = cal.SubjectId,
                    TeacherId     = cal.TeacherId,
                    StudentId     = cal.StudentId,
                    BookingTimeId = cal.BookingTimeId
                };


                foreach (var cal in calendarsLeftJoin)
                {
                    var student     = _repositoryServices.GetStudentById(cal.StudentId);
                    var subject     = _repositoryServices.GetSubjectById(cal.SubjectId);
                    var teacher     = _repositoryServices.GetTeacherById(cal.TeacherId);
                    var bookingTime = _repositoryServices.GetBookingById(cal.BookingTimeId);

                    if (bookingTime == null)
                    {
                        continue;
                    }
                    calendarBookingViewModels.Add(new CalendarBookingViewModel {
                        ClassroomId = cal.ClassroomId, Teacher = teacher, Subject = subject, Student = student, BookingTime = bookingTime
                    });
                }
            }
            ViewBag.CalendarUiList = calendarBookingViewModels.ToArray();

            return(PartialView("TeachersCalendar", calendarBookingViewModels.Count() > 0 ? calendarBookingViewModels.ToArray()[calendarBookingViewModels.Count() - 1] : null));
        }
Beispiel #2
0
        public ActionResult BookTeacherHelpTime()
        {
            ViewBag.Message = "Book Teacher Time.";
            GetUIDropdownLists();

            var calendars = _teacherRepository.GetTeacherCalendar();
            var calendarBookingViewModels = new List <ICalendarBookingViewModel>();
            var classRooms = _teacherRepository.GetClassrooms();

            if (calendars != null)
            {
                var calendarsLeftJoin = from cal in calendars
                                        join cls in classRooms on
                                        cal.CalendarBookingId equals cls.CalendarId into res
                                        from q in res.DefaultIfEmpty()
                                        select new
                {
                    ClassroomId   = q == null ? null : q.ClassroomId,
                    SubjectId     = cal.SubjectId,
                    TeacherId     = cal.TeacherId,
                    StudentId     = cal.StudentId,
                    BookingTimeId = cal.BookingTimeId
                };


                foreach (var cal in calendarsLeftJoin)
                {
                    var student     = _teacherRepository.GetStudentById(cal.StudentId);
                    var subject     = _teacherRepository.GetSubjectById(cal.SubjectId);
                    var teacher     = _teacherRepository.GetTeacherById(cal.TeacherId);
                    var bookingTime = _teacherRepository.GetBookingById(cal.BookingTimeId);

                    if (bookingTime == null)
                    {
                        continue;
                    }
                    calendarBookingViewModels.Add(new CalendarBookingSelectOrDeleteViewModel {
                        ClassId = cal.ClassroomId, Teacher = teacher, Subject = subject, Student = student, BookingTime = bookingTime
                    });
                }
            }
            ViewBag.CalendarUiList = calendarBookingViewModels.ToArray();


            return(View("BookTeacherHelpTime"));
        }