Esempio n. 1
0
 public async Task <int> Save(MyFriendPosition myFriendPosition)
 {
     if (myFriendPosition.MyFriendPositionId > 0)
     {
         _context.Update(myFriendPosition);
         return(await _context.SaveChangesAsync());
     }
     else
     {
         _context.Add(myFriendPosition);
         return(await _context.SaveChangesAsync());
     }
 }
Esempio n. 2
0
        private List <MyFriendPosition> CalcTop3FriendsNearMyCurrentPosition(List <MyFriendPosition> myFriendsPositions, MyFriendPosition myVisitedFriendPosition)
        {
            List <MyFriendPosition> myFriendPositionsFinalResult = new List <MyFriendPosition>();

            myFriendPositionsFinalResult.Add(myVisitedFriendPosition);
            foreach (var myFriendPosition in myFriendsPositions)
            {
                if (myFriendPosition == myVisitedFriendPosition)
                {
                    continue;
                }
                var aElevated2 = Math.Pow((myVisitedFriendPosition.Latitude - myFriendPosition.Latitude), 2);
                var bElevated2 = Math.Pow((myVisitedFriendPosition.Longitude - myFriendPosition.Longitude), 2);
                var sqrtA2B2   = Math.Sqrt(aElevated2 + bElevated2);
                myFriendPosition.Calc = sqrtA2B2;
                myFriendPositionsFinalResult.Add(myFriendPosition);
            }
            var friendNearMeOrderedByDistance = myFriendPositionsFinalResult.OrderBy(mfpKeyValue => mfpKeyValue.Calc).Take(3).ToList();

            return(friendNearMeOrderedByDistance);
        }