示例#1
0
        public ICommandHandlerResult Execute(ICommandContext context, DestroyEmailCodeCommand command)
        {
            var root = context.GetAggregateRoot(command.AggregateId, () => { return(this.repository.Rebuild(command.Email, command.UsageType)); });

            if (root == null)
            {
                return(context.CreateResult(CommandHandlerStatus.NotExists, "验证失败"));
            }

            var validation = root.Destroy(context, command);

            if (!root.CanCommit())
            {
                return(context.CreateResult(validation.HasValue && validation.Value.Option == ValidationOption.Continue ? CommandHandlerStatus.NothingChanged : CommandHandlerStatus.Fail, validation.HasValue ? validation.Value.ErrorMessage : ""));
            }

            if (this.repository.Destroy(root) <= 0)
            {
                throw new RepositoryExcutingException("验证失败,请稍后再尝试");
            }

            return(context.CreateResult(CommandHandlerStatus.Success));
        }
        public ValidationFailure?Destroy(IWorkContext context, DestroyEmailCodeCommand command)
        {
            if (this.UsageStatus == UsageStatus.已使用)
            {
                return(this.RejectBreak(this, m => m.ExpireTime, "验证码已使用"));
            }

            if (this.ExpireTime < context.WorkTime)
            {
                return(this.RejectBreak(this, m => m.ExpireTime, "验证码已过期"));
            }

            if (this.UsageType != command.UsageType)
            {
                return(this.RejectBreak(this, m => m.UsageType, "验证码不正确"));
            }

            if (this.UsageCode.IsNotEquals(command.VCode))
            {
                return(this.RejectBreak(this, m => m.UsageCode, "验证码错误"));
            }

            this.ApplyEvent(new DestroyEmailCodeEvent()
            {
                AggregateId = this.AggregateId,
                Version     = this.Version,
                CreateDate  = context.WorkTime,
                Creator     = context.GetWorkerName(),
                Email       = this.Email,
                UsageStatus = UsageStatus.已使用,
                UsageType   = this.UsageType,
                Message     = this.UsageCode,
            });

            return(null);
        }