public CountriesDto GetStatistics(string country)
        {
            CountriesDto countryDtos = new CountriesDto();

            var url      = $"{_baseUrl}/statistics?country={country}";
            var response = _restClient.Get <Task>(url, _headers);

            JObject content         = JObject.Parse(response.Content);
            var     countryResponse = content.SelectToken("response");

            if (countryResponse.HasValues)
            {
                countryDtos.Continent = countryResponse[0].SelectToken("continent").ToString();
                countryDtos.Country   = countryResponse[0].SelectToken("country").ToString();
                countryDtos.New       = new CommonDataDto
                {
                    Total = countryResponse[0].SelectToken("cases").SelectToken("new").Type != JTokenType.Null ?
                            (int)countryResponse[0].SelectToken("cases").SelectToken("new") : 0,
                    Percent = countryResponse[0].SelectToken("cases").SelectToken("new").Type != JTokenType.Null ?
                              (decimal)countryResponse[0].SelectToken("cases").SelectToken("new") / (decimal)countryResponse[0].SelectToken("cases").SelectToken("total") : 0
                };
                countryDtos.Active = new CommonDataDto
                {
                    Total = countryResponse[0].SelectToken("cases").SelectToken("active").Type != JTokenType.Null ?
                            (int)countryResponse[0].SelectToken("cases").SelectToken("active") : 0,
                    Percent = countryResponse[0].SelectToken("cases").SelectToken("active").Type != JTokenType.Null ?
                              (decimal)countryResponse[0].SelectToken("cases").SelectToken("active") / (decimal)countryResponse[0].SelectToken("cases").SelectToken("total") : 0
                };
                countryDtos.Deaths = new CommonDataDto
                {
                    Total = countryResponse[0].SelectToken("deaths").SelectToken("new").Type != JTokenType.Null ?
                            (int)countryResponse[0].SelectToken("deaths").SelectToken("new") : 0,
                    Percent = countryResponse[0].SelectToken("deaths").SelectToken("new").Type != JTokenType.Null ?
                              (decimal)countryResponse[0].SelectToken("deaths").SelectToken("new") / (decimal)countryResponse[0].SelectToken("cases").SelectToken("total") : 0
                };
            }

            return(countryDtos);
        }
Exemplo n.º 2
0
        public IActionResult GetCountryById(int countryId)

        {
            var country = _countriesRepository.GetCountry(countryId);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                if (!_countriesRepository.CountryExist(countryId))
                {
                    return(NotFound($"the country with the countryId {countryId} could not be found"));
                }
                //if (country == null)
                //{
                //    return NotFound($"the country with the countryId {countryId} could not be found");
                //}
            }


            catch (Exception ex)
            {
                _logger.LogError("an error occured in GetCountryById", ex);

                return(StatusCode(500));
            }
            var countrydto = new CountriesDto()
            {
                Id   = country.Id,
                Name = country.Name
            };

            return(Ok(countrydto));
        }
Exemplo n.º 3
0
        public Exist_UsersDto consultarUsuario(long user_id)
        {
            Exist_UsersDto usuario = new Exist_UsersDto();

            try
            {
                Exist_UsersDtoCollection usuarios = new Exist_UsersDtoCollection();

                string sql = "SELECT *FROM exist_users";
                if (user_id != 0)
                {
                    sql = sql + " WHERE user_id='" + user_id + "'";
                }
                DataTable tabela = conexao.ExecutarConsulta(CommandType.Text, sql);
                foreach (DataRow item in tabela.Rows)
                {
                    usuario.user_email   = item["user_email"].ToString();
                    usuario.user_company = item["user_company"].ToString();
                    usuario.user_name    = item["user_name"].ToString();
                    usuario.user_phone   = item["user_phone"].ToString();
                    exist_languages exist_languages  = new exist_languages();
                    long            lang_id          = Convert.ToInt64(item["lang_id"]);
                    var             lang_collections = exist_languages.Consultar(lang_id);
                    if (lang_collections.Count > 0)
                    {
                        usuario.lang_id = lang_collections[0];
                    }
                    if (item["user_date_expire"] != DBNull.Value)
                    {
                        usuario.user_date_expire = Convert.ToDateTime(item["user_date_expire"]);
                    }
                    if (item["user_date_register"] != DBNull.Value)
                    {
                        usuario.user_date_register = Convert.ToDateTime(item["user_date_register"]);
                    }
                    if (item["date_answer"] != DBNull.Value)
                    {
                        usuario.date_answer = Convert.ToDateTime(item["date_answer"]);
                    }
                    if (item["treatment"] != DBNull.Value)
                    {
                        usuario.treatment = item["treatment"].ToString();
                    }
                    usuario.currency_id = Convert.ToInt64(item["currency_id"]);
                    usuario.base_calc   = Convert.ToInt32(item["base_calc"]);
                    usuario.specie_id   = Convert.ToInt64(item["specie_id"]);
                    usuario.dose        = Convert.ToInt64(item["dose"]);

                    usuario.user_blocked  = Convert.ToBoolean(item["user_blocked"]);
                    usuario.user_id       = Convert.ToInt64(item["user_id"]);
                    usuario.user_password = item["user_password"].ToString();
                    usuario.user_country  = Convert.ToInt64(item["user_country"]);
                    CountriesDto countries = new CountriesDto()
                    {
                        country_id = Convert.ToInt64(item["user_country"])
                    };
                    usuario.user_admin = Convert.ToBoolean(item["user_admin"]);

                    if (item["comments"] != DBNull.Value)
                    {
                        usuario.comments = item["comments"].ToString();
                    }
                    if (item["user_accesslevel"] != DBNull.Value)
                    {
                        usuario.user_accesslevel = Convert.ToInt32(item["user_accesslevel"]);
                    }
                    if (item["lang_id"] != DBNull.Value)
                    {
                        usuario.lang_id.lang_id = Convert.ToInt64(item["lang_id"]);
                    }
                    if (item["table_id"] != DBNull.Value)
                    {
                        usuario.table_id = Convert.ToInt64(item["table_id"]);
                    }
                    if (item["measure_config_id"] != DBNull.Value)
                    {
                        usuario.measure_config_id = Convert.ToInt64(item["measure_config_id"]);
                    }
                    if (item["system_id"] != DBNull.Value)
                    {
                        usuario.system_id = Convert.ToInt64(item["system_id"]);
                    }
                    if (item["action"] != DBNull.Value)
                    {
                        usuario._action = Convert.ToInt32(item["action"]);
                    }
                    if (item["last_name"] != DBNull.Value)
                    {
                        usuario.last_name = item["last_name"].ToString();
                    }
                    return(usuario);
                }
                return(null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }