Exemple #1
0
 public static CustomerDTO FromCustomer(Customer customer)
 {
     return(new CustomerDTO
     {
         Id = customer.Id,
         Username = customer.Username,
         Password = customer.Password,
         ForeName = customer.ForeName,
         Surname = customer.Surname,
         Title = customer.Title,
         Email = customer.Email,
         Telephone = customer.Telephone,
         Status = customer.Status,
         IsAdmin = customer.IsAdmin,
         Addresses = _getCustomerAddress.GetAddressesForCustomer(customer.Id),
         PaymentOptions = _getPaymentOptions.GetPaymentOptionsForCustomer(customer.Id)
     });
 }
Exemple #2
0
        public CartDTO Get(int customerId)
        {
            var cartItems = _getCartItem.GetAllForCustomer(customerId);

            var cartItemDTOList = new List <CartItemDTO>();

            foreach (var cartItem in cartItems)
            {
                var product = _getProduct.GetById(cartItem.ProductId);

                cartItemDTOList.Add(new CartItemDTO
                {
                    Id             = cartItem.Id,
                    Description    = product.Description,
                    LargeImagePath = product.LargeImagePath,
                    SmallImagePath = product.SmallImagePath,
                    Price          = product.Price,
                    Quantity       = cartItem.Quantity,
                    SKU            = product.SKU,
                    CustomerId     = customerId,
                    ProductId      = product.Id
                });
            }

            var subtotal       = cartItemDTOList.Sum(i => i.Subtotal);
            var discountRule   = DiscountManager.Instance.GetDiscount(subtotal);
            var discountValue  = discountRule.CalculatedDiscount;
            var total          = subtotal - discountValue;
            var addresses      = _getCustomerAddress.GetAddressesForCustomer(customerId);
            var paymentOptions = _getPaymentOption.GetPaymentOptionsForCustomer(customerId);

            return(new CartDTO
            {
                Subtotal = subtotal,
                DiscountRate = discountRule.Rate * 100M,
                DiscountValue = discountValue,
                Total = total,
                CustomerId = customerId,
                CartItems = cartItemDTOList,
                DeliveryAddressId = addresses?.FirstOrDefault().Id ?? 0,
                PaymentOptionId = paymentOptions?.FirstOrDefault().Id ?? 0
            });
        }