public CatalogUpdatedEvent(IAcSession acSession, CatalogBase source, ICatalogUpdateIo input) : base(acSession, source) { if (input == null) { throw new System.ArgumentNullException("input"); } this.Input = input; }
public void Update(ICatalogUpdateIo input) { this.CategoryCode = input.CategoryCode; this.Code = input.Code; this.Description = input.Description; this.IsEnabled = input.IsEnabled; this.Name = input.Name; this.ParentCode = input.ParentCode; this.SortCode = input.SortCode; }
private void Handle(IAcSession acSession, ICatalogUpdateIo input, bool isCommand) { var acDomain = _set._acDomain; var catalogRepository = acDomain.RetrieveRequiredService <IRepository <Catalog> >(); if (string.IsNullOrEmpty(input.Code)) { throw new ValidationException("编码不能为空"); } CatalogState bkState; if (!acDomain.CatalogSet.TryGetCatalog(input.Id, out bkState)) { throw new ValidationException("给定标识的目录不存在" + input.Id); } Catalog entity; var stateChanged = false; lock (MessageLocker) { CatalogState oragnization; if (acDomain.CatalogSet.TryGetCatalog(input.Code, out oragnization) && oragnization.Id != input.Id) { throw new ValidationException("重复的目录码" + input.Code); } if (!string.IsNullOrEmpty(input.ParentCode)) { CatalogState parentOragnization; if (!acDomain.CatalogSet.TryGetCatalog(input.ParentCode, out parentOragnization)) { throw new ValidationException("标识为" + input.ParentCode + "的父目录不存在"); } if (input.ParentCode.Equals(input.Code, StringComparison.OrdinalIgnoreCase)) { throw new AnycmdException("目录的父目录不能是自己"); } if (!input.Code.StartsWith(parentOragnization.Code, StringComparison.OrdinalIgnoreCase)) { throw new ValidationException("子级目录的编码必须以父级目录编码为前缀"); } if (input.ParentCode.StartsWith(input.Code, StringComparison.OrdinalIgnoreCase)) { throw new AnycmdException("目录的父目录不能是自己的子孙级目录"); } } entity = catalogRepository.GetByKey(input.Id); if (entity == null) { throw new NotExistException(); } entity.Update(input); var newState = CatalogState.Create(acDomain, entity); stateChanged = newState != bkState; if (stateChanged) { Update(newState); } if (isCommand) { try { catalogRepository.Update(entity); catalogRepository.Context.Commit(); } catch { if (stateChanged) { Update(bkState); } catalogRepository.Context.Rollback(); throw; } } } if (isCommand && stateChanged) { acDomain.MessageDispatcher.DispatchMessage(new CatalogUpdatedEvent(acSession, entity, input, isPrivate: true)); } }
internal CatalogUpdatedEvent(IAcSession acSession, CatalogBase source, ICatalogUpdateIo input, bool isPrivate) : this(acSession, source, input) { this.IsPrivate = isPrivate; }