public ActionResult Index() { var listaOrdenada = repository.GetAllFriends() .OrderByDescending(o => DateTime.Now.Subtract( new DateTime(DateTime.Now.Year, o.BirthDate.Month, o.BirthDate.Day)) .TotalSeconds).ToList(); return(View(listaOrdenada)); }
public async Task <List <FriendResponseModel> > GetAllFriends(int id) { var friends = await repository.GetAllFriends(id); var friendModels = new List <FriendResponseModel>(); foreach (var friend in friends) { var friendModel = new FriendResponseModel { FriendProfile = ConvertToProfileModel(friend.ProfileFriend), UserProfile = ConvertToProfileModel(friend.UserProfile), IsConfirmed = friend.IsConfirmed, }; friendModels.Add(friendModel); } return(friendModels); }
// GET: User public ActionResult Index(int id = 0) { User user; if (id == 0) { user = currentUser; } else { user = userRepository.GetUserById(id); } List <string> friendIds; if (currentUser.FriendIds == null || currentUser.FriendIds == "") { friendIds = null; } else { friendIds = currentUser.FriendIds.Split(',').ToList(); } List <int> friendRequestIds = friendRepository.GetFriendRequestIds(currentUser.UserId); List <int> sentFriendRequestIds = friendRepository.GetSentFriendRequestIds(currentUser.UserId); string friendButtonText; string friendButtonClass = "UserButtonProfile"; bool requested = false; if (friendIds != null && friendIds.Contains(user.UserId.ToString())) { friendButtonText = "Remove Friend"; } else if (sentFriendRequestIds != null && sentFriendRequestIds.Contains(user.UserId)) { friendButtonText = "Cancel Request"; friendButtonClass = "RemoveButtonProfile"; } else if (friendRequestIds != null && friendRequestIds.Contains(user.UserId)) { friendButtonText = "Accept"; requested = true; } else { friendButtonText = "Add Friend"; friendButtonClass = "AcceptButtonProfile"; } UserPageModel userPage = new UserPageModel() { User = user, Statuses = statusRepository.UserStatuses(currentUser.UserId, user.UserId), Friends = friendRepository.GetAllFriends(user.UserId), CurrentUserId = currentUser.UserId, FriendIds = friendIds, FriendButtonText = friendButtonText, Requested = requested, FriendButtonClass = friendButtonClass, }; ViewBag.StatusClass = "ProfileStatus"; return(View(userPage)); }