public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Group group = db.Groups.Find(id); if (group == null) { return(HttpNotFound()); } var GroupTeacherSubject = group.TeachersSubjects.ToList(); List <string> GTS = new List <string>(); Models.Teachers.Teacher teacher_buf = new Models.Teachers.Teacher(); Models.Teachers.Subject subj_buf = new Models.Teachers.Subject(); foreach (var c in GroupTeacherSubject) { if (c.TeacherId != null) { teacher_buf = db.Teachers.Find(c.TeacherId); subj_buf = db.Subjects.Find(c.SubjectId); GTS.Add(teacher_buf.SurName + " " + teacher_buf.Name + " " + teacher_buf.LastName.ToString() + " / " + subj_buf.Name); } } ViewBag.Teachers = GTS; ViewBag.CountStudents = group.Users.Count(); return(View(group)); }
public ActionResult AddNewTeacher(AddNewTeacherViewModel model) { if (ModelState.IsValid) { var teacher = new Models.Teachers.Teacher(); teacher.Name = model.Name; teacher.SurName = model.SurName; teacher.LastName = model.LastName; string path = AppDomain.CurrentDomain.BaseDirectory + "TeacherImg/"; string filename = System.IO.Path.GetFileName(model.Photo.FileName); model.Photo.SaveAs(System.IO.Path.Combine(path, filename)); teacher.PathToPhoto = Server.MapPath(model.Photo.FileName); db.Teachers.Add(teacher); db.SaveChanges(); return RedirectToAction("Index", "Home"); } return View(model); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var search = db.TeacherSubject.Where(x => x.TeacherId == null); foreach (var del in search.ToList()) { db.TeacherSubject.Remove(del); } Group group = db.Groups.Find(id); if (group == null) { return(HttpNotFound()); } var GroupTeacherSubject = group.TeachersSubjects.ToList(); var TeacherSubject = db.TeacherSubject.ToList(); var dictionaryTSTrue = new Dictionary <int, string>(); // Викладач і предмет, які вже зареєстровані в групі var dictionaryTSFalse = new Dictionary <int, string>(); // які не зареєстровані в групі //Якщо у групі немає зареєстрованих викладачів та пердметів //Додаємо у словник весь перелік викладачів та предметів Models.Teachers.Teacher teacher_buf = new Models.Teachers.Teacher(); Models.Teachers.Subject subj_buf = new Models.Teachers.Subject(); if (GroupTeacherSubject.Count == 0) { foreach (var c in TeacherSubject) { teacher_buf = db.Teachers.Find(c.TeacherId); subj_buf = db.Subjects.Find(c.SubjectId); dictionaryTSFalse.Add(c.Id, teacher_buf.SurName + " " + teacher_buf.Name + " " + teacher_buf.LastName.ToString() + " / " + subj_buf.Name); } } //В іншому випадку - розділяємо їх на два словники else { foreach (var GTS in GroupTeacherSubject) { if (GTS.TeacherId != null) { teacher_buf = db.Teachers.Find(GTS.TeacherId); subj_buf = db.Subjects.Find(GTS.SubjectId); dictionaryTSTrue.Add(GTS.Id, teacher_buf.LastName.ToString() + " " + teacher_buf.Name.ToString() + " " + teacher_buf.SurName.ToString() + " / " + subj_buf.Name.ToString()); } } foreach (var GTS in TeacherSubject) { if (dictionaryTSTrue.Any(m => m.Key == GTS.Id) == false && GTS.TeacherId != null) { teacher_buf = db.Teachers.Find(GTS.TeacherId); subj_buf = db.Subjects.Find(GTS.SubjectId); dictionaryTSFalse.Add(GTS.Id, teacher_buf.LastName + " " + teacher_buf.Name + " " + teacher_buf.SurName.ToString() + " / " + subj_buf.Name); } } } var dictionaryTS = new Dictionary <bool, Dictionary <int, string> >(); dictionaryTS.Add(true, dictionaryTSTrue); dictionaryTS.Add(false, dictionaryTSFalse); ViewBag.DictionaryTS = dictionaryTS; return(View(group)); }
public ActionResult Details(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Group group = db.Groups.Find(id); if (group == null) { return HttpNotFound(); } var GroupTeacherSubject = group.TeachersSubjects.ToList(); List<string> GTS = new List<string>(); Models.Teachers.Teacher teacher_buf = new Models.Teachers.Teacher(); Models.Teachers.Subject subj_buf = new Models.Teachers.Subject(); foreach (var c in GroupTeacherSubject) { if (c.TeacherId != null) { teacher_buf = db.Teachers.Find(c.TeacherId); subj_buf = db.Subjects.Find(c.SubjectId); GTS.Add(teacher_buf.SurName + " " + teacher_buf.Name + " " + teacher_buf.LastName.ToString() + " / " + subj_buf.Name); } } ViewBag.Teachers = GTS; ViewBag.CountStudents = group.Users.Count(); return View(group); }
public ActionResult Edit(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } var search = db.TeacherSubject.Where(x => x.TeacherId == null); foreach (var del in search.ToList()) db.TeacherSubject.Remove(del); Group group = db.Groups.Find(id); if (group == null) { return HttpNotFound(); } var GroupTeacherSubject = group.TeachersSubjects.ToList(); var TeacherSubject = db.TeacherSubject.ToList(); var dictionaryTSTrue = new Dictionary<int, string>(); // Викладач і предмет, які вже зареєстровані в групі var dictionaryTSFalse = new Dictionary<int, string>(); // які не зареєстровані в групі //Якщо у групі немає зареєстрованих викладачів та пердметів //Додаємо у словник весь перелік викладачів та предметів Models.Teachers.Teacher teacher_buf = new Models.Teachers.Teacher(); Models.Teachers.Subject subj_buf = new Models.Teachers.Subject(); if (GroupTeacherSubject.Count == 0) { foreach (var c in TeacherSubject) { teacher_buf = db.Teachers.Find(c.TeacherId); subj_buf = db.Subjects.Find(c.SubjectId); dictionaryTSFalse.Add(c.Id, teacher_buf.SurName + " " + teacher_buf.Name + " " + teacher_buf.LastName.ToString() + " / " + subj_buf.Name); } } //В іншому випадку - розділяємо їх на два словники else { foreach (var GTS in GroupTeacherSubject) { if (GTS.TeacherId != null) { teacher_buf = db.Teachers.Find(GTS.TeacherId); subj_buf = db.Subjects.Find(GTS.SubjectId); dictionaryTSTrue.Add(GTS.Id, teacher_buf.LastName.ToString() + " " + teacher_buf.Name.ToString() + " " + teacher_buf.SurName.ToString() + " / " + subj_buf.Name.ToString()); } } foreach (var GTS in TeacherSubject) { if (dictionaryTSTrue.Any(m => m.Key == GTS.Id) == false && GTS.TeacherId != null) { teacher_buf = db.Teachers.Find(GTS.TeacherId); subj_buf = db.Subjects.Find(GTS.SubjectId); dictionaryTSFalse.Add(GTS.Id, teacher_buf.LastName + " " + teacher_buf.Name + " " + teacher_buf.SurName.ToString() + " / " + subj_buf.Name); } } } var dictionaryTS = new Dictionary<bool, Dictionary<int, string>>(); dictionaryTS.Add(true, dictionaryTSTrue); dictionaryTS.Add(false, dictionaryTSFalse); ViewBag.DictionaryTS = dictionaryTS; return View(group); }