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)); }