public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }

            using (var db = new SpecialtySelectorDbContext())
            {
                var specialties = db.Specialties
                                  .Where(sp => sp.Id == id)
                                  .Where(sp => sp.DeletedOn.Equals(null))
                                  .Select(sp => new SpecialtyInfo
                {
                    Id              = sp.Id,
                    Name            = sp.Name,
                    Description     = sp.Description,
                    Eqd             = sp.Eqd,
                    FormOfEducation = sp.FormOfEducation,
                    SubDepartmentId = sp.SubDepartmentId
                })
                                  .FirstOrDefault();

                if (specialties == null)
                {
                    return(HttpNotFound());
                }

                return(View(specialties));
            }
        }
示例#2
0
        public ActionResult Update(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }

            using (var db = new SpecialtySelectorDbContext())
            {
                var teacher = db.Teachers.Find(id);
                var adminId = this.User.Identity.GetUserId();

                if (teacher == null)
                {
                    return(HttpNotFound());
                }

                var teacherViewModel = new UpdateTeacher
                {
                    Id            = teacher.Id,
                    FirstName     = teacher.FirstName,
                    SecondName    = teacher.SecondName,
                    LastName      = teacher.LastName,
                    TeacherInfo   = teacher.TeacherInfo,
                    Degree        = teacher.Degree,
                    AcademicTitle = teacher.AcademicTitle,
                    AdminId       = adminId,
                    Subjects      = teacher.Subjects
                };

                return(View(teacherViewModel));
            }
        }
示例#3
0
        private void CreateUser(SpecialtySelectorDbContext context,
                                string email,
                                string password
                                )
        {
            var userManager = new UserManager <User>(new UserStore <User>(context))
            {
                PasswordValidator = new PasswordValidator
                {
                    RequiredLength          = 1,
                    RequireNonLetterOrDigit = false,
                    RequireDigit            = false,
                    RequireLowercase        = false,
                    RequireUppercase        = false,
                }
            };
            var user = new User
            {
                UserName = email,
                Email    = email,
            };
            var userCreateResult = userManager.Create(user, password);

            if (!userCreateResult.Succeeded)
            {
                throw new Exception(string.Join("; ", userCreateResult.Errors));
            }
        }
示例#4
0
        public ActionResult TeacherInfo(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }

            using (var db = new SpecialtySelectorDbContext())
            {
                var teachers = db.Teachers
                               .Where(t => t.Id == id)
                               .Where(t => t.FiredOn.Equals(null))
                               .Select(t => new TeacherInfo()
                {
                    Id                 = t.Id,
                    Degree             = t.Degree,
                    AcademicTitle      = t.AcademicTitle,
                    FirstName          = t.FirstName,
                    SecondName         = t.SecondName,
                    LastName           = t.LastName,
                    TeacherInformation = t.TeacherInfo,
                    Subjects           = t.Subjects
                })
                               .ToList();

                if (teachers == null)
                {
                    return(HttpNotFound());
                }

                return(View(teachers));
            }
        }
        public ActionResult Update(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }

            using (var db = new SpecialtySelectorDbContext())
            {
                var specialty = db.Specialties.Find(id);

                if (specialty == null)
                {
                    return(HttpNotFound());
                }

                var specialtyViewModel = new UpdateSpecialty
                {
                    Id              = specialty.Id,
                    Name            = specialty.Name,
                    Description     = specialty.Description,
                    Eqd             = specialty.Eqd,
                    FormOfEducation = specialty.FormOfEducation,
                    AdminId         = specialty.AdminId,
                    SubDepartmentId = specialty.SubDepartmentId
                };

                return(View(specialtyViewModel));
            }
        }
        public ActionResult Update(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }

            using (var db = new SpecialtySelectorDbContext())
            {
                var department = db.Departments
                                 .Find(id);

                if (department == null)
                {
                    return(HttpNotFound());
                }

                var departmentViewModel = new UpdateDepartment
                {
                    Id          = department.Id,
                    Name        = department.Name,
                    Description = department.Description,
                    AdminId     = department.AdminId
                };



                return(View(departmentViewModel));
            }
        }
        public ActionResult AllSpecialties()
        {
            using (var db = new SpecialtySelectorDbContext())
            {
                var specialties = db.Specialties
                                  .Include(x => x.SubDepartment.Name)
                                  .Where(sp => sp.DeletedOn.Equals(null))
                                  .Select(sp => new AllSpecialties()
                {
                    Id                = sp.Id,
                    Name              = sp.Name,
                    Description       = sp.Description,
                    Eqd               = sp.Eqd,
                    FormOfEducation   = sp.FormOfEducation,
                    SubDepartmentId   = sp.SubDepartmentId,
                    SubDepartmentName = sp.SubDepartment.Name
                })
                                  .ToList();

                if (specialties == null)
                {
                    return(HttpNotFound());
                }

                return(View(specialties));
            }
        }
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }
            using (var db = new SpecialtySelectorDbContext())
            {
                var department = db.Departments
                                 .Where(d => d.DeletedOn.Equals(null))
                                 .Where(d => d.Id == id)
                                 .Select(d => new DepartmentDetailsModel()
                {
                    Name        = d.Name,
                    Description = d.Description
                })
                                 .FirstOrDefault();

                if (department == null)
                {
                    return(HttpNotFound());
                }

                return(View(department));
            }
        }
示例#9
0
        public ActionResult Details(int?id)
        {
            //FIX
            if (id == null)
            {
                return(HttpNotFound());
            }

            using (var db = new SpecialtySelectorDbContext())
            {
                var subjects = db.Subjects
                               .Where(sp => sp.Id == id)
                               .Where(sp => sp.DeletedOn.Equals(null))
                               .Select(sp => new SubjectInfo
                {
                    Id          = sp.Id,
                    Name        = sp.Name,
                    Description = sp.Description,
                    Specialties = sp.Specialties,
                    Teachers    = sp.Teachers,
                    Course      = sp.Course,
                    Credits     = sp.Credits,
                    IsMandatory = sp.IsMandatory
                })
                               .FirstOrDefault();

                if (subjects == null)
                {
                    return(HttpNotFound());
                }

                return(View(subjects));
            }
        }
示例#10
0
        public ActionResult SubjectInfo(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }

            using (var db = new SpecialtySelectorDbContext())
            {
                var subjects = db.Subjects
                               .Where(s => s.Id == id)
                               .Where(s => s.DeletedOn.Equals(null))
                               .Select(s => new SubjectInfo()
                {
                    Id          = s.Id,
                    Name        = s.Name,
                    Description = s.Description,
                    Specialties = s.Specialties,
                    Teachers    = s.Teachers,
                    Course      = s.Course,
                    Credits     = s.Credits,
                    IsMandatory = s.IsMandatory
                })
                               .ToList();

                if (subjects == null)
                {
                    return(HttpNotFound());
                }

                return(View(subjects));
            }
        }
示例#11
0
        public ActionResult Update(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }

            using (var db = new SpecialtySelectorDbContext())
            {
                var subject = db.Subjects.Find(id);
                var adminId = this.User.Identity.GetUserId();

                if (subject == null)
                {
                    return(HttpNotFound());
                }

                var updateSubjectModel = new UpdateSubject
                {
                    AdminId     = adminId,
                    Id          = subject.Id,
                    Name        = subject.Name,
                    Description = subject.Description,
                    Credits     = subject.Credits,
                    Course      = subject.Course,
                    Teachers    = subject.Teachers,
                    Specialties = subject.Specialties,
                    IsMandatory = subject.IsMandatory,
                    DeletedOn   = subject.DeletedOn
                };

                return(View(updateSubjectModel));
            }
        }
        public ActionResult SubDepartmentInfo(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }

            using (var db = new SpecialtySelectorDbContext())
            {
                var subDepartments = db.SubDepartments
                                     .Where(sb => sb.DepartmentId == id)
                                     .Where(sb => sb.DeletedOn.Equals(null))
                                     .Select(sb => new SubDepartmentInfo()
                {
                    Id          = sb.Id,
                    Name        = sb.Name,
                    Description = sb.Description
                })
                                     .ToList();

                if (subDepartments == null)
                {
                    return(HttpNotFound());
                }

                return(View(subDepartments));
            }
        }
        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));
            }
        }
示例#14
0
        public ActionResult AllSubjects()
        {
            using (var db = new SpecialtySelectorDbContext())
            {
                var subjects = db.Subjects
                               .Include(x => x.Teachers)
                               .Include(x => x.Specialties)
                               .Where(sp => sp.DeletedOn.Equals(null))
                               .Select(sp => new AllSubjects()
                {
                    Id          = sp.Id,
                    Name        = sp.Name,
                    Credits     = sp.Credits,
                    Course      = sp.Course,
                    IsMandatory = sp.IsMandatory
                })
                               .ToList();

                if (subjects == null)
                {
                    return(HttpNotFound());
                }

                return(View(subjects));
            }
        }
        public ActionResult Create()
        {
            using (var db = new SpecialtySelectorDbContext())
            {
                var departments = db.Departments.ToList();

                ViewBag.Departments = departments;

                return(View());
            }
        }
示例#16
0
        public ActionResult Create()
        {
            using (var db = new SpecialtySelectorDbContext())
            {
                var subjects = db.Subjects.ToList();

                ViewBag.Subjects = subjects;

                return(View());
            }
        }
示例#17
0
 private static void SeedDepartments(SpecialtySelectorDbContext context)
 {
     context.Departments.Add(new Department()
     {
         Name        = "?????????",
         Description = @"??????????? ?? ?????? ?? ?????????????? ??????? ?? ?????? ?????? ??? ????????? ??????, ?????????, ???????????? ? ??????? ???????, ?????????????? ??????, ????? ???????? ???????? ? ??????????????, ????????, ????????????? ? ????????????? ?? ????? ? ?????? ? ???? ?????? ??? ??????. ?????? ????????? ? ???????? ???????? ?? ????????, ????? ??????? ?????????? ????????, ??????? [1] ? ???????? ???????????, ????? ? ??????? ?????????, ?????????? ??????? ? ????????, ???? ??????? ???????. ???? ??????? ????????? ?????????, ???????????? ? ???????????? ?? ??????? ? ?????????, ??? ????? ??????????? ???????????. ??????????? ? ?????????? ???? ?? ????????? ? ???????????? ?? ??????????, ?????????? ?? ?????? ???? ?? ???? ?????????? ?? ?????? ??????"
     });
     context.Departments.Add(new Department()
     {
         Name        = "??????????? ?????",
         Description = @"? ?????????????? ?? ???? ????????????? ??????????? ???????????? ????? ? ????? ???? ???????? ?????????????? ?????? ??????????:???????????? ?????? ??????????: ""????????? ? ?????????????"", ""?????-???? ? ???????? ??????"", ""??????????? ??????? ?? ?????? ? ??? ?? ?????-?? ???????? ?????"", ""??????? ?? ????????????? ????"", ""?????????"", ""??-???????? ??????????? ?????? ? ????????"", ""???? ??? ???????? ????????"",""??????????? ??????? ?? ???????? ????"", ""???????????"", ""??????????? ???-3??????"", ""?????????????? ?????"", ""?????????? ??????????"", ""?????????????????? ?? ?????????"", ""?????????? ??????????? ???????"", ""?????? ????-???? ?? ????????"", ""??????????? ? ???????? ?? ???????????? ??????"", ""??-???? ?? ????????????"", ???? ????, ""?????????? ? ?????"".????????? ?????? ??????????: ""????????????? ??????? ? ??????????"",""??????????"", ""??????????"", ""??????????? ??????????"", ""???????? ???????"",""????????????? ??????????? ? ??????"", ""???????????? ???????? ?????"",""??????????????? ?????"" ? ??"
     });
 }
示例#18
0
        public ActionResult Create()
        {
            using (var db = new SpecialtySelectorDbContext())
            {
                var teachers    = db.Teachers.ToList();
                var specialties = db.Specialties.ToList();

                ViewBag.Teachers    = teachers;
                ViewBag.Specialties = specialties;

                return(View());
            }
        }
示例#19
0
        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));
        }
示例#20
0
        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));
            }
        }
示例#21
0
        public ActionResult Index()
        {
            using (var db = new SpecialtySelectorDbContext())
            {
                var departments = db.Departments
                                  .Where(y => y.DeletedOn.Equals(null))
                                  .Select(x => new HomeIndexDepartmentsModel()
                {
                    Id          = x.Id,
                    Name        = x.Name,
                    Description = x.Description
                })
                                  .ToList();

                return(View(departments));
            }
        }
示例#22
0
 protected override void Seed(SpecialtySelectorDbContext context)
 {
     if (!context.Users.Any())
     {
         CreateUser(context, "*****@*****.**", "*****@*****.**");
     }
     if (!context.Departments.Any())
     {
         SeedDepartments(context);
     }
     if (!context.SubDepartments.Any())
     {
         context.SubDepartments.Add(new SubDepartment()
         {
             Name         = "?????????, ???????? ? ??????? ???????",
             Description  = @"?????????? ?? ???? ???????????? ?? ??????????? ? ????????????????? ???????? ?? ?????? ??????? ? ????????? ???????? ? ???????????? ?? ???????????, ????????, ????????? ? ?????????????, ????? ??????? ?? ?????????? ? ??????? ?? ?????????? ?????????? (????????????, ?????????????? ???????, ?????? ?? ??????????? ? ?????? ??????), ? ??????????? ?? ??????? ??????, ????????????? ? ??????????????? ???????????, ????????????????? ??????. ???????????? ?????? ?? ????????? ??????? 73 ?????????????, ?? ????? 16 ?????????, 28 ???????, 18 ?????? ????????? ? 11 ?????????.?????????? ?? ???????? ?? ?????????? ?????? ??????? ? ????????, ????? ???????????? ?? ???????? ? ???????? ? ????????????? ?? ?????????? ? ?? ???????????, ????????? ? ???????????? ????????????? ????????????. ?? ?????????? ?????????????, ?????????????? ? ?????????????? ?????????? ?? ???????????? ?? ?????????????? ?? ?????????????? ?????????,???????? ? ??????? ???????. ? ????? ? ????? ???? ?? ?????? ???????? ?? ???????????????? ?? ????????? ???????????? ? ????????? ?????????? ?? ?????????????????? ???? ?? ??????????? ?????????. ? ????? ???? ?? ???????? ?????????? ???????????? ? ????????? ??????????, ? ? ???????? – ?????????? ?? ????????? ???????????. ? ??????? ?? ??????????? ?? ???????? ?????????? ????????????? ??????????, ???? ????? ???????????? ?????????? ??????, ?????? ? ???????????, ????? ?? ???????????? ?? ??????? ????????????? ?????????? ?? ?????????? ? ?? ??????????? ?????? ?????.",
             DepartmentId = 1
         });
         context.SubDepartments.Add(new SubDepartment()
         {
             Name         = "????????? ? ??????",
             Description  = @"??????????? ??? ?????????? ?? ??????? ? ??????-?????? ?????????, ????????????? ????????? ???-???????? ?????????? ?? ???????????? ?????????-?????????? ??????????? ?? ?????? ??????? ? ??????,?????????, ???????????? ? ??????? ?? ??????? ? ???-????, ?????????? ?? ??????????, ??????? ??????? ?????????? ? ???????? ?? ???????? ?????????.? ????? ???? ?? ???????? ???????????? ? ??-??????? ?????????? ?????? ??????????: ""????????????????"", ""???????? ? ???????"", ""???????????? ????????? ???????"", ""??????????? ?? ???????"",""???????????? ???? ??????????"", ""???????????????????????"", ""?????????? ?? ??????????"", ""???????????"", ""???????????? ?? ?????? ?????????????"", ""???????? ???????????"", ""????????????"", ""?????????????? ?????-??"", ""?????? ?????????"", ""?????? ????????????????"", ""??????? ????????? ? ???????????? ???????????"" ? ??.",
             DepartmentId = 1
         });
         context.SubDepartments.Add(new SubDepartment()
         {
             Name         = "????????? ? ??????????????",
             Description  = @"???????? ???????? ? ??????????? ?? ??????????? ""?????????"", ""?????????-???????????"", ""?????????????? ? ??????"". ?? 31.05.1995 ?. ? ??????? ?? ??????????? ????? ? ??????????? ?? ???????? ""????????? ?? ????????????????"" ???? ????????????? ????? ??? ????. ? ???? ?? ???? ???????????? ?? ???????? ???????? ? ????????????, ??????????? ?????? ? ??????????.????????? ??????? ?? ????????? ? ?????????? ? ????????????, ???????????, ????????? ???????? ? ???????????? ?? ??????????? ?? ??????????? ? ?????????? ?? ??????????, ???????? ? ?????????? ?? ????????????????, ??????????? ?? ????????????????? ??????? ? ?????????? ?????????????.?????????? ???????? ??????????? ? ????????? ?? ???-?????????? ?????????? ?? ?????? ?? ??????????? ????????? – ?????????????????, ?????? ?? ???????? ??????????????? ???? ?? ?????????? ?????????? ? ???????????? ?? ?????????????.",
             DepartmentId = 1
         });
         context.SubDepartments.Add(new SubDepartment()
         {
             Name         = "????????? ? ???????????? ????????",
             Description  = @"?????????? ?? ??????????? ""???????????????????????? ?????????"" ??? ?? ???? ??????? ??????????????????? ?????????? ?? ?????????????????? ??????????? ???????????????? ? ?????????????????, ????? ? ??? ?????? ? ?????? ? ?????????????????? ?? ?????????????? ???????????? ??????-??? ? ??????????, ???????????? ???????????? ??-????????, ?????????????? ???????, ???????????????????, ??????? ?????????????? ? ?????????.",
             DepartmentId = 1
         });
         context.SubDepartments.Add(new SubDepartment()
         {
             Name         = "???????????? ?????????",
             Description  = @"???????? ???? ?? ????????????? ???????? 30-????????? ???????? ??????????????? ? ????????????? ? ???? ? ???? ?????? ? ?????? ????? ?????????? ???????????? ? ???????. ?????????? ????????? ??????????? ???-??????? ?? ??????? ? ?????? ?? ?????????????? ????????? ? ????????????????, ?????? ? ??????? ?? ??????, ???????? ???????? ?? ???????? ? ????????? ????????? ? ?????????????? ????????, ?????????? ? ?????????????????????, ???????????? ??????????, ?????????. ?????? ?????????? ? ????-???????? ?? ????? ????? ?????????? ?? ??? ????? ?????. ",
             DepartmentId = 2
         });
     }
 }
        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())
            {
                Department department = db.Departments.FirstOrDefault(x => x.Id == id);

                if (department != null)
                {
                    department.DeletedOn = DateTime.Now;
                }

                db.SaveChanges();

                return(RedirectToAction("Index", "Home"));
            }
        }
示例#25
0
        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"));
            }
        }
示例#27
0
        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 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 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));
        }