public static wfRequestForm EntityMap(this wfRequestFormView model) { //2.0 将一个实体转换成另外一个实体 return(Mapper.Map <wfRequestFormView, wfRequestForm>(model)); }
public ActionResult add(wfRequestFormView model) { if (ModelState.IsValid == false) { return(WriteError("实体属性验证失败")); } int uid = UserMgr.GetCurrentUserInfo().uID; //补全数据 model.fCreateTime = DateTime.Now; model.fUpdateTime = DateTime.Now; model.fCreatorID = UserMgr.GetCurrentUserInfo().uID; model.wfRFStatus = (int)Enums.ERequestFormStatus.Processing; //2.0 将实体追加到EF容器 wfRequestForm entity = model.EntityMap(); requestformSer.Add(entity); using (System.Transactions.TransactionScope scop = new System.Transactions.TransactionScope()) { requestformSer.SaveChanges(); //获取当前新增的申请单的最新主键值 int wfRFID = entity.wfRFID; //2.0.1 根据wfid获取工作流下面的第1,2个节点数据 var nodes = workSer.QueryWhere(c => c.wfID == model.wfID).FirstOrDefault().wfWorkNodes .OrderBy(c => c.wfnOrderNo).ToList(); //判断nodes是否有值 if (nodes == null || nodes.Count() < 2) { return(WriteError("您所选的工作流中不存在节点数据,请联系管理")); } //2.0.2 获取当前登录用户所在的角色 var role = userinfoRoleSer.QueryWhere(c => c.uID == uid).FirstOrDefault(); //3.0 向wfProcess表中插入数据 //3.0.1 向wfProcess表中插入数据一条申请成功的数据 wfProcess process = new wfProcess() { fCreateTime = DateTime.Now, fCreatorID = UserMgr.GetCurrentUserInfo().uID, fUpdateTime = DateTime.Now, wfnID = nodes[0].wfnID, wfPDescription = "申请单已经提交", wfProcessor = role.rID, wfRFID = wfRFID, wfPExt1 = UserMgr.GetCurrentUserInfo().uID.ToString(), wfRFStatus = (int)Enums.ERequestFormStatus.Pass //通过 }; //追加到EF容器 processSer.Add(process); //3.0.2 向wfProcess表中插入数据一条审批节点的审批数据 int secWfnid = nodes[1].wfnID; int roleType = nodes[1].wfnRoleType; //次节点的审批角色类型 int eDeptID = UserMgr.GetCurrentUserInfo().uWorkGroupID.Value; //获取当前申请人所在的部门 //获取当前节点的审批角色id int processRoleid = roleSer.QueryWhere(c => c.eDepID == eDeptID && c.RoleType == roleType).FirstOrDefault().rID; wfProcess process1 = new wfProcess() { fCreateTime = DateTime.Now, fCreatorID = UserMgr.GetCurrentUserInfo().uID, fUpdateTime = DateTime.Now, wfnID = secWfnid, wfPDescription = "", wfProcessor = processRoleid, wfRFID = wfRFID, wfRFStatus = (int)Enums.ERequestFormStatus.Processing //处理中 }; //追加到EF容器 processSer.Add(process1); processSer.SaveChanges(); scop.Complete(); } return(WriteSuccess("新增成功")); }
public ActionResult add(wfRequestFormView model) { //int uid = UserMgr.GetUserInfo().uID; //using (System.Transactions.TransactionScope scop = new System.Transactions.TransactionScope()) //{ // //1.0 向wfRequestForm表中插入一条申请单数据 // model.fCreateTime = DateTime.Now; // model.fCreatorID = UserMgr.GetUserInfo().uID; // model.fUpdateTime = DateTime.Now; // model.wfRFStatus = (int)Enums.EPorcessStatus.Processing; // //1.0.2 将实体追加到EF容器中 // wfRequestForm entity = model.EntityMap(); // requestformSer.Add(entity); // //1.0.3 统一保存 ,entity.wfRFID=自增主键 // requestformSer.SaveChanges(); // //2.0 向wfprocess表中插入一条申请通过的明细数据(相当于是工作流的第一个节点) // //2.0.1 获取当前工作流的第一个节点和第二个节点 // var nodeList = worknodesSer.QueryWhere(c => c.wfID == model.wfID).OrderBy(c => c.wfnOrderNo).ToList(); // //2.0.2 判断nodelist的长度是否大于2 // if (nodeList.Count() <= 2) // { // return WriteError("当前工作流程节点设定异常,请联系管理员"); // } // var fistNode = nodeList[0]; // var sedNode = nodeList[1]; // //2.0.3 获取当前登录用所在的角色id // sysUserInfo_Role urmodel = userinfoRoleSer.QueryWhere(c => c.uID == uid).FirstOrDefault(); // wfProcess fistProcess = new wfProcess() // { // fCreateTime = DateTime.Now, // fUpdateTime = DateTime.Now, // fCreatorID = uid, // wfnID = fistNode.wfnID, // wfRFStatus = (int)Enums.EPorcessStatus.Pass, // wfPDescription = "申请单提交成功", // wfPExt1 = uid.ToString(), // wfRFID = entity.wfRFID, // wfProcessor = urmodel.rID // }; // //将第一个处理明细数据添加到EF容器中 // processSer.Add(fistProcess); // //3.0向wfprocess表中插入一条工作流第2个节点的审核中数据 // //3.0.1 // int sedRoleType = sedNode.wfnRoleType; // int groupid = UserMgr.GetUserInfo().uWorkGroupID.HasValue ? UserMgr.GetUserInfo().uWorkGroupID.Value : 0; // int? :可空类型 Datetime? // //3.0.2 去表sysRole中查找出rid select rid from sysRole where eDepID=groupid and RoleType=sedRoleType // sysRole role = roleSer.QueryWhere(c => c.eDepID == groupid && c.RoleType == sedRoleType).FirstOrDefault(); // if (role == null) // { // return WriteError("当前节点审批角色不存在,请联系管理员"); // } // wfProcess sedProcess = new wfProcess() // { // fCreateTime = DateTime.Now, // fUpdateTime = DateTime.Now, // fCreatorID = uid, // wfnID = sedNode.wfnID, // wfRFStatus = (int)Enums.EPorcessStatus.Processing, // wfPDescription = null, // wfRFID = entity.wfRFID, // wfProcessor = role.rID //1 获取第二个节点中的审批角色类型 wfnroletype 2 结合当前登录用户所在的工作组id 去sysrole表获取rid // }; // //将第二个处理明细数据添加到EF容器中 // processSer.Add(sedProcess); // // // processSer.SaveChanges(); // //事务提交 // scop.Complete(); //} ////返回成功 //return WriteSuccess("新增成功"); return(Json("")); }
public static wfRequestForm EntityMap(this wfRequestFormView model) { return(Mapper.Map <wfRequestFormView, wfRequestForm>(model)); }