Пример #1
0
        //public List<object> GetAllActive()
        //{
        //    List<object> result = new List<object>();
        //    var auctions = _repository.GetMany(a => a.StateID == 2)
        //        .Select(item => new
        //        {
        //            ID = item.ID,
        //            Deadline = item.Deadline
        //        });

        //    foreach (var item in auctions)
        //    {
        //        result.Add(item);
        //    }

        //    return result;
        //}

        public Dictionary <int, int> GetRecommendedPrice(int?priceUSD, int?priceUAH)
        {
            int    recommendedPriceUSD = 0;
            int    recommendedPriceUAH = 0;
            double currencyRate        = CurrencyService.GetCurrencyRate();

            if ((priceUSD != null || priceUAH != null) && currencyRate > 0)
            {
                int price_usd = (priceUSD != null) ? (int)priceUSD : (priceUAH != null) ? (int)priceUAH / (int)currencyRate : 0;

                try
                {
                    string tmp = $"{XCarsConfiguration.RecommendedPriceRates}"; //"0-2999|20;3000-4999|18;5000-9999|15;10000-14999|13;15000-19999|11;20000-0|10"
                    if (!string.IsNullOrWhiteSpace(tmp))
                    {
                        string[] priceRanges = tmp.Split(';');
                        if (priceRanges.Length > 0)
                        {
                            for (int i = 0; i < priceRanges.Length; i++)
                            {
                                string[] tmp2 = priceRanges[i].Split('|');

                                double rate = 0;
                                double.TryParse(tmp2[1], out rate);

                                tmp2 = tmp2[0].Split('-');

                                int downLimit = 0;
                                int.TryParse(tmp2[0], out downLimit);
                                int upLimit = 0;
                                int.TryParse(tmp2[1], out upLimit);

                                if (upLimit > 0 && price_usd >= downLimit && price_usd <= upLimit ||
                                    upLimit == 0 && price_usd > downLimit)
                                {
                                    double price_usdD = price_usd;
                                    recommendedPriceUSD = (int)(price_usdD * (100D - rate) / 100D);
                                    break;
                                }
                            }
                        }
                    }
                }
                catch
                { }
            }

            recommendedPriceUAH = (int)(recommendedPriceUSD * currencyRate);

            int ostatok = recommendedPriceUSD % 100;

            if (ostatok != 0)
            {
                recommendedPriceUSD = recommendedPriceUSD - ostatok + 100;
            }
            ostatok = recommendedPriceUAH % 100;
            if (ostatok != 0)
            {
                recommendedPriceUAH = recommendedPriceUAH - ostatok + 100;
            }

            return(new Dictionary <int, int>()
            {
                { 1, recommendedPriceUSD },
                { 2, recommendedPriceUAH }
            });
        }