public void UpdateCurrency()
        {
            try
            {
                var XmlDataList = new ParsingXML().DownloadRatesFile();
                var XmlDataListNational = new ParsingXML().getNationCurrency();
                if (XmlDataList == null)
                {
                    Log.AddLog("Second attempt");
                    XmlDataList = new ParsingXML().DownloadRatesFile();
                    if (XmlDataList == null)
                    {
                        Log.AddLog("Bad Second attempt");
                        return;
                    }
                }
                if (XmlDataListNational == null)
                {
                    Log.AddLog("Second attempt /2");
                    XmlDataListNational = new ParsingXML().getNationCurrency();
                    if (XmlDataListNational == null)
                    {
                        Log.AddLog("Bad Second attempt /2");
                        return;
                    }
                }

                DateTime date = Convert.ToDateTime(XmlDataList.First().RelevanceDate);

                decimal USD, EUR, UZS, USDNational, EURNational, RUBNational;

                USD = Convert.ToDecimal(XmlDataList.Find(x => x.IsoCode.Contains("USD")).ExchangeValue) / Convert.ToDecimal(XmlDataList.Find(x => x.IsoCode.Contains("USD")).Nominal);
                EUR = Convert.ToDecimal(XmlDataList.Find(x => x.IsoCode.Contains("EUR")).ExchangeValue) / Convert.ToDecimal(XmlDataList.Find(x => x.IsoCode.Contains("EUR")).Nominal);
                UZS = Convert.ToDecimal(XmlDataList.Find(x => x.IsoCode.Contains("UZS")).ExchangeValue) / Convert.ToDecimal(XmlDataList.Find(x => x.IsoCode.Contains("UZS")).Nominal);

                USDNational = Convert.ToDecimal(XmlDataListNational.Find(y => y.IsoCode.Contains("USD")).ExchangeValue);
                EURNational = Convert.ToDecimal(XmlDataListNational.Find(y => y.IsoCode.Contains("EUR")).ExchangeValue);
                RUBNational = Convert.ToDecimal(XmlDataListNational.Find(y => y.IsoCode.Contains("RUB")).ExchangeValue);

                if (FindAndDeactivateEntity(date))
                {
                    var newRateUSD = new sl_ExchangeRate()
                    {
                        sl_RelevanceDate = date,
                        sl_TransactionCurrencyId = ToTransactionCurrency("USD", decimal.One),
                        sl_ExchangeRate1 = decimal.One,
                        new_national_currency = decimal.One
                    };
                    service.Create(newRateUSD);
                    var newRateEUR = new sl_ExchangeRate()
                    {
                        sl_RelevanceDate = date,
                        sl_TransactionCurrencyId = ToTransactionCurrency("EUR", EUR / USD),
                        sl_ExchangeRate1 = EUR / USD,
                        new_national_currency = EURNational
                    };
                    service.Create(newRateEUR);
                    var newRateUZS = new sl_ExchangeRate()
                    {
                        sl_RelevanceDate = date,
                        sl_TransactionCurrencyId = ToTransactionCurrency("UZS", UZS / USD),
                        sl_ExchangeRate1 = UZS / USD,
                        new_national_currency = USDNational
                    };
                    service.Create(newRateUZS);
                    var newRateRUB = new sl_ExchangeRate()
                    {
                        sl_RelevanceDate = date,
                        sl_TransactionCurrencyId = ToTransactionCurrency("RUB", decimal.One / USD),
                        sl_ExchangeRate1 = decimal.One / USD,
                        new_national_currency = RUBNational
                    };
                    service.Create(newRateRUB);
                }
                else
                {
                    Log.AddLog("All Currency is correct");
                }
            }
            catch (Exception ex)
            {
                Log.AddLog(string.Format("Somethink is wrong in WorkClass: {0}", ex.Message));
            }
        }
Beispiel #2
0
        public void UpdateCurrency()
        {
            try
            {
                var XmlDataList         = new ParsingXML().DownloadRatesFile();
                var XmlDataListNational = new ParsingXML().getNationCurrency();
                if (XmlDataList == null)
                {
                    Log.AddLog("Second attempt");
                    XmlDataList = new ParsingXML().DownloadRatesFile();
                    if (XmlDataList == null)
                    {
                        Log.AddLog("Bad Second attempt");
                        return;
                    }
                }
                if (XmlDataListNational == null)
                {
                    Log.AddLog("Second attempt /2");
                    XmlDataListNational = new ParsingXML().getNationCurrency();
                    if (XmlDataListNational == null)
                    {
                        Log.AddLog("Bad Second attempt /2");
                        return;
                    }
                }


                DateTime date = Convert.ToDateTime(XmlDataList.First().RelevanceDate);

                decimal USD, EUR, UZS, USDNational, EURNational, RUBNational;

                USD = Convert.ToDecimal(XmlDataList.Find(x => x.IsoCode.Contains("USD")).ExchangeValue) / Convert.ToDecimal(XmlDataList.Find(x => x.IsoCode.Contains("USD")).Nominal);
                EUR = Convert.ToDecimal(XmlDataList.Find(x => x.IsoCode.Contains("EUR")).ExchangeValue) / Convert.ToDecimal(XmlDataList.Find(x => x.IsoCode.Contains("EUR")).Nominal);
                UZS = Convert.ToDecimal(XmlDataList.Find(x => x.IsoCode.Contains("UZS")).ExchangeValue) / Convert.ToDecimal(XmlDataList.Find(x => x.IsoCode.Contains("UZS")).Nominal);

                USDNational = Convert.ToDecimal(XmlDataListNational.Find(y => y.IsoCode.Contains("USD")).ExchangeValue);
                EURNational = Convert.ToDecimal(XmlDataListNational.Find(y => y.IsoCode.Contains("EUR")).ExchangeValue);
                RUBNational = Convert.ToDecimal(XmlDataListNational.Find(y => y.IsoCode.Contains("RUB")).ExchangeValue);

                if (FindAndDeactivateEntity(date))
                {
                    var newRateUSD = new sl_ExchangeRate()
                    {
                        sl_RelevanceDate         = date,
                        sl_TransactionCurrencyId = ToTransactionCurrency("USD", decimal.One),
                        sl_ExchangeRate1         = decimal.One,
                        new_national_currency    = USDNational
                    };
                    service.Create(newRateUSD);
                    var newRateEUR = new sl_ExchangeRate()
                    {
                        sl_RelevanceDate         = date,
                        sl_TransactionCurrencyId = ToTransactionCurrency("EUR", EUR / USD),
                        sl_ExchangeRate1         = EUR / USD,
                        new_national_currency    = EURNational
                    };
                    service.Create(newRateEUR);
                    var newRateUZS = new sl_ExchangeRate()
                    {
                        sl_RelevanceDate         = date,
                        sl_TransactionCurrencyId = ToTransactionCurrency("UZS", UZS / USD),
                        sl_ExchangeRate1         = UZS / USD,
                        new_national_currency    = decimal.One
                    };
                    service.Create(newRateUZS);
                    var newRateRUB = new sl_ExchangeRate()
                    {
                        sl_RelevanceDate         = date,
                        sl_TransactionCurrencyId = ToTransactionCurrency("RUB", decimal.One / USD),
                        sl_ExchangeRate1         = decimal.One / USD,
                        new_national_currency    = RUBNational
                    };
                    service.Create(newRateRUB);
                }
                else
                {
                    Log.AddLog("All Currency is correct");
                }
            }
            catch (Exception ex)
            {
                Log.AddLog(string.Format("Somethink is wrong in WorkClass: {0}", ex.Message));
            }
        }