Example #1
0
 public void CreateFlowWithAssignId(Guid flowId, string flowName, User originator, string title, Dictionary<string, string> args = null, string comment = null)
 {
     var trans = TransactionManager.BeginTransaction();
     try
     {
         var flow = new Flow();
         flow.FlowStatus = FlowStatus.Instance;
         var flowType = _flowTypeRepository.GetByTypeName(flowName);
         if (flowType == null)
             throw new Exception(string.Format("{0}的流程类型不存在", flowName));
         flow.FlowType = flowType;
         flow.Id = flowId;
         flow.Title = title;
         args = args ?? new Dictionary<string, string>();
         args.ToList().ForEach(o => flow.FlowDataFields.Add(new FlowDataField { Name = o.Key, Value = o.Value }));
         flow.RecordDescription.CreateBy(originator);
         flow.UserOfFlowAdmin = originator;
         var history = new FlowHistory()
         {
             Comment = comment,
             Action = "提交流程",
             Stage = "发起流程"
         };
         history.RecordDescription.CreateBy(originator);
         flow.FlowHistories.Add(history);
         _flowRepository.Save(flow);
         trans.Commit();
     }
     catch (Exception)
     {
         trans.Rollback();
         throw;
     }
 }
Example #2
0
 public void ExecuteTask(Guid taskId, string actionName, User executor, Dictionary<string, string> args = null, string comment = null)
 {
     var trans = TransactionManager.BeginTransaction();
     try
     {
         var flowNodeInstanceTask = _flowNodeInstanceTaskRepository.Find(taskId);
         flowNodeInstanceTask.FlowNodeInstance.Execute(actionName, executor);
         flowNodeInstanceTask.FlowNodeInstance.BelongsFlow.WriteDataFields(args);
         var flow = flowNodeInstanceTask.FlowNodeInstance.BelongsFlow;
         var history = new FlowHistory()
         {
             Comment = comment,
             Action = actionName,
             Stage = flowNodeInstanceTask.FlowNodeInstance.BelongsFlowNode.Name
         };
         history.RecordDescription.CreateBy(executor);
         flow.FlowHistories.Add(history);
         _flowNodeInstanceRepository.Save(flowNodeInstanceTask.FlowNodeInstance);
         _flowNodeInstanceTaskRepository.Save(flowNodeInstanceTask);
         _flowRepository.Save(flow);
         trans.Commit();
     }
     catch (Exception)
     {
         trans.Rollback();
         throw;
     }
 }
Example #3
0
 public void CreateNewUnit(EditUnitModel model)
 {
     var trans = TransactionManager.BeginTransaction();
     try
     {
         var unit = new Unit()
         {
             Name = model.FormData.Name,
             IsFlowUint = model.FormData.IsFlowUnit,
             IsWebUint = model.FormData.IsWebUnit,
             ParentUint = model.ParentId.HasValue ? _unitRepository.Find(model.ParentId.Value) : null
         };
         _unitRepository.Save(unit);
         var user = new User()
         {
             Account = "admin",
             Name = "管理员",
             Pwd = Md5Utility.GetMd5HashCode("admin"),
             Unit = unit
         };
         InitUnitPermissions(unit, user);
         _userRepository.Save(user);
         trans.Commit();
     }
     catch (Exception)
     {
         trans.Rollback();
         throw;
     }
 }
Example #4
0
 private void DealMessage(NotifyMessage notifyMessage, User user)
 {
     var proposal = new Proposal();
     proposal.Content = notifyMessage.Content;
     proposal.IsFromMessage = true;
     proposal.ProposalType = ProposalType.NpcProposal;
     proposal.RecordDescription.CreateBy(user);
     proposal.Title = string.Format("{0}", MyString.SubString(notifyMessage.Content, 24, ""));
     _proposalRepository.Save(proposal);
     var args = new Dictionary<string, string>();
     var npcAuditor = ProposalRoleService.GetNpcAuditJieKouRen(user.Unit);
     args.Add("Originator", user.Id.ToString());
     args.Add("NpcAuditor", npcAuditor.Id.ToString());
     _flowService.CreateFlowWithAssignId(proposal.Id, "ProposalFlow", user,
         string.Format("{0}发起[{1}][短信]", user.Name, proposal.Title),
       args, "发起流程");
 }
 //HACK:想办法支持嵌套事务,可以统一提交,这样就可以重用更多的代码了
 public void ExecuteFlowNodeInstance(Guid flowNodeInstanceId, string actionName, User executor, string comment,
    Dictionary<string, string> args = null)
 {
     var trans = TransactionManager.BeginTransaction();
     try
     {
         var flowNodeInstance = _flowNodeInstanceRepository.Find(flowNodeInstanceId);
         if (flowNodeInstance == null)
             throw new ArgumentException("该任务未找到对应的流程节点对象");
         flowNodeInstance.Execute(actionName, executor);
         _flowNodeInstanceRepository.Save(flowNodeInstance);
         flowNodeInstance.BelongsFlow.WriteDataFields(args);
         _flowRepository.Save(flowNodeInstance.BelongsFlow);
         trans.Commit();
     }
     catch (Exception)
     {
         trans.Rollback();
         throw;
     }
 }
Example #6
0
 public virtual void ExecuteBy(FlowNodeAction action, User user)
 {
     TaskStatus = TaskStatus.Executed;
     FlowNodeAction = action;
     RecordDescription.UpdateBy(user);
 }
Example #7
0
 public RoleUser GetRoleUser(User user)
 {
     return RoleUsers.FirstOrDefault(o => o.UserId == user.Id);
 }
Example #8
0
 public virtual void UpdateBy(User operatorUser)
 {
     DateOfLastestModify = DateTime.Now;
     IsUpdated = true;
     UserOfLasetestModify = operatorUser;
 }
Example #9
0
 public virtual void CreateBy(User operatorUser)
 {
     IsCreated = true;
     DateOfCreate = DateTime.Now;
     UserOfCreate = operatorUser;
 }
Example #10
0
 public virtual void Done(User user, TaskStatus taskStatus)
 {
     var state = TaskUserStates.Single(o => o.Id == user.Id);
     state.RecordDescription.UpdateBy(user);
     state.TaskStatus = taskStatus;
 }
Example #11
0
 private void FillUser(User user, EditUserModel viewModel)
 {
     if (viewModel.FormData.DepartmentId == null)
         throw new ArgumentException("所属部门不能为空");
     user.Name = viewModel.FormData.Name;
     if (!(string.IsNullOrEmpty(viewModel.FormData.Pwd) || string.IsNullOrEmpty(viewModel.FormData.RePwd)) && viewModel.FormData.Pwd == viewModel.FormData.RePwd)
     {
         user.Pwd = Md5Utility.GetMd5HashCode(viewModel.FormData.Pwd);
     }
     user.QQ = viewModel.FormData.QQ;
     user.OrderSort = viewModel.FormData.OrderSort;
     user.Department = _departmentRepository.Find(viewModel.FormData.DepartmentId.Value);
 }
Example #12
0
 private static SelectUserOptionsComponent ConvertUser2SelectUserOptionsRow(User user)
 {
     return new SelectUserOptionsComponent()
     {
         Id = user.Id,
         Name = user.Name,
         NodeType = 2,
         State = "open",
         IconCls = ApplicationConst.TreeParentNode
     };
 }
Example #13
0
 public void NewUser(EditUserModel viewModel)
 {
     var userInContext = NpcContext.CurrentUser;
     if (_userRepository.IsRepeatAccount(viewModel.FormData.Mobile.Trim(), userInContext.Unit.Id))
     {
         throw new ArgumentException(string.Format("手机{0}已被使用,请选择其它的手机号码", viewModel.FormData.Mobile));
     }
     var user = new User();
     user.Account = viewModel.FormData.Mobile;
     FillUser(user, viewModel);
     user.Unit = userInContext.Unit;
     user.RecordDescription.CreateBy(userInContext);
     _userRepository.Save(user);
     var phoneBookService = new PhoneBookService();
     var phoneBook = phoneBookService.CreateOrGetDefaultPhoneBook(userInContext.Unit);
     var phoneBookRecord = new PhoneBookRecord();
     phoneBookRecord.Mobile = viewModel.FormData.Mobile;
     phoneBookRecord.Name = viewModel.FormData.Name;
     phoneBookRecord.User = user;
     phoneBookRecord.PhoneBook = phoneBook;
     phoneBookRecord.RecordDescription.CreateBy(userInContext);
     _phoneBookRecordRepository.Save(phoneBookRecord);
     user.PhoneBookRecord = phoneBookRecord;
     _userRepository.Save(user);
     if (!string.IsNullOrEmpty(viewModel.FormData.RoleNames))
         SaveOrUpdateRoleUser(user.Id, viewModel.FormData.RoleNames.Split(new[] { ',' }));
 }
Example #14
0
 private void InitUnitPermissions(Unit unit, User admin)
 {
     var privilegeRepository = new PrivilegeRepository();
     var privileges = privilegeRepository.GetAllPrivileges();
     var roleRepository = new RoleRepository();
     var roles = roleRepository.GetAllRoleByUnitId(unit.Id);
     var role = roles.FirstOrDefault(r => r.Code == "SuperAdmin");
     if (role == null)
     {
         role = new Role();
         role.Name = "超级管理员";
         role.Code = "SuperAdmin";
         role.UnitId = unit.Id;
         privileges.ToList().ForEach(privilege => role.Privileges.Add(privilege));
         roleRepository.Save(role);
     }
     var roleUserRepository = new RoleUserRepository();
     var roleUser = roleUserRepository.GetRoleUserByUserId(admin.Id);
     if (roleUser == null)
     {
         roleUser = new RoleUser();
         roleUser.UserId = admin.Id;
         roleUser.Roles.Add(role);
         roleUserRepository.Save(roleUser);
     }
 }