public FunctionUpdatedEvent(IAcSession acSession, FunctionBase source, IFunctionUpdateIo input) : base(acSession, source) { if (input == null) { throw new System.ArgumentNullException("input"); } this.Input = input; }
public void Update(IFunctionUpdateIo input) { this.Code = input.Code; this.IsManaged = input.IsManaged; this.IsEnabled = input.IsEnabled; this.Description = input.Description; this.DeveloperId = input.DeveloperId; this.SortCode = input.SortCode; }
private void Handle(IAcSession acSession, IFunctionUpdateIo input, bool isCommand) { var acDomain = _set._acDomain; var functionRepository = acDomain.RetrieveRequiredService <IRepository <Function> >(); if (string.IsNullOrEmpty(input.Code)) { throw new ValidationException("编码不能为空"); } FunctionState bkState; if (!acDomain.FunctionSet.TryGetFunction(input.Id, out bkState)) { throw new NotExistException(); } CatalogState resource; if (!acDomain.CatalogSet.TryGetCatalog(bkState.ResourceTypeId, out resource)) { throw new ValidationException("意外的功能资源标识" + bkState.ResourceTypeId); } Function entity; bool stateChanged = false; lock (Locker) { FunctionState oldState; if (!acDomain.FunctionSet.TryGetFunction(input.Id, out oldState)) { throw new NotExistException(); } FunctionState functionState; if (acDomain.FunctionSet.TryGetFunction(resource, input.Code, out functionState) && functionState.Id != input.Id) { throw new ValidationException("重复的编码"); } entity = functionRepository.GetByKey(input.Id); if (entity == null) { throw new NotExistException("更新的实体不存在"); } entity.Update(input); var newState = FunctionState.Create(acDomain, entity); stateChanged = newState != bkState; if (stateChanged) { Update(newState); } if (isCommand) { try { functionRepository.Update(entity); functionRepository.Context.Commit(); } catch { if (stateChanged) { Update(bkState); } functionRepository.Context.Rollback(); throw; } } } if (isCommand && stateChanged) { acDomain.MessageDispatcher.DispatchMessage(new FunctionUpdatedEvent(acSession, entity, input) { IsPriviate = true }); } }