示例#1
0
 public IActionResult RemoveFromFriendship(int friendId)
 {
     if (_friendsRepository.IsFriends(_user.Id, friendId))
     {
         _friendsRepository.RemoveFriend(_user.Id, friendId);
         return(Ok(new { status = true }));
     }
     else
     {
         return(Ok(new { status = false }));
     }
 }
 public IActionResult GetAccountDatas(int currentAccountId, int searchedAccountId)
 {
     if (currentAccountId != searchedAccountId)
     {
         if (_friendsRepository.IsFriends(currentAccountId, searchedAccountId)) //friends true
         {
             return Ok(_accountDetailRepository.GetDatasFriend(searchedAccountId));
         }
         else //not friends
         {
             return Ok(_accountDetailRepository.GetDatasPublic(currentAccountId, searchedAccountId));
         }
     }
     else //view own profile
     {
         return Ok(_accountDetailRepository.GetDatasOwn(searchedAccountId));
     }
 }
示例#3
0
        public ICollection <SearchAccount> SearchAccounts(int currentUserId, string term)
        {
            //final search results
            List <SearchAccount> results = new List <SearchAccount>();

            ICollection <int> accountIdList = _context.Accounts.Where(a => a.Fullname.Contains(term))
                                              .OrderBy(a => a.Name)
                                              .Select(a => a.Id)
                                              .ToList();

            foreach (var itemId in accountIdList)
            {
                if (currentUserId != itemId)                                 //don't show current user 2x
                {
                    if (_friendsRepository.IsFriends(currentUserId, itemId)) //friends
                    {
                        SearchAccount searchItem = _accountDetailRepository.GetDatasFriend(itemId);
                        if (searchItem != null)
                        {
                            results.Add(searchItem);
                        }
                    }
                    else //not friends
                    {
                        SearchAccount searchItem = _accountDetailRepository.GetDatasPublic(currentUserId, itemId);
                        if (searchItem != null)
                        {
                            results.Add(searchItem);
                        }
                    }
                }
                else //search own profile
                {
                    SearchAccount searchItem = _accountDetailRepository.GetDatasOwn(itemId);
                    if (searchItem != null)
                    {
                        results.Add(searchItem);
                    }
                }
            }

            return(results);
        }