Exemple #1
0
        public static DbGeography getCircle(Models.Coordinates coords, double km)
        {
            string      textPoint    = String.Format("POINT ({0} {1})", coords.Lng, coords.Lat);
            DbGeography point        = DbGeography.PointFromText(textPoint, DbGeography.DefaultCoordinateSystemId); //4326 = [WGS84]
            DbGeography targetCircle = point.Buffer(km);

            return(targetCircle);
        }
        public void Issue570_DbGeo_HasValues()
        {
            EntityFramework.Handlers.Register();
            const string redmond = "POINT (122.1215 47.6740)";
            DbGeography  point   = DbGeography.PointFromText(redmond, DbGeography.DefaultCoordinateSystemId);
            DbGeography  orig    = point.Buffer(20);

            var fromDb = connection.QuerySingle <DbGeography>("declare @geos table(geo geography); insert @geos(geo) values(@val); select * from @geos",
                                                              new { val = orig });

            fromDb.Area.IsNotNull();
            fromDb.Area.IsEqualTo(orig.Area);
        }
Exemple #3
0
        public List <object> GetClusteredHelpers(SearchParams searchParams)
        {
            string path = System.Web.Hosting.HostingEnvironment.MapPath("~/Files/ProfileImages/");
            IQueryable <HelperLocation> h      = null;
            DbGeography           targetCircle = null;
            List <HelperLocation> LoactionList = new List <HelperLocation>();

            if (searchParams != null)
            {
                if (searchParams.Latitude > 0 && searchParams.Longitude > 0 && searchParams.Radius >= 0)
                {
                    DbGeography center = DbGeography.FromText("Point(" + searchParams.Latitude + " " + searchParams.Longitude + ")");
                    targetCircle = center.Buffer(searchParams.Radius);

                    h = helpaContext.HelperLocations
                        .IncludeEntities(x => x.Helper, x => x.Location, x => x.Helper.HelperServices).Include(x => x.Helper.HelperServices.Select(q => q.Service)).Include(q => q.Helper.HelperServices.Select(x => x.HelperServiceScopes.Select(l => l.Scope)));
                    var io = helpaContext.HelperLocations.Where(x => x.Location.LocationGeography.Latitude.ToString().Contains(targetCircle.Latitude.ToString()) && x.Location.LocationGeography.Longitude.ToString().Contains(targetCircle.Longitude.ToString())).ToList();
                    if (searchParams.ServiceId > 0)
                    {
                        h = h.Where(x => x.Helper.HelperServices.Any(m => m.ServiceId == searchParams.ServiceId));
                    }
                    if (searchParams.LocationTypeId > 0)
                    {
                        h = h.Where(x => x.Helper.LocationType == searchParams.LocationTypeId);
                    }
                    if (searchParams.ScopeId > 0)
                    {
                        h = h.Where(x => x.Helper.HelperServices.Any(m => m.HelperServiceScopes.Any(n => n.HelperScopeId == searchParams.ScopeId)));
                    }
                }
            }

            else
            {
                h = helpaContext.HelperLocations
                    .IncludeEntities(x => x.Helper, x => x.Location, x => x.Helper.HelperServices.Select(y => y.Service));
                var t = h.ToList();

                if (searchParams != null)
                {
                    if (searchParams.ServiceId > 0)
                    {
                        h = h.Where(x => x.Helper.HelperServices.Select(q => q.ServiceId).FirstOrDefault() == searchParams.ServiceId);
                    }

                    if (searchParams.LocationTypeId > 0)
                    {
                        h = h.Where(x => x.Helper.LocationType == searchParams.LocationTypeId);
                    }

                    if (searchParams.ScopeId > 0)
                    {
                        h = h.Where(x => x.Helper.HelperServices.Any(m => m.HelperServiceScopes.Any(n => n.HelperScopeId == searchParams.ScopeId)));
                    }
                }
            }

            var pl = h.ToList();

            foreach (var item in pl)
            {
                var lat         = Convert.ToDouble(item.Location.LocationGeography.Latitude);
                var Longi       = Convert.ToDouble(item.Location.LocationGeography.Longitude);
                var SearchLat   = Convert.ToDouble(searchParams.Latitude);
                var SearchLongi = Convert.ToDouble(searchParams.Longitude);
                var sCoord      = new GeoCoordinate(SearchLat, SearchLongi);
                var eCoord      = new GeoCoordinate(lat, Longi);

                var DistanceRadius = sCoord.GetDistanceTo(eCoord);

                if (DistanceRadius <= searchParams.Radius)
                {
                    LoactionList.Add(item);
                }
            }
            var            r       = helpaContext.AspNetUsers.Where(x => x.AspNetRoles.Select(y => y.Name).Contains("HELPER") && x.RowStatus == true).ToList();
            var            final   = LoactionList.Join(r, x => x.Helper.UserId, y => y.Id, (x, y) => new { q = x, w = y }).ToList();
            List <object>  data    = new List <object>();
            HelpersHomeDTO helpers = new HelpersHomeDTO();

            foreach (var item in final)
            {
                var w = item.w;
                var q = item.q;

                helpers = new HelpersHomeDTO();
                helpers.LocalityName = item.q.Location.Locality;
                string location   = item.q.Location.LocationGeography.StartPoint.ToString();
                int    startIndex = location.IndexOf("(");
                int    endIndex   = location.IndexOf(")");
                var    LatLong    = location.Substring(startIndex + 1, endIndex - startIndex - 1).Split(null);
                helpers.Latitude  = Math.Round(Convert.ToDouble(LatLong[1]), 8).ToString();
                helpers.Longitude = Math.Round(Convert.ToDouble(LatLong[0]), 8).ToString();
                var EMPLOYEE = helpaContext.AspNetUsers.Where(x => x.LocationId == item.q.LocationId).ToList();
                helpers.NumberOfHelpersInLocality = final.Count();
                List <HelpersInLocalty> Obj = new List <HelpersInLocalty>();
                foreach (var v in final)
                {
                    HelpersInLocalty ob = new HelpersInLocalty();
                    ob.UserId         = v.w.Id;
                    ob.Name           = v.w.UserName;
                    ob.ProfilePicture = path + v.w.ProfileImage;
                    ob.Description    = v.w.Description;
                    ob.AverageRating  = v.w.AverageRating.ToString();
                    ob.RatingCount    = v.w.AverageRating.ToString();
                    ob.Status         = v.w.RowStatus.ToString();
                    ob.Latitude       = helpaContext.Locations.Where(x => x.LocationId == v.w.LocationId).Select(x => x.LocationGeography.Latitude).FirstOrDefault();
                    ob.Longitude      = helpaContext.Locations.Where(x => x.LocationId == v.w.LocationId).Select(x => x.LocationGeography.Longitude).FirstOrDefault();

                    Obj.Add(ob);
                }
                helpers.HelpersInLocalties = Obj;
                data.Add(helpers);
                break;
            }

            if (data.Count > 0)
            {
                return(data);
            }
            return(null);
        }