Esempio n. 1
0
 public IActionResult GetAllFriends(string user)
 {
     try
     {
         AllFriends all = _repo.GetAllFriends(user);
         if (all.friends == null)
         {
             return(BadRequest(new AppErrorResponse {
                 status = "failure", reason = "User does not exist"
             }));
         }
         else if (all.friends.Count() == 0)
         {
             return(NotFound(new AppErrorResponse {
                 status = "failure", reason = "User does not have any friends"
             }));
         }
         else
         {
             all.friends = all.friends.Distinct().ToList();
             return(Ok(all));
         }
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, ex.Message, ex.InnerException);
         return(BadRequest(new AppErrorResponse()));
     }
 }
Esempio n. 2
0
        public FriendSuggestion GetFriendSuggestions(string user)
        {
            FriendSuggestion suggestion = new FriendSuggestion();

            suggestion.suggestions = new List <string>();
            AllFriends all = GetAllFriends(user);

            if (all.friends == null)
            {
                suggestion.suggestions = null;
                return(suggestion);
            }
            foreach (var friend1 in all.friends)
            {
                var l1 = GetAllFriends(friend1);
                l1.friends.Remove(user);
                if (l1.friends.Count > 0)
                {
                    suggestion.suggestions.AddRange(l1.friends.Except(all.friends));
                    foreach (var friend2 in l1.friends)
                    {
                        var l2 = GetAllFriends(friend2);
                        l2.friends.Remove(user);
                        if (l2.friends.Count > 0)
                        {
                            suggestion.suggestions.AddRange(l2.friends.Except(all.friends));
                        }
                    }
                }
            }
            return(suggestion);
        }
Esempio n. 3
0
 private void DeleteFriend(Friend friend)
 {
     if (DialogService.Confirm("Really want to delete this friend?"))
     {
         AllFriends.Remove(friend);
         DataProvider.Delete(friend);
         DialogService.ShowMessage("Delete friend successfully");
     }
 }
Esempio n. 4
0
 private void ECTorpedoAttack(sortie_battle.torpedo api)
 {
     if (api == null)
     {
         return;
     }
     AllFriends.ZipEach(api.api_fdam.Skip(1), Delegates.SetDamage);
     AllEnemies.ZipEach(api.api_edam.Skip(1), Delegates.SetDamage);
     AllFriends.ZipEach(api.api_fydam.Skip(1), Delegates.SetGiveDamage);
     AllEnemies.ZipEach(api.api_eydam.Skip(1), Delegates.SetGiveDamage);
 }
Esempio n. 5
0
        private void EditFriend(Friend friend)
        {
            var result = EditWindowController.ShowDialog(new OpenEditWindowArgs {
                Type = ActionType.Edit, Friend = SelectedFriend
            });

            if (result.HasValue && result.Value)
            {
                // Remember user's selection
                int index = AllFriends.IndexOf(SelectedFriend);
                AllFriends = new ObservableCollection <Friend>(DataProvider.GetAllFriends().OfType <Friend>());

                // re-selected the original item
                SelectedFriend = AllFriends[index];
            }
        }
Esempio n. 6
0
        public AllFriends GetAllFriends(string user)
        {
            AllFriends all = new AllFriends();

            all.friends = new List <string>();
            using (var factory = new FriendSuggestorContextFactory())
            {
                // Get a context
                using (var context = factory.CreateContext())
                {
                    User u = context.Users.Where(x => x.UserName == user).FirstOrDefault();
                    if (u != null)
                    {
                        var u1 = (from l in context.FriendsLists
                                  join r in context.Users
                                  on l.UserF equals r.UserId
                                  where l.UserSF == u.UserId && l.IsFriend == true
                                  select r.UserName).Distinct().ToList();
                        if (u1.Count > 0)
                        {
                            all.friends.AddRange(u1);
                        }
                        var u2 = (from l in context.FriendsLists
                                  join r in context.Users
                                  on l.UserSF equals r.UserId
                                  where l.UserF == u.UserId && l.IsFriend == true
                                  select r.UserName).Distinct().ToList();
                        if (u2.Count > 0)
                        {
                            all.friends.AddRange(u2);
                        }
                    }
                    else
                    {
                        all.friends = null;
                    }
                }
            }
            return(all);
        }