Ejemplo n.º 1
0
        public void ChangeNickName(IWorkContext context, ChangeEmployeeNickNameCommand command)
        {
            if (this.NickName.IsEquals(command.NickName))
            {
                return;
            }

            this.ApplyEvent(new ChangeEmployeeNickNameEvent()
            {
                AggregateId = this.AggregateId,
                Creator     = context.GetWorkerName(),
                CreateDate  = context.WorkTime,
                Version     = this.Version,

                NickName = command.NickName,
            });
        }
        public ICommandHandlerResult Execute(ICommandContext context, ChangeEmployeeNickNameCommand command)
        {
            var root = context.GetAggregateRoot(command.AggregateId, () => employeeRepository.Rebuild(command.AggregateId));

            if (root == null)
            {
                return(context.CreateResult(CommandHandlerStatus.NotExists));
            }

            root.ChangeNickName(context, command);
            if (root.CanNotCommit())
            {
                return(context.CreateResult(CommandHandlerStatus.NothingChanged));
            }

            if (employeeRepository.Change(root) <= 0)
            {
                throw new RepositoryExcutingException("执行失败,请稍后再试");
            }

            return(context.CreateResult(CommandHandlerStatus.Success));
        }