Ejemplo n.º 1
0
        /// <summary>
        /// Récupère et stock toutes les valeurs possibles d'échanges
        /// </summary>
        /// <returns></returns>
        public static bool storeAllCurrenciesPobisiblitiesInDB()
        {
            //Création du client pour les opérations de GET
            WebClient wb = new WebClient();
            List <ExchangeRateOffline> offlineRateList = new List <ExchangeRateOffline>();

            string responseForEUR = wb.DownloadString(API_RATE);
            string responseForUSD = wb.DownloadString(API_RATE + "?base=USD");
            string responseForGBP = wb.DownloadString(API_RATE + "?base=GBP");
            string responseForJPY = wb.DownloadString(API_RATE + "?base=JPY");
            string responseForCAD = wb.DownloadString(API_RATE + "?base=CAD");
            string responseForAUD = wb.DownloadString(API_RATE + "?base=AUD");
            string responseFORCNY = wb.DownloadString(API_RATE + "?base=CNY");


            List <string> allUrlsToGet = new List <string>()
            {
                responseForEUR, responseFORCNY, responseForCAD, responseForJPY,
                responseForUSD, responseForGBP, responseForAUD
            };

            foreach (var url in allUrlsToGet)
            {
                ExchangeRateOffline rate = JsonConvert.DeserializeObject <ExchangeRateOffline>(url);
                offlineRateList.Add(rate);
            }

            //Insertion en base de donnés
            bool isInserted = QueryDBHelper.InsertRatesInDB(offlineRateList);

            return(isInserted);
        }
Ejemplo n.º 2
0
 public ActionResult IsOffline(bool offline)
 {
     if (!offline)
     {
         return(RedirectToAction(Url.Action("Index")));
     }
     else
     {
         ViewData["CurrenciesList"] = QueryDBHelper.GetMostUsedForOfflineMode();
         return(View());
     }
 }
Ejemplo n.º 3
0
        public ActionResult Index()
        {
            //Récupération de la liste des devises dispo en base
            List <CurrencyModel> currenciesList = QueryDBHelper.getConverterModelFromDB();

            ViewData["CurrenciesList"] = currenciesList;

            //On vérifie si la table est vide, si oui on la remplit pour l'utilisation du mode offline

            if (QueryDBHelper.isExchangeEmpty())
            {
                //Pour l'utilisation du mode offline on ajoute en base les taux de changes des 7 monnaies les plus utilisées
                APIQuery.storeAllCurrenciesPobisiblitiesInDB();
            }
            return(View());
        }