public async Task <ActionResult> CreateClass(ClassCreateViewModel model)
        {
            var departments = await InstitutionManager.GetAllDepartmentsAsync();

            SelectList departSelectList = new SelectList(departments, "Id", "Name");

            ViewBag.departSelectList = departSelectList;

            var majors = await InstitutionManager.GetMajorsForDepartmentAsync(departments.ElementAtOrDefault(0));

            SelectList majorSelectList = new SelectList(majors, "Id", "Name");

            ViewBag.majorSelectList = majorSelectList;

            var grades = await InstitutionManager.GetAllGradesAsync();

            SelectList gradeSelectList = new SelectList(grades, "Id", "GradeNum");

            ViewBag.gradeSelectList = gradeSelectList;

            ViewBag.Classes = await InstitutionManager.GetAllClassesAsync();

            if (ModelState.IsValid)
            {
                var grade = await InstitutionManager.FindGradeByIdAsync(model.GradeId);

                if (grade == null)
                {
                    ModelState.AddModelError("", "找不到grade");
                    return(View(model));
                }
                var major = await InstitutionManager.FindMajorByIdAsync(model.MajorId);

                if (major == null)
                {
                    ModelState.AddModelError("", "找不到major");
                    return(View(model));
                }
                var class1 = new Class
                {
                    ClassDefination = model.Defination,
                    Grade           = grade,
                    Major           = major
                };
                if (await InstitutionManager.IsClassExistAsync(c =>
                                                               !c.IsDeleted && c.Grade.Id == class1.Grade.Id && c.Major.Id == class1.Major.Id &&
                                                               c.ClassDefination == class1.ClassDefination))
                {
                    ModelState.AddModelError("", "已存在Class");
                    return(View(model));
                }
                await InstitutionManager.AddClassAsync(class1);

                return(RedirectToAction("AllClass"));
            }
            return(View(model));
        }
        public async Task <ActionResult> EditClass(ClassEditViewModel model)
        {
            var departments = await InstitutionManager.GetAllDepartmentsAsync();

            SelectList departSelectList = new SelectList(departments.ToList(), "Id", "Name");

            ViewBag.departSelectList = departSelectList;

            var majors = await InstitutionManager.GetMajorsForDepartmentAsync(departments.ElementAtOrDefault(0));

            SelectList majorSelectList = new SelectList(majors.ToList(), "Id", "Name");

            ViewBag.majorSelectList = majorSelectList;

            var grades = await InstitutionManager.GetAllGradesAsync();

            SelectList gradeSelectList = new SelectList(grades.ToList(), "Id", "GradeNum");

            ViewBag.gradeSelectList = gradeSelectList;

            ViewBag.Classes = await InstitutionManager.GetAllClassesAsync();

            if (ModelState.IsValid)
            {
                var class1 = await InstitutionManager.FindClassByIdAsync(model.Id);

                if (class1 == null)
                {
                    ModelState.AddModelError("", "找不到class1");
                    return(View(model));
                }
                var grade = await InstitutionManager.FindGradeByIdAsync(model.GradeId);

                if (grade == null)
                {
                    ModelState.AddModelError("", "找不到grade");
                    return(View(model));
                }
                var major = await InstitutionManager.FindMajorByIdAsync(model.MajorId);

                if (major == null)
                {
                    ModelState.AddModelError("", "找不到major");
                    return(View(model));
                }
                class1.Major           = major;
                class1.Grade           = grade;
                class1.ClassDefination = model.Defination;

                await InstitutionManager.UpdateClassAsync(class1);

                await UserManager.RemoveStudentsFromClassAsync(model.IdsToRemove ?? new string[] { });

                return(RedirectToAction("AllClass"));
            }
            return(View(model));
        }
        public async Task <ActionResult> CreateMajor()
        {
            ViewBag.Majors = await InstitutionManager.GetAllMajorsAsync();

            var departments = await InstitutionManager.GetAllDepartmentsAsync();

            SelectList selectList = new SelectList(departments, "Id", "Name");

            ViewBag.selectList = selectList;
            return(View());
        }
        public async Task <ActionResult> EditMajor(int?id)
        {
            var major = await InstitutionManager.FindMajorByIdAsync(id ?? 0);

            if (major == null)
            {
                return(HttpNotFound());
            }
            var departments = await InstitutionManager.GetAllDepartmentsAsync();

            SelectList selectList = new SelectList(departments, "Id", "Name");

            ViewBag.selectList = selectList;
            var model = new MajorEditViewModel {
                Id = major.Id, DepartmentId = major.Department.Id, MajorName = major.Name
            };

            return(View(model));
        }
        public async Task <ActionResult> EditClass(int?id)
        {
            var class1 = await InstitutionManager.FindClassByIdAsync(id ?? 0);

            if (class1 == null)
            {
                return(HttpNotFound("class不存在"));
            }

            var departments = await InstitutionManager.GetAllDepartmentsAsync();

            SelectList departSelectList = new SelectList(departments.ToList(), "Id", "Name");

            ViewBag.departSelectList = departSelectList;

            var majors = await InstitutionManager.GetMajorsForDepartmentAsync(departments.ElementAtOrDefault(0));

            SelectList majorSelectList = new SelectList(majors.ToList(), "Id", "Name");

            ViewBag.majorSelectList = majorSelectList;

            var grades = await InstitutionManager.GetAllGradesAsync();

            SelectList gradeSelectList = new SelectList(grades.ToList(), "Id", "GradeNum");

            ViewBag.gradeSelectList = gradeSelectList;

            ViewBag.Classes = await InstitutionManager.GetAllClassesAsync();

            var model = new ClassEditViewModel
            {
                Defination   = class1.ClassDefination,
                DepartmentId = class1.Major.Department.Id,
                GradeId      = class1.Grade.Id,
                MajorId      = class1.Major.Id,
                Students     = class1.Students
            };

            return(View(model));
        }
        public async Task <ActionResult> CreateClass()
        {
            var departments = await InstitutionManager.GetAllDepartmentsAsync();

            SelectList departSelectList = new SelectList(departments, "Id", "Name");

            ViewBag.departSelectList = departSelectList;

            var majors = await InstitutionManager.GetMajorsForDepartmentAsync(departments.ElementAtOrDefault(0));

            SelectList majorSelectList = new SelectList(majors, "Id", "Name");

            ViewBag.majorSelectList = majorSelectList;

            var grades = await InstitutionManager.GetAllGradesAsync();

            SelectList gradeSelectList = new SelectList(grades, "Id", "GradeNum");

            ViewBag.gradeSelectList = gradeSelectList;

            ViewBag.Classes = await InstitutionManager.GetAllClassesAsync();

            return(View());
        }
        public async Task <ActionResult> CreateDepartment()
        {
            ViewBag.Departments = await InstitutionManager.GetAllDepartmentsAsync();

            return(View());
        }
        public async Task <ActionResult> AllDepartment()
        {
            var list = await InstitutionManager.GetAllDepartmentsAsync();

            return(View(list));
        }