public async Task <ActionResult> Edit(int?id)
        {
            var position = await PositionManager.FindEntityByIdAsync(id ?? 0);

            if (position == null)
            {
                return(HttpNotFound());
            }

            ViewBag.Positions = await PositionManager.GetAllEntities().ToListAsync();

            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 model = new PositionEditViewModel
            {
                Id          = position.Id,
                Description = position.Description,
                Name        = position.Name,
                UserId      = position.HeadUser.Teacher.Id,
                OfficeId    = position.Office.Id
            };

            return(View(model));
        }
        public async Task <ActionResult> Create()
        {
            var departments = await DepartmentManager.GetAllEntities().ToListAsync();

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

            ViewBag.departSelectList = departSelectList;

            var majors = await MajorManager.GetMajorsForDepartment(departments.ElementAtOrDefault(0)).ToListAsync();

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

            ViewBag.majorSelectList = majorSelectList;

            var grades = await GradeManager.GetAllEntities().ToListAsync();

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

            ViewBag.gradeSelectList = gradeSelectList;

            var teachers = (await UserManager.GetNoClassTeachersAsync()).ToList();

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


            ViewBag.Classes = await ClassManager.GetAllEntities().ToListAsync();

            return(View());
        }
        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> Edit(int?id)
        {
            var class1 = await ClassManager.FindEntityByIdAsync(id ?? 0);

            if (class1 == null)
            {
                return(HttpNotFound("class不存在"));
            }
            var departments = await DepartmentManager.GetAllEntities().ToListAsync();

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

            ViewBag.departSelectList = departSelectList;

            var majors = await MajorManager.GetMajorsForDepartment(departments.ElementAtOrDefault(0)).ToListAsync();

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

            ViewBag.majorSelectList = majorSelectList;

            var grades = await GradeManager.GetAllEntities().ToListAsync();

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

            ViewBag.gradeSelectList = gradeSelectList;

            var teachers = (await UserManager.GetNoClassTeachersAsync()).ToList();

            if (class1.ClassTeacher != null)
            {
                teachers.Add(class1.ClassTeacher.Teacher);
            }
            ViewBag.teacherSelectList = new SelectList(teachers, "Id", "Name");

            ViewBag.Classes = await ClassManager.GetAllEntities().ToListAsync();

            var model = new ClassEditViewModel
            {
                Defination     = class1.ClassDefination,
                DepartmentId   = class1.Major.Department.Id,
                GradeId        = class1.Grade.Id,
                MajorId        = class1.Major.Id,
                Students       = await UserManager.GetStudentsOfClassAsync(class1).ToListAsync(),
                ClassTeacherId = class1.ClassTeacher == null ? null : class1.ClassTeacher.Teacher.Id
            };

            return(View(model));
        }
        public async Task <ActionResult> Create()
        {
            ViewBag.Positions = await PositionManager.GetAllEntities().ToListAsync();

            var teachers = await UserManager.GetNoPositionTeachersAsync();

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

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

            return(View());
        }
Exemplo n.º 6
0
        public ActionResult Index(int?p, string searchString, string currentFilter)
        {
            var list = DepartmentManager.GetAllEntities();

            if (searchString != null)
            {
                p = 1;
            }
            else
            {
                searchString = currentFilter;
            }
            ViewBag.CurrentFilter = searchString;
            list = list.Where(e => string.IsNullOrEmpty(searchString) || e.Name.Contains(searchString));
            list = list.OrderBy(e => e.Name);
            var pagesize = 5;
            var page     = p ?? 1;

            return(View(list.ToPagedList(page, pagesize)));
        }
        public async Task <ActionResult> Edit(ClassEditViewModel model)
        {
            var departments = await DepartmentManager.GetAllEntities().ToListAsync();

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

            ViewBag.departSelectList = departSelectList;

            var majors = await MajorManager.GetMajorsForDepartment(departments.ElementAtOrDefault(0)).ToListAsync();

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

            ViewBag.majorSelectList = majorSelectList;

            var grades = await GradeManager.GetAllEntities().ToListAsync();

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

            ViewBag.gradeSelectList = gradeSelectList;

            var teachers = (await UserManager.GetNoClassTeachersAsync()).ToList();

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

            ViewBag.Classes = await ClassManager.GetAllEntities().ToListAsync();

            if (ModelState.IsValid)
            {
                var class1 = await ClassManager.FindEntityByIdAsync(model.Id);

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

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

                if (major == null)
                {
                    ModelState.AddModelError("", "找不到major");
                    return(View(model));
                }
                var teacher = await UserManager.FindByIdAsync(model.ClassTeacherId);

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

                await ClassManager.UpdateEntityAsync(class1);

                teacher.TeacherInfo.ManageClass = class1;
                await UserManager.UpdateAsync(teacher);

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

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

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

                var majors = await MajorManager.GetMajorsForDepartment(departments.ElementAtOrDefault(0)).ToListAsync();

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

                var grades = await GradeManager.GetAllEntities().ToListAsync();

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

                var teachers = (await UserManager.GetNoClassTeachersAsync()).ToList();
                ViewBag.teacherSelectList = new SelectList(teachers, "Id", "Name");

                ViewBag.Classes = await ClassManager.GetAllEntities().ToListAsync();

                var grade = await GradeManager.FindEntityByIdAsync(model.GradeId);

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

                if (major == null)
                {
                    ModelState.AddModelError("", "找不到major");
                    return(View(model));
                }
                var teacher = await UserManager.FindByIdAsync(model.ClassTeacherId);

                if (teacher == null)
                {
                    ModelState.AddModelError("", "找不到teacher");
                    return(View(model));
                }
                var class1 = new Class
                {
                    ClassDefination = model.Defination,
                    Grade           = grade,
                    Major           = major,
                    ClassTeacher    = teacher.TeacherInfo
                };
                if (await ClassManager.IsEntityExistByLamdaAsync(c =>
                                                                 c.Grade.Id == class1.Grade.Id && c.Major.Id == class1.Major.Id &&
                                                                 c.ClassDefination == class1.ClassDefination))
                {
                    ModelState.AddModelError("", "已存在Class");
                    return(View(model));
                }
                var class2 = await ClassManager.AddEntityAsync(class1);

                teacher.TeacherInfo.ManageClass = class2;
                await UserManager.UpdateAsync(teacher);


                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
Exemplo n.º 9
0
        public async Task <ActionResult> Create()
        {
            ViewBag.Departments = await DepartmentManager.GetAllEntities().ToListAsync();

            return(View());
        }