Exemplo n.º 1
0
        public async Task <string> GetPlatformActualAndSaveorUpdate(PlatformWellActual platformWellActual, Bearer bearer)
        {
            string          message      = string.Empty;
            List <Platform> platformList = new List <Platform>();

            string PlatformWellActualURL = platformWellActual.Url; //ConfigurationManager.AppSetting["PlatformWellActualAPI:URL"];

            using (var httpClient = new HttpClient())
            {
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", bearer.token);

                using (var response = await httpClient.GetAsync(PlatformWellActualURL))
                {
                    string apiResponse = await response.Content.ReadAsStringAsync();

                    try
                    {
                        platformList = JsonConvert.DeserializeObject <List <Platform> >(apiResponse);
                        DALUtility.InsertOrUpdatePlatformWellData(platformList);
                        message = "Data saved and loaded successfully.";
                        return(message);
                    }
                    catch (Exception ex)
                    {
                        message = "API return different set of data for example some key are missing or new key is added. " + ex.Message.ToString().Replace("'", "");
                        return(message);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> SaveAPIDataAndLoad(PlatformWellActual platformWellActual)
        {
            if (!platformWellActual.Url.Equals(string.Empty))
            {
                string message = await platformWellUtilityBL.GetPlatformActualAndSaveorUpdate(platformWellActual, bearer);

                if (!message.Equals(string.Empty))
                {
                    ViewBag.Message = message;
                }
            }

            var platformWellList = platformWellUtilityBL.GetPlatformWellList();

            return(View("Index", platformWellList));
        }