public async Task <ActionResult> EditDepartment(DepartmentEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                var de = await InstitutionManager.FindDepartmentByIdAsync(model.Id);

                if (de != null)
                {
                    if (!string.IsNullOrEmpty(model.Name))
                    {
                        de.Name = model.Name;
                    }
                    await InstitutionManager.UpdateDepartmentAsync(de);

                    await InstitutionManager.AddMajorsToDepartmentAsync(de, model.IdsToAdd ?? new int[] { });

                    await InstitutionManager.RemoveMajorsFromDepartmentAsync(de, model.IdsToRemove ?? new int[] { });

                    return(RedirectToAction("AllDepartment"));
                }
                else
                {
                    ModelState.AddModelError("", "学院不存在");
                }
            }
            return(View(model));
        }
        public async Task <ActionResult> CreateMajor(MajorCreateViewModel major)
        {
            if (ModelState.IsValid)
            {
                if (string.IsNullOrEmpty(major.MajorName))
                {
                    ModelState.AddModelError("", "MajorName不能为空");
                }
                else if (major.DepartmentId == 0)
                {
                    ModelState.AddModelError("", "DepartmentId不能为空");
                }
                else
                {
                    var model = await InstitutionManager.FindMajorByNameAsync(major.MajorName);

                    if (model == null)
                    {
                        await InstitutionManager.AddMajorAsync(major.MajorName);

                        model = await InstitutionManager.FindMajorByNameAsync(major.MajorName);

                        var depart = await InstitutionManager.FindDepartmentByIdAsync(major.DepartmentId);

                        if (depart == null)
                        {
                            ModelState.AddModelError("", "找不到对应学院");
                        }
                        await InstitutionManager.AddMajorsToDepartmentAsync(depart, new[] { model.Id });

                        return(RedirectToAction("AllMajor"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "已有相同名称");
                    }
                }
            }
            return(View(major));
        }