public void DistanceTest()
        {
            //63 hounslow heath road, Toronto, Canada
            var mock = new TorontoPartyAdvisor.Commands.Helpers.MathPosition(43.673351, -79.4592933);

            var sameTest = mock.Distance(mock);

            Assert.IsTrue(sameTest == 0);

            //rue Jean Schyns 44, La Louviere, Belgique
            var home = new TorontoPartyAdvisor.Commands.Helpers.MathPosition(50.4790720, 4.2203430);

            var res = mock.Distance(home);

            //There are more than 6000 km between Belgium and Canada
            Assert.IsTrue(res > 6000000);

            //test between google map pos and end of facade of the bar 244
            var pos1 = new TorontoPartyAdvisor.Commands.Helpers.MathPosition(43.648232, -79.388948);
            var pos2 = new TorontoPartyAdvisor.Commands.Helpers.MathPosition(43.6480779, -79.3888383);

            var res2 = pos1.Distance(pos2);

            var pixyPos = new TorontoPartyAdvisor.Commands.Helpers.MathPosition(43.6658029, -79.40538643);

            var distance = pixyPos.Distance(new TorontoPartyAdvisor.Commands.Helpers.MathPosition(43.65674, -79.407115));

            var test = distance;
        }
        public void Execute()
        {
            List<int> userIds = new List<int>();

            using (var db = new PartyAdvisorEntities())
            {
                var user = db.Users.SingleOrDefault(x => x.FacebookToken == Args.AccessToken);

                //request from an unauthentified user
                if(user == null)
                {
                    //TODO insert log here

                    ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                    logger.Warn(FormatHelper.FormatCommandToLog(this, Args));

                    Results = new List<SearchUserViewModel>();
                    return;
                }

                var place = db.Places.Find(Args.PlaceId);

                var placePosition = new TorontoPartyAdvisor.Commands.Helpers.MathPosition(place.Latitude, place.Longitude);

                //filter by time
                var userPositions = db.Positions.Where(x => DbFunctions.AddMinutes(x.Date, -(Args.Minutes)) > DateTimeOffset.Now).ToList();

                //filter by distance
                foreach(var userPosition in userPositions)
                {
                    var userMathPosition = new TorontoPartyAdvisor.Commands.Helpers.MathPosition(userPosition.Latitude, userPosition.Longitude);
                    if (placePosition.HasPositionInItsRadius(userMathPosition, place.RadiusMeters))
                    {
                        if (!userIds.Contains(userPosition.UserId))
                        {
                            userIds.Add(userPosition.UserId);
                        }
                    }
                }

                //we get the list of id of users at the place, now we get more infos

                var res = (from x in userIds
                           join y in db.Users on x equals y.Id
                           select new SearchUserViewModel()
                           {
                               Id = y.Id,
                               Gender = y.Gender
                           }).ToList();

                Results = res;
                return;
            }
        }
        public void HasPositionInItsRadiusTest()
        {
            //63 hounslow heath road, Toronto, Canada
            var mock = new TorontoPartyAdvisor.Commands.Helpers.MathPosition(43.673351, -79.4592933);

            //rue Jean Schyns 44, La Louviere, Belgique
            var home = new TorontoPartyAdvisor.Commands.Helpers.MathPosition(50.4790720, 4.2203430);

            var res = mock.HasPositionInItsRadius(home, 7000000);

            Assert.IsTrue(res);
        }
 public bool HasPositionInItsRadius(MathPosition obj, int radiusMeters)
 {
     return this.Distance(obj) <= radiusMeters;
 }
 public double Distance(MathPosition obj)
 {
     return Distance(obj.Latitude, obj.Longitude);
 }