コード例 #1
0
        public async Task Consume(ConsumeContext <IAvailableDriverFound> context)
        {
            var message = context.Message;
            var order   = new Domain.Entities.Order(message.CustomerId, message.DriverId);

            order.SetExecutionCountry(_orderService.GetExecutionCountry(message.DestinationPoint.Country));
            order.SetPaymentAmount(_orderService.GetPaymentAmount(
                                       string.Join(" ", message.StartPoint.Street, message.StartPoint.HouseNumber),
                                       message.StartPoint.City,
                                       message.StartPoint.State,
                                       string.Join(" ", message.DestinationPoint.Street, message.DestinationPoint.HouseNumber),
                                       message.DestinationPoint.City,
                                       message.DestinationPoint.State,
                                       message.DestinationPoint.Country));

            var money = _mapper.Map <Money>(order.PaymentAmount);

            order.AddDomainEvent(new OrderCreated(
                                     message.CustomerId,
                                     message.DriverId,
                                     money,
                                     message.CustomerDetails,
                                     message.DriverDetails,
                                     message.StartPoint,
                                     message.DestinationPoint));

            _unitOfWork.Add(order);
            await _unitOfWork.CommitAsync();
        }
コード例 #2
0
        public async Task Consume(ConsumeContext <IOrderCancelled> context)
        {
            var message = context.Message;

            var order = message.RequestorType == RequestorType.Customer
                ? await _unitOfWork.OrderRepository.GetCurrentOrderByCustomerId(message.RequestorId)
                : await _unitOfWork.OrderRepository.GetCurrentOrderByDriverId(message.RequestorId);

            order.Cancel(message.Comments);
            order.AddDomainEvent(message.RequestorType == RequestorType.Customer
                ? new RideTerminated(order.DriverId, RequestorType.Driver)
                : new RideTerminated(order.CustomerId, RequestorType.Customer));

            await _unitOfWork.CommitAsync();
        }
コード例 #3
0
        public async Task Consume(ConsumeContext <IRideFinished> context)
        {
            var message = context.Message;
            var order   = await _unitOfWork.OrderRepository.GetCurrentOrderByDriverId(message.DriverId);

            var customersInvoice = _orderService.CreateCustomersInvoice(
                message.CustomerId,
                message.CustomerDetails.Name,
                message.CustomerDetails.Surname,
                message.CustomerDetails.PhoneNumber,
                message.CustomerDetails.Email);

            order.SetDriverInvoice(message.DriversInvoice);
            order.SetCustomerInvoice(customersInvoice);

            order.Complete();
            order.AddDomainEvent(new OrderCompleted(message.CustomerId, customersInvoice));

            await _unitOfWork.CommitAsync();
        }