public override bool Execute() { int totalUsers = accountServices.GetAllUserProfiles().Count(); UserProfileModel accepter = accountServices.GetUserProfileByUserProfileId(random.Next(1, totalUsers)); GetFriendRequestsModel gfrm = new GetFriendRequestsModel(); gfrm.UserProfileId = accepter.UserProfileId; IQueryable<UserProfileModel> friendRequests = accountServices.GetFriendRequests(gfrm); UserProfileModel requester = friendRequests.FirstOrDefault(); if (requester != null) { FriendRequestModel m = new FriendRequestModel(); m.AddedUserProfileId = accepter.UserProfileId; m.AdderUserProfileId = requester.UserProfileId; Console.WriteLine("Making users " + m.AdderUserProfileId + " and " + m.AddedUserProfileId + " friends."); return accountServices.ConfirmFriendRequest(m); } else { return false; } }
public override bool Execute() { int totalUsers = accountServices.GetAllUserProfiles().Count(); GetFriendRequestsModel gfrm = new GetFriendRequestsModel(); gfrm.UserProfileId = random.Next(1, totalUsers); Console.WriteLine("All pending friend requests of " + gfrm.UserProfileId); foreach (UserProfileModel upm in accountServices.GetFriendRequests(gfrm)) { Console.WriteLine("\t" + upm.UserProfileId); } return true; }
// // GET: /Notification/ public ActionResult Index() { GetFriendRequestsModel gfrm = new GetFriendRequestsModel(); gfrm.UserProfileId = accountServices.GetUserByUsername(User.Identity.Name).UserId; IQueryable<UserProfileModel> iq = accountServices.GetFriendRequests(gfrm); NotificationModel nm = new NotificationModel(); nm.FriendRequestNotifications = new List<FriendRequestViewModel>(); List<UserProfileModel> lupm = iq.ToList<UserProfileModel>(); foreach (UserProfileModel upm in lupm) { FriendRequestViewModel frm = new FriendRequestViewModel(); frm.UserProfileId = upm.UserProfileId; frm.FullName = upm.FirstName + " " + upm.LastName; nm.FriendRequestNotifications.Add(frm); } IQueryable<MessageModel> messageList = EventServices.GetInstance().GetMessages(new GetMessagesModel { GetUnreadOnly = true, UserProfileID = gfrm.UserProfileId }); List<MessageViewModel> messageViewList = new List<MessageViewModel>(); foreach (MessageModel mm in messageList) { UserProfileModel sender = accountServices.GetUserProfileByUserProfileId(mm.SenderProfileID); messageViewList.Add(new MessageViewModel { EventID = mm.EventID != null ? (int)mm.EventID : -1, EventName = EventServices.GetInstance().GetEventById(mm.EventID != null ? (int)mm.EventID : -1).Title, Message = mm.Message, MessageID = mm.MessageID, SenderName = sender.FirstName + " " + sender.LastName, SenderProfileID = mm.SenderProfileID }); } nm.UnreadMessages = messageViewList; return View(nm); }
// TODO: CHECK: IS THIS THE PENDING FRIEND REQUESTS MADE BY THE USER? public IQueryable<UserProfileModel> GetFriendRequests(GetFriendRequestsModel gfrm) { UserProfile up = db.UserProfiles.Where(u => u.UserProfileId == gfrm.UserProfileId).FirstOrDefault(); var pendingFriendRequests = up.PendingFriendRequests; List<UserProfile> friendRequests = new List<UserProfile>(); foreach (FriendRequest request in pendingFriendRequests) { friendRequests.Add(request.AddingParty); } List<UserProfileModel> userProfileModels = new List<UserProfileModel>(); foreach (UserProfile userProfile in friendRequests) { userProfileModels.Add(Utilities.UserProfileToUserProfileModel(userProfile)); } return userProfileModels.AsQueryable(); }