protected override Task <RequestStatus> HandleCommand(ResetPasswordCommand request,
                                                              CancellationToken cancellationToken)
        {
            var resetCode = FindResetCode(request);
            var user      = FindUserAuthenticationData(resetCode, request);

            if (resetCode.IsExpired)
            {
                _resetPasswordCodeRepository.RemoveResetPasswordCode(resetCode.ResetCode, resetCode.Email);
                return(Task.FromResult(RequestStatus.CreateFromCommandContext(request.CommandContext, Status.FAILED)));
            }

            if (!resetCode.Checked)
            {
                throw new InvalidCommandException("ResetCode must be checked first");
            }

            user.Password = request.NewPassword;
            _userAuthenticationDataRepository.UpdateUserAuth(user);

            _logger.LogInformation("User with email {email} and reset code {@resetCode} has changed password", request.Email, resetCode);
            return(Task.FromResult(RequestStatus.CreateFromCommandContext(request.CommandContext, Status.COMPLETED)));
        }
Ejemplo n.º 2
0
        protected override Task <RequestStatus> HandleCommand(BidCommand request, CancellationToken cancellationToken)
        {
            var auction = _auctionRepository.FindAuction(request.AuctionId);

            if (auction == null)
            {
                throw new CommandException("Invalid auction id");
            }

            var user = _userRepository.FindUser(request.SignedInUser);

            if (user == null)
            {
                throw new CommandException($"Cannot find user {request.SignedInUser.UserName}");
            }

            auction.Raise(user, request.Price);
            var bid = auction.Bids.Last();

            var response = RequestStatus.CreateFromCommandContext(request.CommandContext, Status.PENDING);

            _auctionRepository.UpdateAuction(auction);
            _userRepository.UpdateUser(user);
            var toSend = auction.PendingEvents.Concat(user.PendingEvents);

            _eventBusService.Publish(toSend, response.CorrelationId, request);
            _requestStatusService.TrySendNotificationToAll("AuctionPriceChanged", new Dictionary <string, object>()
            {
                { "winningBid", bid }
            });
            auction.MarkPendingEventsAsHandled();
            _logger.LogDebug("Bid {@bid} submited for an auction {@auction} by {@user}", bid, auction, request.SignedInUser);


            return(Task.FromResult(response));
        }