public void Update(IRoleUpdateIo input) { this.CategoryCode = input.CategoryCode; this.Description = input.Description; this.Icon = input.Icon; this.IsEnabled = input.IsEnabled; this.Name = input.Name; this.SortCode = input.SortCode; }
public RoleUpdatedEvent(IAcSession acSession, RoleBase source, IRoleUpdateIo output) : base(acSession, source) { if (output == null) { throw new ArgumentNullException("output"); } this.Output = output; }
private void Handle(IAcSession acSession, IRoleUpdateIo input, bool isCommand) { var acDomain = _set._acDomain; var roleDic = _set._roleDic; var roleRepository = acDomain.RetrieveRequiredService <IRepository <Role> >(); RoleState bkState; if (!acDomain.RoleSet.TryGetRole(input.Id, out bkState)) { throw new NotExistException(); } Role entity; bool stateChanged = false; lock (Locker) { RoleState oldState; if (!acDomain.RoleSet.TryGetRole(input.Id, out oldState)) { throw new NotExistException(); } if (acDomain.RoleSet.Any(a => string.Equals(a.Name, input.Name, StringComparison.OrdinalIgnoreCase) && a.Id != input.Id)) { throw new ValidationException("角色名称重复"); } entity = roleRepository.GetByKey(input.Id); if (entity == null) { throw new NotExistException(); } entity.Update(input); var newState = RoleState.Create(entity); stateChanged = newState != bkState; if (stateChanged) { Update(newState); } if (isCommand) { try { roleRepository.Update(entity); roleRepository.Context.Commit(); } catch { if (stateChanged) { Update(bkState); } roleRepository.Context.Rollback(); throw; } } } if (isCommand && stateChanged) { acDomain.MessageDispatcher.DispatchMessage(new RoleUpdatedEvent(acSession, entity, input, isPrivate: true)); } }
internal RoleUpdatedEvent(IAcSession acSession, RoleBase source, IRoleUpdateIo input, bool isPrivate) : this(acSession, source, input) { this.IsPrivate = isPrivate; }