Example #1
0
        private string GetLocationId(string location)
        {
            string locationId  = null;
            var    citiesFound = _citiesRepository.Get(location);

            if (!citiesFound.Any())
            {
                Console.WriteLine("The city is not found.");
            }

            if (citiesFound.Count() > 1)
            {
                foreach (var city in citiesFound)
                {
                    Console.WriteLine($"ID: {city.Id} \n City: {city.Name} \n Country: {city.Country} \n Coordinates: \n longitude: {city.Lon}, \n latitude: {city.Lat} \n");
                }

                Console.WriteLine("Please select your city and print its ID:");
                var userInput = "default";
                while (!citiesFound.Any(c => c.Id.ToString() == userInput))
                {
                    userInput = Console.ReadLine();

                    if (citiesFound.Any(c => c.Id.ToString() == userInput))
                    {
                        locationId = userInput;
                    }
                    else
                    {
                        Console.WriteLine("Incorrect city ID, please try again");
                    }
                }
            }

            else
            {
                locationId = citiesFound.First().Id.ToString();
            }

            return(locationId);
        }
Example #2
0
 public Cities GetCitiesByName(string citiesName)
 {
     return(_citiesRepository.Get(
                x => x.Name.Equals(citiesName),
                x => x.Streets));
 }
Example #3
0
        public object GetAll()
        {
            var queryValues = Request.RequestUri.ParseQueryString();

            int page  = Convert.ToInt32(queryValues["page"]);
            int start = Convert.ToInt32(queryValues["start"]);
            int limit = Convert.ToInt32(queryValues["limit"]);
            int id    = Convert.ToInt32(queryValues["id"]);
            int orden = Convert.ToInt32(queryValues["orden"]);

            string strFieldFilters = queryValues["fieldFilters"];

            FieldFilters fieldFilters = new FieldFilters();

            if (!String.IsNullOrEmpty(strFieldFilters))
            {
                fieldFilters = JsonConvert.DeserializeObject <FieldFilters>(strFieldFilters);
            }


            #region Configuramos el orden de la consulta si se obtuvo como parametro
            string strOrder = !string.IsNullOrWhiteSpace(queryValues["sort"]) ? queryValues["sort"] : "";
            strOrder = strOrder.Replace('[', ' ');
            strOrder = strOrder.Replace(']', ' ');

            Sort sort;

            if (!string.IsNullOrWhiteSpace(strOrder))
            {
                sort = JsonConvert.DeserializeObject <Sort>(strOrder);
            }
            else
            {
                sort = new Sort();
            }
            #endregion

            string query = !string.IsNullOrWhiteSpace(queryValues["query"]) ? queryValues["query"] : "";

            int totalRecords = 0;

            try
            {
                if (id == 0)
                {
                    object       json;
                    IList <City> lista;

                    lista = repository.GetList(fieldFilters, query, sort, page, start, limit, ref totalRecords);

                    json = new
                    {
                        total   = totalRecords,
                        data    = lista,
                        success = true
                    };

                    return(json);
                }
                else
                {
                    City estatus = repository.Get(id);

                    object json = new
                    {
                        data    = estatus,
                        success = true
                    };

                    return(json);
                }
            }
            catch (Exception ex)
            {
                LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message);

                object json = new
                {
                    message = ex.Message,
                    success = false
                };

                return(json);
            }
        }