public void GetAllCurrenciesAndUpdate() { //For each JSON call there will be transaction ID associated with it var restTransactionID = Guid.NewGuid().GetHashCode(); try { HttpRequestClient client = new HttpRequestClient(); var freshCurrencies = client.GetCurrencies(); tblCurrencyMarketView cur = null; List <tblCurrencyMarketView> curFreshList = new List <tblCurrencyMarketView>(); List <tblCurrencyRankChanged> ranksChanged = new List <tblCurrencyRankChanged>(); List <tblCurrencyView> newlyAdded = new List <tblCurrencyView>(); foreach (var item in freshCurrencies) { cur = new tblCurrencyMarketView() { ID = Guid.NewGuid(), CoinMarkCapID = item.Id, AvailableSupply = Utlity.ParseDecimal(item.AvailableSupply), LastUpdatedUTC = item.LastUpdated, MarketCapConvert = Utlity.ParseDecimal(item.MarketCapConvert), MarketCapUSD = Utlity.ParseDecimal(item.MarketCapUsd), Name = item.Name, PercentageChange1H = Utlity.ParseDouble(item.PercentChange1h), PercentageChange24H = Utlity.ParseDouble(item.PercentChange24h), PercentageChange7D = Utlity.ParseDouble(item.PercentChange7d), PriceBTC = Utlity.ParseDecimal(item.PriceBtc), PriceConvert = Utlity.ParseDecimal(item.PriceConvert), PriceUSD = Utlity.ParseDecimal(item.PriceUsd), Rank = Utlity.ParseInt(item.Rank), Symbol = item.Symbol, TotalSupply = Utlity.ParseDecimal(item.TotalSupply), Volume24hUSD = Utlity.ParseDecimal(item.Volume24hUsd), Volumne24HConvert = Utlity.ParseDecimal(item.Volume24Convert), TimeStamp = DateTime.Now, TransactionID = restTransactionID }; curFreshList.Add(cur); } //Add Fresh Currencies, which are going to be just 1 or 2 at a time var addRemovePairs = FindNewCurrencies(curFreshList, restTransactionID); if (addRemovePairs.Added != null && addRemovePairs.Added.Count > 0) { newlyAdded = BuildNewCurrencyList(curFreshList, addRemovePairs.Added, restTransactionID); CurrencyDataContext.InsertCurrencyViews(newlyAdded); } if (addRemovePairs.Removed != null && addRemovePairs.Removed.Count > 0) { CurrencyDataContext.UpdateCurrencyViewForDelete(addRemovePairs.Removed, restTransactionID); } //Get those currency views which need to be updated in DB (New ones) var updateCurView = GetCurrencyViewToUpdate(curFreshList, newlyAdded); //The update the old currency views and report rank change if (updateCurView != null && updateCurView.Count > 0) { ranksChanged = CurrencyDataContext.UpdateCurrencyViewAndCurrencyRankChanged(updateCurView, restTransactionID); } CurrencyDataContext.InsertCurrencyMarketView(curFreshList); CurrencyDataContext.InsertTransactionLog(restTransactionID); } catch (Exception ex) { CurrencyDataContext.InsertTransactionLog(restTransactionID, false); ErrorLogging.LogError(ex); } }