Пример #1
0
 private static int GetSpecialsQuantity(CalculateTrolleyTotalCommand.RequestTrolley.TrolleyProductQuantity productQuantity, CalculateTrolleyTotalCommand.RequestTrolley.TrolleySpecial sps)
 {
     try
     {
         return(sps.Quantities.FirstOrDefault(x => x.Name == productQuantity.Name).Quantity);
     }
     catch
     {
         return(0);
     }
 }
Пример #2
0
        private static decimal GetSpecialsPrice(CalculateTrolleyTotalCommand.RequestTrolley request,
                                                CalculateTrolleyTotalCommand.RequestTrolley.TrolleyProductQuantity productQuantity, decimal priceWithoutSpecials)
        {
            var productPrice = priceWithoutSpecials;

            try
            {
                var sps = FindApplicableSpecial(request, productQuantity);

                if (SpecialsIncorrectlySetup(sps))
                {
                    return(productPrice);
                }

                var specialSetQuantity = GetSpecialsQuantity(productQuantity, sps);

                if (SpecialQuantityInvalid(specialSetQuantity))
                {
                    return(productPrice);
                }

                var productsOverFlowingSpecial = productQuantity.Quantity % specialSetQuantity;

                var productSpecialPrice = (productQuantity.Quantity / specialSetQuantity) * sps.Total;

                var productOverFlowPrice = productsOverFlowingSpecial *
                                           request.Products.OrderBy(x => x.Price).FirstOrDefault().Price;

                productPrice = productOverFlowPrice + productSpecialPrice;

                return(productPrice);
            }
            catch
            {
                return(priceWithoutSpecials);
            }
        }
Пример #3
0
 private static decimal GerMarkedPrice(CalculateTrolleyTotalCommand.RequestTrolley request, CalculateTrolleyTotalCommand.RequestTrolley.TrolleyProductQuantity productQuantity)
 {
     return(productQuantity.Quantity * request.Products.OrderBy(x => x.Price).FirstOrDefault().Price);
 }
Пример #4
0
 private static CalculateTrolleyTotalCommand.RequestTrolley.TrolleySpecial FindApplicableSpecial(CalculateTrolleyTotalCommand.RequestTrolley request, CalculateTrolleyTotalCommand.RequestTrolley.TrolleyProductQuantity productQuantity)
 {
     try
     {
         return(request.Specials.Where(x => x.Quantities.Any(q => q.Name == productQuantity.Name)).OrderByDescending(x => x.Total).FirstOrDefault());
     }
     catch (Exception e)
     {
         return(null);
     }
 }