public async System.Threading.Tasks.Task <FriendResult> GetFriendsClosestAsync(int friendId) { var friendsList = new List <Friend>(await _friendRepository.List()); var selected = friendsList.Find(x => x.Id == friendId); if (selected == null) { return(null); } var distancelist = new List <FriendDistance>(); foreach (var friend in friendsList) { if (friend.Id != friendId) { var friendDistance = new FriendDistance(); friendDistance.Id = friend.Id; friendDistance.Name = friend.Name; friendDistance.CityName = friend.CityName; friendDistance.Lat = friend.Lat; friendDistance.Lon = friend.Lon; var distance = HaversineDistance(selected.Lat, selected.Lon, friend.Lat, friend.Lon); var distanceFlat = GetFlatDistance(selected.Lat, selected.Lon, friend.Lat, friend.Lon); friendDistance.Distance = distance; friendDistance.DistanceFlat = distanceFlat; distancelist.Add(friendDistance); await _calculoHistoricoLogRepository.Insert( new CreateCalculoHistoricoLogCommand(DateTime.Now, Global.loggerUser.login, selected.Name, selected.Lat, selected.Lon, friend.Name, friend.Lat, friend.Lon, distance)); } } FriendResult result = new FriendResult(); result.Friend = selected; result.Friends = distancelist.OrderBy(i => i.Distance).Take(3).ToList(); return(result); }
public async Task <ICommandResult> HandleAsync(CreateCalculoHistoricoLogCommand command) { var result = await _calculoHistoricoLogRepository.Insert(new { @dataCalculo = command.dataCalculo, @usuarioToken = command.usuarioToken, @nomeAmigoSelecionado = command.nomeAmigoSelecionado, @latAmigoSelecionado = command.latAmigoSelecionado, @lonAmigoSelecionado = command.lonAmigoSelecionado, @nomeAmigoLocalizado = command.nomeAmigoLocalizado, @latAmigoLocalizado = command.latAmigoLocalizado, @lonAmigoLocalizado = command.lonAmigoLocalizado, @distancia = command.distancia }); return(new CreateGenericCommandResult(true, (int)result)); }