Exemplo n.º 1
0
        private static void ThrowExceptionIfAddressIsInvalid(DeliveryAddress deliveryAddress)
        {
            if (!deliveryAddress.GetBrokenRules().Any())
            {
                return;
            }

            var deliveryAddressIssues = new StringBuilder();

            deliveryAddressIssues.AppendLine("There were some issues with the address you are adding.");

            foreach (var rule in deliveryAddress.GetBrokenRules())
            {
                deliveryAddressIssues.AppendLine(rule.Rule);
            }

            throw new InvalidAddressException(deliveryAddressIssues.ToString());
        }
Exemplo n.º 2
0
        public CreateOrderResponse CreateOrder(CreateOrderRequest request)
        {
            var response = new CreateOrderResponse();

            var customer = _customerRepository.FindBy(request.CustomerId);

            var deliveryAddress = new DeliveryAddress
            {
                Customer = customer,
                Name = string.Format("{0} {1}", customer.FirstName, customer.LastName),
                AddressLine1 = request.AddressLine1,
                AddressLine2 = request.AddressLine2,
                City = request.City,
                State = request.State,
                ZipCode = request.ZipCode
            };

            customer.AddAddress(deliveryAddress);

            _customerRepository.Save(customer);

            var cart = _cartRepository.FindBy(request.CartId);

            var order = cart.ConvertToOrder();

            order.Customer = customer;

            order.OrderNumber = _nextSequenceRepository.ExecuteStoredProcedure("GetNextInSequence",
                new[] { new SqlParameter("sequenceKey", "SalesOrder") }).NextSequenceFormatted;

            order.DeliveryAddress = deliveryAddress;

            ThrowExceptionIfOrderIsInvalid(order);

            _orderRepository.Save(order);

            _cartRepository.Remove(cart);

            _uow.Commit();

            response.Order = order.ConvertToOrderView();

            return response;
        }
Exemplo n.º 3
0
        public virtual void AddAddress(DeliveryAddress deliveryAddress)
        {
            ThrowExceptionIfAddressIsInvalid(deliveryAddress);

            _deliveryAddressBook.Add(deliveryAddress);
        }