Exemplo n.º 1
0
        public async Task <ActionResult> Edit(DepartmentEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                var de = await DepartmentManager.FindEntityByIdAsync(model.Id);

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

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

                    await MajorManager.ResetMajorsDepartmentAsync(model.IdsToRemove ?? new int[] { });

                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View("Error", new[] { "学院不存在" }));
                }
            }
            return(View(model));
        }
        public async Task <JsonResult> GetMajorOfDepartment(int?departId)
        {
            var depart = await DepartmentManager.FindEntityByIdAsync(departId ?? 0);

            if (depart == null)
            {
                return(Json(new { error = 1, message = "找不到该Department" }));
            }
            return(Json(new { error = 0, message = "获取成功", data = depart.Majors.Select(m => new { m.Id, m.Name }) }));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Delete(int?id)
        {
            if (ModelState.IsValid)
            {
                var major = await DepartmentManager.FindEntityByIdAsync(id ?? 0);

                if (major != null)
                {
                    await DepartmentManager.DeleteEntityAsync(major);
                }
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
        public async Task <ActionResult> Edit(int?id)
        {
            var de = await DepartmentManager.FindEntityByIdAsync(id ?? 0);

            if (de == null)
            {
                return(View("Error", new[] { "学院不存在" }));
            }
            ViewBag.InMajors = await MajorManager.GetMajorsForDepartment(de).ToListAsync();

            ViewBag.OutMajors = await MajorManager.FindNoDepartmentMajors().ToListAsync();

            var model = new DepartmentEditViewModel {
                Id = de.Id, Name = de.Name
            };

            return(View(model));
        }