Beispiel #1
0
        public IEnumerable <Earthquake> Search(EarthquakeModel model)
        {
            try
            {
                var predicate = PredicateBuilder.True <Earthquake>();

                if (model.LocationModel.IsByCountry)
                {
                    predicate = GetLocationPredicate(predicate, model);
                    predicate = GetMagnitudePredicate(predicate, model);
                    predicate = GetDateTimePredicate(predicate, model);
                    return(this.DbContext.Set <Earthquake>()
                           .Include(e => e.Place)
                           .Include(e => e.MagnitudeType)
                           .Include(e => e.Source)
                           .AsExpandable().Where(predicate));
                }

                predicate = GetMagnitudePredicate(predicate, model);
                predicate = GetDateTimePredicate(predicate, model);

                return(model.LocationModel.NearEarthquakes
                       .AsQueryable().Where(predicate).ToList());
            }
            catch (Exception ex)
            {
                ExceptionUtility.Error(ex, this.GetType());
                return(new List <Earthquake>());
            }
        }
Beispiel #2
0
        public async Task <ICollection <EarthquakeModel> > GetPastDayAllAsync()
        {
            var httpClient = _httpClientFactory.CreateClient();

            var response = await httpClient.GetFromJsonAsync <GeoJsonResponse>("https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson");

            var result = new List <EarthquakeModel>();

            foreach (var item in response.Features)
            {
                EarthquakeModel earthquake = Map(item);
                result.Add(earthquake);
            }

            return(result);
        }
Beispiel #3
0
        public object GetData(string location, string latitude, string longitude, string magnitude, string date)
        {
            string data = string.Empty;

            try
            {
                EarthquakeModel model         = new EarthquakeModel();
                LocationModel   locationModel = GetLocationModel(location, latitude, longitude);

                model.LocationModel = locationModel;
                model.Magnitude     = GetMagnitude(magnitude);
                model.DateTime      = GetDate(date);

                var earthquakes = earthquakeRepository.Search(model);
                if (earthquakes.Count() > 0)
                {
                    data = FromObjectToGeoJSON(earthquakes);
                }
                else
                {
                    data = ExceptionUtility.NoElementsMessage;
                }

                object obj = new object();
                obj = data;
                return(obj);
            }

            catch (Exception ex)
            {
                ExceptionUtility.Warn(ex, this.GetType());
                data = ExceptionUtility.BadRequestMessage;
                //data[1] = ExceptionUtility.BadRequestMessage;
                return(data);
            }
        }
Beispiel #4
0
        private Expression <Func <Earthquake, bool> > GetLocationPredicate(Expression <Func <Earthquake, bool> > predicate, EarthquakeModel model)
        {
            try
            {
                /*decimal latitude = Convert.ToDecimal(model.LocationModel.Latitude);
                 * decimal longitude = Convert.ToDecimal(model.LocationModel.Longitude);
                 *
                 *
                 *  bool isfirstCountryParameter = true;
                 *  for (int i = 0; i < model.LocationModel.Country.Length; i++)
                 *  {
                 *      string country = model.LocationModel.Country[i].ToString();
                 *
                 *      if (country != CountryEnum.EMPTY.ToString())
                 *      {
                 *          if (isfirstCountryParameter)
                 *          {
                 *              //que de chile solo se muestre los sensibles
                 *              if (country == CountryEnum.CHILE.ToString())
                 *              {
                 *                  predicate = predicate.And(e => e.Place.Country.Contains(country) && e.IsSensible == true);
                 *              }
                 *              else if (country == CountryEnum.WORLD.ToString())
                 *              {
                 *                  predicate = predicate.And(e => e.Place.Country != string.Empty);
                 *              }
                 *              else
                 *              {
                 *                  predicate = predicate.And(e => e.Place.Country.Contains(country));
                 *              }
                 *              isfirstCountryParameter = false;
                 *          }
                 *          else
                 *          {
                 *              //que de chile solo se muestre los sensibles
                 *              if (country == CountryEnum.CHILE.ToString())
                 *              {
                 *                  predicate = predicate.Or(e => e.Place.Country.Contains(country) && e.IsSensible == true);
                 *              }
                 *              else if (country == CountryEnum.WORLD.ToString())
                 *              {
                 *                  predicate = predicate.Or(e => e.Place.Country != string.Empty);
                 *              }
                 *              else
                 *              {
                 *                  predicate = predicate.Or(e => e.Place.Country.Contains(country));
                 *              }
                 *          }
                 *      }
                 *  }*/

                return(predicate);
            }
            catch (Exception ex)
            {
                ExceptionUtility.Error(ex, this.GetType());
                return(predicate);
            }
        }
Beispiel #5
0
        private Expression <Func <Earthquake, bool> > GetMagnitudePredicate(Expression <Func <Earthquake, bool> > predicate, EarthquakeModel model)
        {
            try
            {
                if (model.Magnitude == "Sensible")
                {
                    predicate = predicate.And(e => e.IsSensible == true);
                }

                else
                {
                    decimal magnitude = Convert.ToDecimal(model.Magnitude, CultureInfo.InvariantCulture);
                    predicate = predicate.And(e => e.Magnitude >= magnitude);
                }

                return(predicate);
            }
            catch (Exception ex)
            {
                ExceptionUtility.Error(ex, this.GetType());
                return(predicate);
            }
        }
Beispiel #6
0
 private Expression <Func <Earthquake, bool> > GetDateTimePredicate(Expression <Func <Earthquake, bool> > predicate, EarthquakeModel model)
 {
     try
     {
         predicate = predicate.And(e => e.UTCDateTime >= model.DateTime);
         return(predicate);
     }
     catch (Exception ex)
     {
         ExceptionUtility.Warn(ex, this.GetType());
         return(predicate);
     }
 }