Beispiel #1
0
        public async Task <double> GetTotalAmountAfterDiscountsAsync(CartDTO cart)
        {
            double totalAmountWithoutDiscounts   = 0;
            IList <CartDetailDTO> cartDetailDTOs = await GetCartDetailsAsync(cart.CartId);

            foreach (CartDetailDTO item in cartDetailDTOs)
            {
                totalAmountWithoutDiscounts += (await _productEFService.GetProductAsync(item.ProductId)).Price * item.ProductQuantity;
            }
            return(totalAmountWithoutDiscounts - (await GetCampaignDiscountAsync(cart)) - (await GetCouponDiscountAsync(cart)));
        }
Beispiel #2
0
        public async Task <double> CalculateDeliveryCostAndCountAsync(int cartId, double costPerDelivery, double costPerProduct, double fixedCost)
        {
            Cart cart = new Cart(_cartEFService, _mapper, _productEFService, _categoryEFService);
            IList <CartDetailDTO> cartDetailDTOs = await cart.GetCartDetailsAsync(cartId);

            int    numberOfDeliveries = cartDetailDTOs.Select(async cd => (await _productEFService.GetProductAsync(cd.ProductId)).CategoryId).Distinct().Count();
            double deliveryCost       = (costPerDelivery * numberOfDeliveries) + (costPerProduct * cartDetailDTOs.Select(cd => cd.ProductId).Distinct().Count()) + fixedCost;

            deliveryCost = Math.Round(deliveryCost, 2);
            DeliveryDTO deliveryDTO = new DeliveryDTO()
            {
                CartId = cartId,
                Cost   = deliveryCost
            };
            await _deliveryEFService.AddDeliveryAsync(_mapper.Map <DeliveryModel>(deliveryDTO));

            return(deliveryCost);
        }
Beispiel #3
0
 public async Task <ProductDTO> GetProductAsync(int productId)
 {
     return(_mapper.Map <ProductDTO>(await _productEFService.GetProductAsync(productId)));
 }