Example #1
0
        public IEnumerable <PointModel> Get(String username    = null,
                                            double?latitude    = null,
                                            double?longitude   = null,
                                            double?range       = null,
                                            long?from          = null,
                                            long?to            = null,
                                            String title       = null,
                                            String description = null)
        {
            var points = dbContext.Points.Where(p => true);

            if (username != null)
            {
                points = points.Where(p => username.Equals(p.AspNetUser.UserName));
            }
            if (!String.IsNullOrWhiteSpace(title))
            {
                points = points.Where(p => p.Title.Contains(title));
            }
            if (!String.IsNullOrWhiteSpace(description))
            {
                points = points.Where(p => p.Description.Contains(description));
            }
            if (from != null && to != null)
            {
                DateTime fromDate = TimeUtils.UnixTimeStampToDateTime(from.Value);
                DateTime toDate   = TimeUtils.UnixTimeStampToDateTime(to.Value);

                points = points.Where(p => p.Uploaded >= fromDate && p.Uploaded <= toDate);
            }
            if (latitude != null && longitude != null && range != null)
            {
                Position topLeft     = new Position();
                Position bottomRight = new Position();

                LocationUtils.BoundingBox(latitude.Value, longitude.Value, 1000 * range.Value,
                                          out topLeft, out bottomRight);

                Decimal bottomRightLatitude  = new Decimal(bottomRight.Latitude);
                Decimal topLeftLatitude      = new Decimal(topLeft.Latitude);
                Decimal topLeftLongitude     = new Decimal(topLeft.Longitude);
                Decimal bottomRightLongitude = new Decimal(bottomRight.Longitude);

                points = points.Where(p => p.Latitude > bottomRightLatitude &&
                                      p.Latitude <topLeftLatitude &&
                                                  p.Longitude> topLeftLongitude &&
                                      p.Longitude < bottomRightLongitude);
            }
            return(points.Take(200).ToList().Select(p =>
                                                    new PointModel
            {
                Title = p.Title,
                Description = p.Description,
                Latitude = p.Latitude,
                Longitude = p.Longitude,
                Uploaded = (long)p.Uploaded.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds,
                PointId = p.PointId,
                Username = p.AspNetUser.UserName
            }));
        }