コード例 #1
0
ファイル: EmployeeController.cs プロジェクト: pennsong/OB
        public ActionResult EditEmployeeDoc(EditEmployeeDoc editEmployeeDoc)
        {
            ViewBag.Path1 = "上传资料>";
            var employee = db.Employee.Include(a => a.EmployeeDocs).Where(a => a.UserId == WebSecurity.CurrentUserId && a.Id == editEmployeeDoc.EmployeeId).SingleOrDefault();
            if (employee == null)
            {
                return HttpNotFound();
            }

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

            if (ModelState.IsValid)
            {
                var old = new HashSet<int>(employee.GetEmployeeDocs().Select(a => a.Id));
                var cur = new HashSet<int>(editEmployeeDoc.EditSingleEmployeeDocs.Where(a => a.EmployeeDocId != 0).Select(a => a.EmployeeDocId));

                // 取得在最新列表中的记录更新
                var upd = (from a in old
                           where cur.Contains(a)
                           select a).ToList();
                foreach (var i in upd)
                {
                    var e1 = db.EmployeeDoc.Find(i);
                    var e2 = editEmployeeDoc.EditSingleEmployeeDocs.Where(a => a.EmployeeDocId == i).Single();
                    e1.ImgPath = e2.ImgPath;
                }
                // end

                // 取得在最新列表中的记录添加
                var add = editEmployeeDoc.EditSingleEmployeeDocs.Where(a => !String.IsNullOrWhiteSpace(a.ImgPath) && a.EmployeeDocId == 0);
                foreach (var i in add)
                {
                    var e = new EmployeeDoc { EmployeeId = employee.Id, DocumentId = i.DocumentId, ImgPath = i.ImgPath };
                    employee.EmployeeDocs.Add(e);
                }
                // end
                db.PPSave();
                return RedirectToAction("FrontDetail");
            }

            return View(editEmployeeDoc);
        }
コード例 #2
0
ファイル: EmployeeController.cs プロジェクト: pennsong/OB
        public ActionResult EditEmployeeDoc()
        {
            ViewBag.Path1 = "上传资料>";
            var employee = db.Employee.Include(a => a.EmployeeDocs).Where(a => a.UserId == WebSecurity.CurrentUserId).SingleOrDefault();
            if (employee == null)
            {
                return HttpNotFound();
            }

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

            var editEmployeeDoc = new EditEmployeeDoc { EmployeeId = employee.Id };

            // 取得资料列表模版
            var clientPensionCityDocument = db.ClientPensionCityDocument.Include(a => a.Documents).Where(a => a.ClientId == employee.ClientId && ((a.PensionCityId == null && employee.PensionCityId == null) || (a.PensionCityId == employee.PensionCityId))).SingleOrDefault();
            if (clientPensionCityDocument == null || clientPensionCityDocument.Documents == null)
            {
                throw new Exception("对应资料列表未配置, 请联系客服人员!");
            }

            foreach (var item in clientPensionCityDocument.Documents)
            {
                var employeeDoc = employee.EmployeeDocs.Where(a => a.DocumentId == item.Id).SingleOrDefault();
                var imgPath = "";
                int employeeDocId = 0;
                if (employeeDoc != null)
                {
                    imgPath = employeeDoc.ImgPath;
                    employeeDocId = employeeDoc.Id;
                }
                var editSingleEmployeeDoc = new EditSingleEmployeeDoc { EmployeeDocId = employeeDocId, DocumentId = item.Id, DocumentName = item.Name, ImgPath = (String.IsNullOrWhiteSpace(imgPath)) ? null : imgPath };
                editEmployeeDoc.EditSingleEmployeeDocs.Add(editSingleEmployeeDoc);
            }

            return View(editEmployeeDoc);
        }