예제 #1
0
            private void Handle(IAcSession acSession, IRoleCreateIo input, bool isCommand)
            {
                var acDomain       = _set._acDomain;
                var roleDic        = _set._roleDic;
                var roleRepository = acDomain.RetrieveRequiredService <IRepository <Role> >();

                if (!input.Id.HasValue)
                {
                    throw new ValidationException("标识是必须的");
                }
                Role entity;

                lock (Locker)
                {
                    RoleState role;
                    if (acDomain.RoleSet.TryGetRole(input.Id.Value, out role))
                    {
                        throw new ValidationException("已经存在");
                    }
                    if (acDomain.RoleSet.Any(a => string.Equals(a.Name, input.Name, StringComparison.OrdinalIgnoreCase)))
                    {
                        throw new ValidationException("同名的角色已经存在");
                    }

                    entity = Role.Create(input);

                    if (!roleDic.ContainsKey(entity.Id))
                    {
                        var state = RoleState.Create(entity);
                        roleDic.Add(entity.Id, state);
                    }
                    if (isCommand)
                    {
                        try
                        {
                            roleRepository.Add(entity);
                            roleRepository.Context.Commit();
                        }
                        catch
                        {
                            if (roleDic.ContainsKey(entity.Id))
                            {
                                roleDic.Remove(entity.Id);
                            }
                            roleRepository.Context.Rollback();
                            throw;
                        }
                    }
                }
                if (isCommand)
                {
                    acDomain.MessageDispatcher.DispatchMessage(new RoleAddedEvent(acSession, entity, input, isPrivate: true));
                }
            }
예제 #2
0
 public static Role Create(IRoleCreateIo input)
 {
     Debug.Assert(input.Id != null, "input.Id != null");
     return(new Role(input.Id.Value)
     {
         CategoryCode = input.CategoryCode,
         Description = input.Description,
         Icon = input.Icon,
         IsEnabled = input.IsEnabled,
         Name = input.Name,
         SortCode = input.SortCode
     });
 }
예제 #3
0
파일: Role.cs 프로젝트: mingkongbin/anycmd
 public static Role Create(IRoleCreateIo input)
 {
     Debug.Assert(input.Id != null, "input.Id != null");
     return new Role
     {
         CategoryCode = input.CategoryCode,
         Description = input.Description,
         Icon = input.Icon,
         Id = input.Id.Value,
         IsEnabled = input.IsEnabled,
         Name = input.Name,
         SortCode = input.SortCode
     };
 }
예제 #4
0
 public void AddDescendant(IAcSession subject, Guid parentRoleId, IRoleCreateIo childRoleCreateInput)
 {
     _acDomain.Handle(new AddRoleCommand(subject, childRoleCreateInput));
     Debug.Assert(childRoleCreateInput.Id != null, "childRoleCreateInput.Id != null");
     _acDomain.Handle(new AddPrivilegeCommand(subject, new PrivilegeCreateIo
     {
         Id                = Guid.NewGuid(),
         SubjectType       = UserAcSubjectType.Role.ToName(),
         SubjectInstanceId = childRoleCreateInput.Id.Value,
         ObjectType        = AcElementType.Role.ToName(),
         ObjectInstanceId  = parentRoleId,
         AcContent         = null,
         AcContentType     = null
     }));
 }
예제 #5
0
 public void AddDescendant(IAcSession subject, Guid parentRoleId, IRoleCreateIo childRoleCreateInput)
 {
     _acDomain.Handle(new AddRoleCommand(subject, childRoleCreateInput));
     Debug.Assert(childRoleCreateInput.Id != null, "childRoleCreateInput.Id != null");
     _acDomain.Handle(new AddPrivilegeCommand(subject, new PrivilegeCreateIo
     {
         Id = Guid.NewGuid(),
         SubjectType = UserAcSubjectType.Role.ToName(),
         SubjectInstanceId = childRoleCreateInput.Id.Value,
         ObjectType = AcElementType.Role.ToName(),
         ObjectInstanceId = parentRoleId,
         AcContent = null,
         AcContentType = null
     }));
 }
예제 #6
0
 public void AddRole(IAcSession subject, IRoleCreateIo input)
 {
     _acDomain.Handle(new AddRoleCommand(subject, input));
 }
예제 #7
0
 public void AddRole(IAcSession subject, IRoleCreateIo input)
 {
     _acDomain.Handle(new AddRoleCommand(subject, input));
 }