public IActionResult FindByEmail(string email = default(string)) { var userId = _userManager.GetUserId(HttpContext.User); //TODO: make User table var friends = _userManager.Users .Where(u => _friendsRepository.AreFriends(u.Id, userId) && u.Id != userId && (email == default(string) || u.Email.StartsWith(email)) ) .Select(u => new User { Email = u.Email, Id = u.Id }) .ToList(); friends.ForEach(async u => u.IsOnline = await IsOnline(u.Id)); //other users except his friends var foundOtherUsers = _userManager.Users .Where(u => !_friendsRepository.AreFriends(u.Id, userId) && !_friendsRepository.ArePendingFriends(u.Id, userId) && u.Id != userId && (email == default(string) || u.Email.StartsWith(email)) ) .Select(u => new User { Email = u.Email, Id = u.Id }) .ToList(); foundOtherUsers.ForEach(async u => u.IsOnline = await IsOnline(u.Id)); var pending = _userManager.Users .Where(u => _friendsRepository.ArePendingFriends(u.Id, userId) && u.Id != userId && (email == default(string) || u.Email.StartsWith(email)) ) .Select(u => new User { Email = u.Email, Id = u.Id }) .ToList(); pending.ForEach(async u => u.IsOnline = await IsOnline(u.Id)); if (foundOtherUsers == null) { return(NotFound()); } var model = new FriendsModel { Friends = friends, Others = foundOtherUsers, Pending = pending }; return(new OkObjectResult(model)); }
public async Task <IActionResult> Profile(string userId = OWNER_DEFAULT) { var user = (userId == OWNER_DEFAULT) ? await Owner() : _userManager.Users.FirstOrDefault(u => u.Id == userId); var ownerId = (await Owner()).Id; var friendStatus = ""; if (_friendsRepository.AreFriends(userId, ownerId)) { friendStatus = "friend"; } else if (_friendsRepository.ArePendingFriends(userId, ownerId)) { friendStatus = "subscribed"; } else { friendStatus = ""; } var model = new ProfileViewModel { Email = user.Email, Address = user.Address, IsYourProfile = userId == OWNER_DEFAULT, Id = user.Id, FriendStatus = friendStatus, IsOnline = await IsOnline(userId), Avatar = user.Avatar, AvatarContentType = user.AvatarContentType }; return(View(model)); }