コード例 #1
0
ファイル: DBHandler.cs プロジェクト: jabr212/Catchem-PoGo
 public static IEnumerable <GeoLatLonAlt> GetAltitudeForCoords(double lat, double lng, double distance)
 {
     distance = distance / 1000;
     using (var db = new BotContext())
     {
         return
             (db.MapzenAlt.Where(
                  x =>
                  12742 *
                  SqlCeFunctions.Asin(
                      SqlCeFunctions.SquareRoot(SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lat - lat) / 2) *
                                                SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 *
                                                                   (x.Lat - lat) / 2) +
                                                SqlCeFunctions.Cos(SqlCeFunctions.Pi() / 180 * lat) *
                                                SqlCeFunctions.Cos(SqlCeFunctions.Pi() / 180 * x.Lat) *
                                                SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lon - lng) / 2) *
                                                SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lon - lng) / 2))) <
                  distance).OrderBy(x =>
                                    12742 *
                                    SqlCeFunctions.Asin(
                                        SqlCeFunctions.SquareRoot(SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lat - lat) / 2) *
                                                                  SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 *
                                                                                     (x.Lat - lat) / 2) +
                                                                  SqlCeFunctions.Cos(SqlCeFunctions.Pi() / 180 * lat) *
                                                                  SqlCeFunctions.Cos(SqlCeFunctions.Pi() / 180 * x.Lat) *
                                                                  SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lon - lng) / 2) *
                                                                  SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lon - lng) / 2)))).ToList());
     }
 }
コード例 #2
0
ファイル: DBHandler.cs プロジェクト: jabr212/Catchem-PoGo
 public static bool ElevationDataExists(double lat, double lng, double distance)
 {
     distance = distance / 1000;
     using (var db = new BotContext())
     {
         var res = false;
         try
         {
             res =
                 db.MapzenAlt.Any(
                     x =>
                     12742 *
                     SqlCeFunctions.Asin(
                         SqlCeFunctions.SquareRoot(
                             SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lat - lat) / 2) *
                             SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 *
                                                (x.Lat - lat) / 2) +
                             SqlCeFunctions.Cos(SqlCeFunctions.Pi() / 180 * lat) *
                             SqlCeFunctions.Cos(SqlCeFunctions.Pi() / 180 * x.Lat) *
                             SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lon - lng) / 2) *
                             SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Lon - lng) / 2))) <
                     distance);
         }
         catch (Exception)
         {
             //ignore
         }
         return(res);
     }
 }
コード例 #3
0
 public void SqlCeFunction_passing_function_as_argument_to_another_works()
 {
     using (var context = GetArubaCeContext())
     {
         var query = context.AllTypes.Select(a => SqlCeFunctions.Asin(SqlCeFunctions.Acos(a.c10_float)));
         Assert.Contains("ASIN", query.ToString().ToUpperInvariant());
         Assert.Contains("ACOS", query.ToString().ToUpperInvariant());
     }
 }
コード例 #4
0
 public void SqlCeFunctions_scalar_function_translated_properly_to_sql_function()
 {
     using (var context = GetArubaCeContext())
     {
         var query1 = context.AllTypes.Select(a => SqlCeFunctions.Acos(a.c7_decimal_28_4));
         var query2 = context.AllTypes.Select(a => SqlCeFunctions.Acos(a.c10_float));
         Assert.Contains("ACOS", query1.ToString().ToUpperInvariant());
         Assert.Contains("ACOS", query2.ToString().ToUpperInvariant());
     }
 }
コード例 #5
0
ファイル: DBHandler.cs プロジェクト: jabr212/Catchem-PoGo
 public static IEnumerable <PokemonSeen> GetPokemonSeenForCoords(double lat, double lng, double distance)
 {
     distance = distance / 1000;
     using (var db = new BotContext())
     {
         return
             (db.PokemonSeen.Where(
                  x =>
                  12742 *
                  SqlCeFunctions.Asin(
                      SqlCeFunctions.SquareRoot(SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Latitude - lat) / 2) *
                                                SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 *
                                                                   (x.Latitude - lat) / 2) +
                                                SqlCeFunctions.Cos(SqlCeFunctions.Pi() / 180 * lat) *
                                                SqlCeFunctions.Cos(SqlCeFunctions.Pi() / 180 * x.Latitude) *
                                                SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Longitude - lng) / 2) *
                                                SqlCeFunctions.Sin(SqlCeFunctions.Pi() / 180 * (x.Longitude - lng) / 2))) <
                  distance).ToList());
     }
 }
コード例 #6
0
        public ActionResult Index(
            string date = null, string slug = null)
        {
            DateTime selectedDate;

            if (string.IsNullOrEmpty(date) || !DateTime.TryParse(date, out selectedDate))
            {
                selectedDate = DateTime.Today;
            }
            ViewBag.SelectedDate = selectedDate;
            ViewBag.Category     = string.IsNullOrEmpty(slug)
                ? null
                : Db.EventCategories.FirstOrDefault(x => x.Slug.Equals(slug, StringComparison.OrdinalIgnoreCase));
            return(View(Db.Events.Include(x => x.Category).Where(x => (slug == null || x.Category.Slug.Equals(slug, StringComparison.OrdinalIgnoreCase)) && x.IsActive && SqlCeFunctions.DateDiff("DAY", x.EventDate, selectedDate) == 0).OrderBy(x => x.EventDate).ToList()));
        }