private void Search() { if (string.IsNullOrWhiteSpace(SearchText)) { NiCovid19Model.Clear(); GetCountryListcases(); NiCovid19Model.Clear(); } else { var countrySearch = NiCovid19Model.Where(c => c.country.ToLower().StartsWith(SearchText.ToLower())).ToList(); NiCovid19Model.Clear(); foreach (var country in countrySearch) { NiCovid19Model.Add(country); } } }
private async void GetCountryListcases() { Device.BeginInvokeOnMainThread(() => { IsBusy = true; }); IRestResponse response = await _commonServices.GetCountries(); if (response.StatusCode == HttpStatusCode.OK) { var totalCae = JsonConvert.DeserializeObject <List <NinjaCovid19CountriesModel> >(response.Content); foreach (var data in totalCae) { double dcases = CommonUtils.ConvertToDouble(data.cases); var cases = dcases.ToString("N0", CultureInfo.InvariantCulture); double dtodayCases = CommonUtils.ConvertToDouble(data.todayCases); var todayCases = dtodayCases.ToString("N0", CultureInfo.InvariantCulture); double ddeaths = CommonUtils.ConvertToDouble(data.deaths); var deaths = ddeaths.ToString("N0", CultureInfo.InvariantCulture); double dtodayDeaths = CommonUtils.ConvertToDouble(data.todayDeaths); var todayDeaths = dtodayDeaths.ToString("N0", CultureInfo.InvariantCulture); double drecovered = CommonUtils.ConvertToDouble(data.recovered); var recovered = drecovered.ToString("N0", CultureInfo.InvariantCulture); double dactive = CommonUtils.ConvertToDouble(data.active); var active = dactive.ToString("N0", CultureInfo.InvariantCulture); double dcritical = CommonUtils.ConvertToDouble(data.critical); var critical = dcritical.ToString("N0", CultureInfo.InvariantCulture); double dcasesPerOneMillion = CommonUtils.ConvertToDouble(data.casesPerOneMillion); var casesPerOneMillion = dcasesPerOneMillion.ToString("N0", CultureInfo.InvariantCulture); DateTime start = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); Double db = Convert.ToDouble(data.updated); var CountryUpdatetime = start.AddMilliseconds(db).ToLocalTime(); var DateCurrent = CountryUpdatetime.ToString("dddd, dd MMMM yyyy HH:mm:ss"); // Recovered = data.recovered.ToString(); NiCovid19Model.Add(new NinjaCovid19CountriesModel() { countryInfo = data.countryInfo, country = data.country, cases = cases, todayCases = "+ " + todayCases + "", deaths = deaths, todayDeaths = "+ " + todayDeaths + "", recovered = recovered, active = active, critical = "+ " + critical + "", casesPerOneMillion = data.casesPerOneMillion, deathsPerOneMillion = data.deathsPerOneMillion, updated = DateCurrent, }); Device.BeginInvokeOnMainThread(() => { IsBusy = false; }); } } }