public ButtonUpdatedEvent(IAcSession acSession, ButtonBase source, IButtonUpdateIo input) : base(acSession, source) { if (input == null) { throw new System.ArgumentNullException("input"); } this.Input = input; }
public void Update(IButtonUpdateIo input) { this.Code = input.Code; this.CategoryCode = input.CategoryCode; this.Description = input.Description; this.Icon = input.Icon; this.IsEnabled = input.IsEnabled; this.Name = input.Name; this.SortCode = input.SortCode; }
private void Handle(IAcSession acSession, IButtonUpdateIo input, bool isCommand) { var acDomain = _set._acDomain; var buttonRepository = acDomain.RetrieveRequiredService <IRepository <Button> >(); if (string.IsNullOrEmpty(input.Code)) { throw new ValidationException("编码不能为空"); } ButtonState bkState; if (!acDomain.ButtonSet.TryGetButton(input.Id, out bkState)) { throw new NotExistException("意外的按钮标识" + input.Id); } Button entity; var stateChanged = false; lock (MessageLocker) { ButtonState oldState; if (!acDomain.ButtonSet.TryGetButton(input.Id, out oldState)) { throw new NotExistException("意外的按钮标识" + input.Id); } ButtonState button; if (acDomain.ButtonSet.TryGetButton(input.Code, out button) && button.Id != input.Id) { throw new ValidationException("重复的按钮编码"); } entity = buttonRepository.GetByKey(input.Id); if (entity == null) { throw new NotExistException(); } entity.Update(input); var newState = ButtonState.Create(entity); stateChanged = bkState != newState; if (stateChanged) { Update(newState); } if (isCommand) { try { buttonRepository.Update(entity); buttonRepository.Context.Commit(); } catch { if (stateChanged) { Update(bkState); } buttonRepository.Context.Rollback(); throw; } } } if (isCommand && stateChanged) { acDomain.MessageDispatcher.DispatchMessage(new ButtonUpdatedEvent(acSession, entity, input, isPrivate: true)); } }
internal ButtonUpdatedEvent(IAcSession acSession, ButtonBase source, IButtonUpdateIo input, bool isPrivate) : this(acSession, source, input) { this.IsPrivate = isPrivate; }