Example #1
0
        public ActionResult EditEmployeeEducation(EditEmployeeEducation editEmployeeEducation)
        {
            ViewBag.Path1 = "教育信息>";
            var employee = db.Employee.Include(a => a.Educations).Where(a => a.UserId == WebSecurity.CurrentUserId && a.Id == editEmployeeEducation.EmployeeId).SingleOrDefault();
            if (employee == null)
            {
                return HttpNotFound();
            }

            if (employee.EmployeeStatus != EmployeeStatus.新增已通知)
            {
                return RedirectToAction("FrontDetail");
            }

            if (ModelState.IsValid)
            {
                var old = new HashSet<int>(employee.GetEducations().Select(a => a.Id));
                var cur = new HashSet<int>(editEmployeeEducation.EditEducations.Where(a => a.Delete == false).Select(a => a.EducationId));
                // 取得不在最新列表中的记录删除
                var del = (from a in old
                           where !(cur.Contains(a))
                           select a).ToList();
                foreach (var i in del)
                {
                    var e = db.Education.Find(i);
                    db.Education.Remove(e);
                }
                // end

                // 取得在最新列表中的记录更新
                var upd = (from a in old
                           where cur.Contains(a)
                           select a).ToList();
                foreach (var i in upd)
                {
                    var e1 = db.Education.Find(i);
                    var e2 = editEmployeeEducation.EditEducations.Where(a => a.EducationId == i).Single();
                    e1.School = e2.School;
                    e1.Major = e2.Major;
                    e1.Degree = e2.Degree.Value;
                    e1.Begin = e2.Begin.Value;
                    e1.End = e2.End;
                }
                // end

                // 取得在最新列表中的记录添加
                var add = editEmployeeEducation.EditEducations.Where(a => a.Delete == false && a.EducationId == 0);
                foreach (var i in add)
                {
                    var e = new Education { EmployeeId = employee.Id, School = i.School, Major = i.Major, Degree = i.Degree.Value, Begin = i.Begin.Value, End = i.End };
                    employee.Educations.Add(e);
                }
                // end
                db.PPSave();
                return RedirectToAction("EditEmployeeWork");
            }

            return View(editEmployeeEducation);
        }
Example #2
0
        public ActionResult EditEmployeeEducation()
        {
            ViewBag.Path1 = "教育信息>";
            Employee employee = db.Employee.Where(a => a.UserId == WebSecurity.CurrentUserId).SingleOrDefault();
            if (employee == null)
            {
                return HttpNotFound();
            }

            if (employee.EmployeeStatus != EmployeeStatus.新增已通知)
            {
                return RedirectToAction("FrontDetail");
            }

            var editEmployeeEducation = new EditEmployeeEducation { EmployeeId = employee.Id };

            Mapper.CreateMap<Education, EditEducation>().ForMember(x => x.EducationId, o => o.MapFrom(s => s.Id));
            var list = Mapper.Map<ICollection<Education>, ICollection<EditEducation>>(employee.GetEducations());

            editEmployeeEducation.EditEducations = list;

            return View(editEmployeeEducation);
        }