public async Task <ActionResult> Edit(OfficeEditViewModel model)
        {
            var de = await DepartmentManager.GetAllEntities().ToListAsync();

            ViewBag.SelectListDepart = new SelectList(de, "Id", "Name");

            if (ModelState.IsValid)
            {
                var office = await OfficeManager.FindEntityByIdAsync(model.Id);

                if (office == null)
                {
                    return(View("Error", new[] { "找不到该部门" }));
                }
                var depart = await DepartmentManager.FindEntityByIdAsync(model.DepartmentId);

                if (depart == null)
                {
                    return(View("Error", new[] { "找不到该学院" }));
                }
                office.Name        = model.Name;
                office.Description = model.Description;
                office.Department  = depart;
                await OfficeManager.UpdateEntityAsync(office);

                await PositionManager.ResetPositionsOfficeAsync(model.IdsToRemove ?? new int[] { });

                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
        public async Task <ActionResult> Edit(PositionEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                var departs = await DepartmentManager.GetAllEntities().ToListAsync();

                ViewBag.selectListDepart = new SelectList(departs, "Id", "Name");

                var offices = await OfficeManager.GetOfficesForDepartment(departs.ElementAtOrDefault(0)).ToListAsync();

                ViewBag.selectListOffice = new SelectList(offices, "Id", "Name");

                var teachers = await UserManager.GetNoPositionTeachersAsync();

                ViewBag.selectListTeacher = new SelectList(teachers, "Id", "Name");



                var position = await PositionManager.FindEntityByIdAsync(model.Id);

                if (position != null)
                {
                    var user = await UserManager.FindByIdAsync(model.UserId);

                    if (user == null)
                    {
                        ModelState.AddModelError("", "用户不存在");
                        return(View(model));
                    }
                    var office = await OfficeManager.FindEntityByIdAsync(model.OfficeId);

                    if (office == null)
                    {
                        ModelState.AddModelError("", "部门不存在");
                        return(View(model));
                    }
                    position.Name        = model.Name;
                    position.Description = model.Description;
                    position.HeadUser    = user.TeacherInfo;
                    position.Office      = office;
                    await PositionManager.UpdateEntityAsync(position);

                    user.TeacherInfo.Position = position;
                    await UserManager.UpdateAsync(user);

                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("", "目标不存在");
                }
            }
            return(View(model));
        }
        public async Task <ActionResult> Delete(int?id)
        {
            if (ModelState.IsValid)
            {
                var office = await OfficeManager.FindEntityByIdAsync(id ?? 0);

                if (office == null)
                {
                    return(View("Error", new[] { "找不到目标" }));
                }
                await OfficeManager.DeleteEntityAsync(office);
            }
            return(View("Index"));
        }
        public async Task <ActionResult> Edit(int?id)
        {
            var office = await OfficeManager.FindEntityByIdAsync(id ?? 0);

            if (office == null)
            {
                return(View("Error", new[] { "找不到该部门" }));
            }
            ViewBag.OutPositions = await PositionManager.FindNoOfficePositions().ToListAsync();

            ViewBag.InPositions = office.Positions.ToList();
            var model = new OfficeEditViewModel
            {
                DepartmentId = office.Department.Id,
                Description  = office.Description,
                Id           = office.Id,
                Name         = office.Name
            };
            var de = await DepartmentManager.GetAllEntities().ToListAsync();

            ViewBag.SelectListDepart = new SelectList(de, "Id", "Name");
            return(View(model));
        }