private IEnumerable<SelectListItem> GetTeachers(int? selectedValue = null) { ApplicationDbContext context = new ApplicationDbContext(); var values = context.Teachers.ToList(); IEnumerable<SelectListItem> list = from value in values select new SelectListItem { //Text = value.ToString(), Text = String.Format("{0} {1} {2}", value.LastName, value.FirstName, value.MiddleName), Value = value.Id.ToString(), Selected = value.Id == selectedValue, }; return list; }
private IEnumerable<SelectListItem> GetClassrooms(int? selectedValue = null) { ApplicationDbContext context = new ApplicationDbContext(); var values = context.Classrooms.ToList(); IEnumerable<SelectListItem> list = from value in values select new SelectListItem { //Text = value.ToString(), Text = String.Format("{0} ({1} {2})", value.Number, value.Capacity, value.Type), Value = value.Id.ToString(), Selected = value.Id == selectedValue, }; return list; }
private IEnumerable<SelectListItem> GetLessons(int? selectedValue = null) { ApplicationDbContext context = new ApplicationDbContext(); var values = context.Lessons.ToList(); IEnumerable<SelectListItem> list = from value in values select new SelectListItem { //Text = value.ToString(), Text = value.Title, Value = value.Id.ToString(), Selected = value.Id == selectedValue, }; return list; }
//ApplicationDbContext context = new ApplicationDbContext(); // // GET: /Schedule/ public ActionResult Index() { using (ApplicationDbContext context = new ApplicationDbContext()) { //var a = context.Groups.ToList(); ViewBag.Groups = context.Groups.OrderBy(i => i.Title).ToList(); //int semesterId = context.Semesters.Where(i => i.StartsOn.Year == DateTime.Now.Year).Single().Id; int semesterId = 1; var schedules = context.ScheduleItems.Where(i => i.SemesterId == semesterId) .Include(i => i.Group) .Include(i => i.Lesson) .Include(i => i.Teacher) .Include(i => i.Classroom) .Include(i => i.Semester) .ToList(); Hashtable schedulesHashtable = new Hashtable(); foreach (var item in schedules) { string key = String.Format("{0}_{1}_{2}_{3}_{4}", item.SemesterId, item.DayOfWeek, item.LessonNumber,item.GroupId, item.LessonFrequency); if(schedulesHashtable.ContainsKey(key) == false) schedulesHashtable.Add(key, item); } ViewBag.SchedulesHashtable = schedulesHashtable; ViewBag.Semester = semesterId; return View(); } }