public void ChangeInfo(IWorkContext context, ChangeDepartmentInfoCommand command) { this.ApplyEvent(new ChangeDepartmentEvent { AggregateId = this.AggregateId, CreateDate = context.WorkTime, Creator = context.GetWorkerName(), Version = this.Version, Name = command.Name, Descn = command.Descn, }); }
public ICommandHandlerResult Execute(ICommandContext context, ChangeDepartmentInfoCommand command) { var root = context.GetAggregateRoot(command.AggregateId, () => departmentRepository.Rebuild(command.AggregateId)); if (root == null) { return(context.CreateResult(CommandHandlerStatus.NotExists)); } root.ChangeInfo(context, command); if (root.CanNotCommit()) { return(context.CreateResult(CommandHandlerStatus.NothingChanged)); } if (departmentRepository.Change(root) <= 0) { throw new RepositoryExcutingException("执行失败,请稍后再试"); } return(context.CreateResult(CommandHandlerStatus.Success)); }