Exemple #1
0
        public async Task <Unit> Handle(DeleteCustomerCommand request, CancellationToken cancellationToken)
        {
            var customer = await _unitOfWork.CustomerRepository.FindAsync(request.Id);

            _unitOfWork.Delete(customer);
            await _unitOfWork.CommitAsync();

            return(Unit.Value);
        }
        public async Task Consume(ConsumeContext <ICustomerRated> context)
        {
            var message  = context.Message;
            var customer = await _unitOfWork.CustomerRepository.GetCustomerWithRides(message.CustomerId);

            Fail.IfNull(customer, message.CustomerId);

            _customerService.RecalculateCustomerGrade(customer, message.Grade);
            await _unitOfWork.CommitAsync();
        }
        public async Task Consume(ConsumeContext <ICustomerPickedUp> context)
        {
            var message  = context.Message;
            var consumer = await _unitOfWork.CustomerRepository.GetCustomerWithRides(message.CustomerId);

            var currentRide = consumer.GetCurrentRideWhileWaitingForDriver();

            currentRide.MarkAsOnGoing();

            await _unitOfWork.CommitAsync();
        }
Exemple #4
0
        public async Task Consume(ConsumeContext <IOrderCompleted> context)
        {
            var message  = context.Message;
            var customer = await _unitOfWork.CustomerRepository.GetCustomerWithRidesAndPaymentMethods(message.CustomerId);

            var preferredPaymentMethod = customer.GetPrefferedPaymentMethod();
            var currentRide            = customer.GetCurrentRide();

            currentRide.Complete();

            await _paymentService.PerformPayment(preferredPaymentMethod, currentRide.Price);

            await _unitOfWork.CommitAsync();
        }
Exemple #5
0
        public async Task Consume(ConsumeContext <IRideTerminated> context)
        {
            var message = context.Message;

            if (message.DestinatedEntityType == RequestorType.Customer)
            {
                var customer = await _unitOfWork.CustomerRepository.GetCustomerWithRides(message.DestinatedEntityId);

                var ride = customer.GetCurrentRideWhileWaitingForDriver();
                ride.Cancel();

                await _unitOfWork.CommitAsync();
            }
        }
        public async Task Consume(ConsumeContext <IOrderCreated> context)
        {
            var message  = context.Message;
            var customer = await _unitOfWork.CustomerRepository.GetCustomerWithRides(message.CustomerId);

            var newRide = _rideService.CreateRide(message.Price,
                                                  message.DriverId,
                                                  message.DriverDetails,
                                                  message.StartPoint,
                                                  message.Destination);

            customer.AddRide(newRide);
            await _unitOfWork.CommitAsync();
        }
        public async Task <Unit> Handle(AddPaymentMethodCommand request, CancellationToken cancellationToken)
        {
            var customer = await _unitOfWork.CustomerRepository.GetCustomerWithPaymentMethods(request.Id);

            Fail.IfNull(customer, request.Id);

            var paymentMethod = _paymentMethodService.CreatePaymentMethod(request.Type, request.Email, request.Password,
                                                                          request.PhoneNumber, request.IsAlwaysLoggedIn, request.CardNumber, request.ExpiryDate, request.CvvCode, request.Country);

            customer.AddPaymentMethod(paymentMethod);
            await _unitOfWork.CommitAsync();

            return(Unit.Value);
        }
Exemple #8
0
        public async Task <Unit> Handle(DeletePaymentMethodCommand request, CancellationToken cancellationToken)
        {
            var customer = await _unitOfWork.CustomerRepository.GetCustomerWithPaymentMethods(request.Id);

            Fail.IfNull(customer, request.Id);

            var paymentMethod = customer.PaymentMethods.SingleOrDefault(x => x.Id == request.PaymentMethodId);

            Fail.IfNull(paymentMethod, request.PaymentMethodId);

            customer.RemovePaymentMethod(paymentMethod);
            await _unitOfWork.CommitAsync();

            return(Unit.Value);
        }
        public async Task <Unit> Handle(RequestRideCommand request, CancellationToken cancellationToken)
        {
            var customer = await _unitOfWork.CustomerRepository.FindAsync(request.Id);

            Fail.IfNull(customer, request.Id);

            customer.AddDomainEvent(new RideRequested(
                                        customer.Id,
                                        _mapper.Map <CustomerDetails>(customer),
                                        _mapper.Map <Address>(request.StartPoint),
                                        _mapper.Map <Address>(request.DestinationPoint)));

            await _unitOfWork.CommitAsync();

            return(Unit.Value);
        }
Exemple #10
0
        public async Task <Unit> Handle(RateDriverCommand request, CancellationToken cancellationToken)
        {
            var customer = await _unitOfWork.CustomerRepository.GetCustomerWithRides(request.CustomerId);

            Fail.IfNull(customer, request.CustomerId);

            var ride = customer.Rides.SingleOrDefault(x => x.Id == request.Id);

            Fail.IfNull(ride, request.Id);

            customer.AddDomainEvent(new DriverRated(ride.DriverId, request.Grade));

            await _unitOfWork.CommitAsync();

            return(Unit.Value);
        }
Exemple #11
0
        public async Task <Unit> Handle(UploadCustomerPhotoCommand request, CancellationToken cancellationToken)
        {
            var customer = await _unitOfWork.CustomerRepository.FindAsync(request.Id);

            Fail.IfNull(customer, request.Id);

            using (var memoryStream = new MemoryStream())
            {
                request.Photo.OpenReadStream().CopyTo(memoryStream);
                customer.PersonalInfo.Photo = memoryStream.ToArray();
            }

            await _unitOfWork.CommitAsync();

            return(Unit.Value);
        }
        public async Task <Unit> Handle(DeleteRouteCommand request, CancellationToken cancellationToken)
        {
            var customer = await _unitOfWork.CustomerRepository.GetCustomerWithRides(request.CustomerId);

            Fail.IfNull(customer, request.CustomerId);

            var ride = customer.Rides.SingleOrDefault(x => x.Id == request.Id);

            Fail.IfNull(ride, request.Id);

            var deletedRoute = _rideService.RemoveRoute(ride, request.RouteId);

            customer.AddDomainEvent(new RouteDeleted(ride.DriverId, deletedRoute.DestinationPoint));
            await _unitOfWork.CommitAsync();

            return(Unit.Value);
        }
        public async Task <Unit> Handle(AddRouteCommand request, CancellationToken cancellationToken)
        {
            var customer = await _unitOfWork.CustomerRepository.GetCustomerWithRides(request.CustomerId);

            Fail.IfNull(customer, request.CustomerId);

            var ride = customer.Rides.SingleOrDefault(x => x.Id == request.Id);

            Fail.IfNull(ride, request.Id);

            var destinationPointAddress = _mapper.Map <Address>(request.DestinationPoint);

            var addedRoute = _rideService.AddRoute(ride, request.PreviousRouteId, destinationPointAddress);

            customer.AddDomainEvent(
                new RouteAdded(ride.DriverId, addedRoute.PreviousRoute.DestinationPoint, destinationPointAddress));

            await _unitOfWork.CommitAsync();

            return(Unit.Value);
        }