public async Task <bool> Handle(CreateOrderCommand request, CancellationToken cancellationToken)
        {
            var order = new Domain.AggregatesModel.OrderAggregate.Order(request.User1Id, request.User2Id, request.User1Type, request.User2Type, request.DealId,
                                                                        request.AppointmentedUserType, request.PayerType, request.PayerId, request.Price, request.AppointedTime, request.Text,
                                                                        request.Latitude, request.Longitude, request.LocationName, request.Address);

            _orderRepository.Add(order);
            return(await _orderRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken));
        }
예제 #2
0
 public static OrderDraftDto FromOrder(Domain.AggregatesModel.OrderAggregate.Order order)
 {
     return(new OrderDraftDto
     {
         OrderItems = order.OrderItems.Select(oi => new CreateOrderCommand.OrderItemDto
         {
             Discount = oi.GetCurrentDiscount(),
             ProductId = oi.ProductId,
             UnitPrice = oi.GetUnitPrice(),
             PictureUrl = oi.GetPictureUri(),
             Units = oi.GetUnits(),
             ProductName = oi.GetOrderItemProductName()
         }),
         Total = order.GetTotal()
     });
 }
예제 #3
0
        public async Task <bool> Handle(CreateOrderCommand message, CancellationToken cancellationToken)
        {
            // Add/Update the Buyer AggregateRoot
            // DDD patterns comment: Add child entities and value-objects through the Order Aggregate-Root
            // methods and constructor so validations, invariants and business logic
            // make sure that consistency is preserved across the whole aggregate
            var address = new Address(message.Street, message.City, message.State, message.Country, message.ZipCode);
            var order   = new Domain.AggregatesModel.OrderAggregate.Order(message.UserId, message.UserName, address,
                                                                          message.CardTypeId, message.CardNumber, message.CardSecurityNumber, message.CardHolderName,
                                                                          message.CardExpiration);

            foreach (var item in message.OrderItems)
            {
                order.AddOrderItem(item.ProductId, item.ProductName, item.UnitPrice, item.Discount, item.PictureUrl,
                                   item.Units);
            }

            _orderRepository.Add(order);

            return(await _orderRepository.UnitOfWork
                   .SaveEntitiesAsync(cancellationToken));
        }