private void Handle(IAcSession acSession, IMenuUpdateIo input, bool isCommand) { var acDomain = _set._acDomain; var menuById = _set._menuById; var menuRepository = acDomain.RetrieveRequiredService <IRepository <Menu, Guid> >(); MenuState bkState; if (!acDomain.MenuSet.TryGetMenu(input.Id, out bkState)) { throw new ValidationException("给定标识的菜单不存在" + input.Id); } Menu entity; var stateChanged = false; lock (Locker) { MenuState oldState; if (!acDomain.MenuSet.TryGetMenu(input.Id, out oldState)) { throw new ValidationException("给定标识的菜单不存在" + input.Id); } entity = menuRepository.GetByKey(input.Id); if (entity == null) { throw new NotExistException(); } entity.Update(input); var newState = MenuState.Create(acDomain, entity); stateChanged = newState != bkState; if (stateChanged) { Update(newState); } if (isCommand) { try { menuRepository.Update(entity); menuRepository.Context.Commit(); } catch { if (stateChanged) { Update(bkState); } menuRepository.Context.Rollback(); throw; } } } if (isCommand && stateChanged) { acDomain.MessageDispatcher.DispatchMessage(new MenuUpdatedEvent(acSession, entity, input, isPrivate: true)); } }
public void Update(IMenuUpdateIo input) { this.AppSystemId = input.AppSystemId; this.Description = input.Description; this.Icon = input.Icon; this.Name = input.Name; this.SortCode = input.SortCode; this.Url = input.Url; }
public MenuUpdatedEvent(IAcSession acSession, MenuBase source, IMenuUpdateIo input) : base(acSession, source) { if (input == null) { throw new System.ArgumentNullException("input"); } this.Input = input; }
internal MenuUpdatedEvent(IAcSession acSession, MenuBase source, IMenuUpdateIo input, bool isPrivate) : this(acSession, source, input) { this.IsPrivate = isPrivate; }