public ActionResult Create(CreateSubDepartment subDepartmentModel) { if (this.ModelState.IsValid && subDepartmentModel.Description != null && subDepartmentModel.Name != null) { var adminId = this.User.Identity.GetUserId(); var subDepartment = new SubDepartment() { Name = subDepartmentModel.Name, Description = subDepartmentModel.Description, DepartmentId = subDepartmentModel.DepartmentId, AdminId = adminId }; using (var db = new SpecialtySelectorDbContext()) { db.SubDepartments.Add(subDepartment); db.SaveChanges(); return(RedirectToAction("Details", new { id = subDepartment.Id })); } } using (var db = new SpecialtySelectorDbContext()) { var departments = db.Departments.ToList(); ViewBag.Departments = departments; return(View(subDepartmentModel)); } }
public ActionResult Update(UpdateSubject updateSubject) { if (ModelState.IsValid && updateSubject != null) { using (var db = new SpecialtySelectorDbContext()) { var subjects = db.Subjects. Find(updateSubject.Id); var adminId = this.User.Identity.GetUserId(); var listOfTeachers = new List <Teacher>(); var listOfSpecialties = new List <Specialty>(); if (updateSubject.Teacher != null) { foreach (var teacher in updateSubject.Teacher) { var currentTeacher = db.Teachers.FirstOrDefault(t => t.Id == teacher); listOfTeachers.Add(currentTeacher); } } if (updateSubject.Specialty != null) { foreach (var specialty in updateSubject.Specialty) { var currentSpecialty = db.Specialties.FirstOrDefault(s => s.Id == specialty); listOfSpecialties.Add(currentSpecialty); } } subjects.AdminId = adminId; subjects.Name = updateSubject.Name; subjects.Description = updateSubject.Description; subjects.Course = updateSubject.Course; subjects.Credits = updateSubject.Credits; subjects.IsMandatory = updateSubject.IsMandatory; subjects.DeletedOn = updateSubject.DeletedOn; subjects.Specialties = listOfSpecialties; subjects.Teachers = listOfTeachers; subjects.Id = updateSubject.Id; db.SaveChanges(); } return(RedirectToAction("Details", new { id = updateSubject.Id })); } return(View(updateSubject)); }
public ActionResult Create(CreateTeacher createTeacher) { if (ModelState.IsValid && createTeacher != null) { using (var db = new SpecialtySelectorDbContext()) { var adminId = this.User.Identity.GetUserId(); var subnew = new List <Subject>(); if (createTeacher.Subject != null) { foreach (var kvp in createTeacher.Subject) { var asd = db.Subjects.FirstOrDefault(x => x.Id == kvp); subnew.Add(asd); } } var teacher = new Teacher() { FirstName = createTeacher.FirstName, SecondName = createTeacher.SecondName, AdminId = adminId, LastName = createTeacher.LastName, AcademicTitle = createTeacher.AcademicTitle, Degree = createTeacher.Degree, TeacherInfo = createTeacher.TeacherInfo, Subjects = subnew }; db.Teachers.Add(teacher); db.SaveChanges(); return(RedirectToAction("Details", new { id = teacher.Id })); } } using (var db = new SpecialtySelectorDbContext()) { var subjects = db.Subjects.ToList(); ViewBag.Subjects = subjects; return(View(createTeacher)); } }
public ActionResult Delete(int?id) { if (id == null) { return(HttpNotFound()); } using (var db = new SpecialtySelectorDbContext()) { Department department = db.Departments.FirstOrDefault(x => x.Id == id); if (department != null) { department.DeletedOn = DateTime.Now; } db.SaveChanges(); return(RedirectToAction("Index", "Home")); } }
public ActionResult Update(UpdateDepartment updateDepartment) { if (ModelState.IsValid) { using (var db = new SpecialtySelectorDbContext()) { var department = db.Departments .Find(updateDepartment.Id); department.Name = updateDepartment.Name; department.Description = updateDepartment.Description; department.DeletedOn = updateDepartment.DeletedOn; db.SaveChanges(); } return(RedirectToAction("Details", new { id = updateDepartment.Id })); } return(View(updateDepartment)); }
public ActionResult Delete(int?id) { if (id == null) { return(HttpNotFound()); } using (var db = new SpecialtySelectorDbContext()) { var subject = db.Subjects.Find(id); if (subject != null) { subject.DeletedOn = DateTime.Now; } db.SaveChanges(); return(RedirectToAction("Index", "Home")); } }
public ActionResult Delete(int?id) { if (id == null) { return(HttpNotFound()); } using (var db = new SpecialtySelectorDbContext()) { Specialty specialty = db.Specialties.FirstOrDefault(s => s.Id == id); if (specialty != null) { specialty.DeletedOn = DateTime.Now; } db.SaveChanges(); return(RedirectToAction("Index", "Home")); } }
public ActionResult Update(UpdateTeacher updateTeacher) { if (ModelState.IsValid && updateTeacher != null) { using (var db = new SpecialtySelectorDbContext()) { var teachers = db.Teachers. Find(updateTeacher.Id); var adminId = this.User.Identity.GetUserId(); var subnew = new List <Subject>(); if (updateTeacher.Subject != null) { foreach (var kvp in updateTeacher.Subject) { var asd = db.Subjects.FirstOrDefault(x => x.Id == kvp); subnew.Add(asd); } } teachers.AdminId = adminId; teachers.FirstName = updateTeacher.FirstName; teachers.SecondName = updateTeacher.SecondName; teachers.LastName = updateTeacher.LastName; teachers.TeacherInfo = updateTeacher.TeacherInfo; teachers.Degree = updateTeacher.Degree; teachers.AcademicTitle = updateTeacher.AcademicTitle; teachers.FiredOn = updateTeacher.FiredOn; teachers.Subjects = subnew; db.SaveChanges(); } return(RedirectToAction("Details", new { id = updateTeacher.Id })); } return(View(updateTeacher)); }
public ActionResult Create(CreateSpecialty createSpecialty) { if (this.ModelState.IsValid) { var adminId = this.User.Identity.GetUserId(); var specialty = new Specialty() { Name = createSpecialty.Name, Description = createSpecialty.Description, Eqd = createSpecialty.Eqd, FormOfEducation = createSpecialty.FormOfEducation, SubDepartmentId = createSpecialty.SubDepartmentId, AdminId = adminId }; using (var db = new SpecialtySelectorDbContext()) { db.Specialties.Add(specialty); db.SaveChanges(); var subDepartments = db.SubDepartments.ToList(); ViewBag.SubDepartments = subDepartments; return(RedirectToAction("Details", new { id = specialty.Id })); } } using (var db = new SpecialtySelectorDbContext()) { var subDepartments = db.SubDepartments.ToList(); ViewBag.SubDepartments = subDepartments; return(View(createSpecialty)); } }
public ActionResult Update(UpdateSpecialty updateSpecialty) { if (ModelState.IsValid && updateSpecialty != null) { using (var db = new SpecialtySelectorDbContext()) { var specialty = db.Specialties. Find(updateSpecialty.Id); specialty.Name = updateSpecialty.Name; specialty.Description = updateSpecialty.Description; specialty.Eqd = updateSpecialty.Eqd; specialty.FormOfEducation = updateSpecialty.FormOfEducation; specialty.DeletedOn = updateSpecialty.DeletedOn; specialty.SubDepartmentId = updateSpecialty.SubDepartmentId; db.SaveChanges(); } return(RedirectToAction("Details", new { id = updateSpecialty.Id })); } return(View(updateSpecialty)); }
public ActionResult Create(CreateDepartment departmentModel) { if (this.ModelState.IsValid && departmentModel.Description != null && departmentModel.Name != null) { var adminId = this.User.Identity.GetUserId(); var department = new Department { Name = departmentModel.Name, Description = departmentModel.Description, AdminId = adminId }; using (var db = new SpecialtySelectorDbContext()) { db.Departments.Add(department); db.SaveChanges(); return(RedirectToAction("Details", new { id = department.Id })); } } return(View(departmentModel)); }
public ActionResult Create(CreateSubject createSubject) { if (createSubject != null && ModelState.IsValid) { using (var db = new SpecialtySelectorDbContext()) { var adminId = this.User.Identity.GetUserId(); var listOfTeachers = new List <Teacher>(); var listOfSpecialties = new List <Specialty>(); //FIX if (createSubject.Teacher != null) { foreach (var teacher in createSubject.Teacher) { var currentTeacher = db.Teachers.FirstOrDefault(t => t.Id == teacher); listOfTeachers.Add(currentTeacher); } } //FIX if (createSubject.Specialty != null) { foreach (var specialty in createSubject.Specialty) { var currentSpecialty = db.Specialties.FirstOrDefault(s => s.Id == specialty); listOfSpecialties.Add(currentSpecialty); } } var subject = new Subject() { Name = createSubject.Name, IsMandatory = createSubject.IsMandatory, Credits = createSubject.Credits, Course = createSubject.Course, Description = createSubject.Description, Specialties = listOfSpecialties, Teachers = listOfTeachers, AdminId = adminId }; db.Subjects.Add(subject); db.SaveChanges(); //FIX return(RedirectToAction("Details", new { id = subject.Id })); } } using (var db = new SpecialtySelectorDbContext()) { var teachers = db.Teachers.ToList(); var specialties = db.Specialties.ToList(); ViewBag.Teachers = teachers; ViewBag.Specialties = specialties; return(View(createSubject)); } }