public bool ConfirmFriendRequest(FriendRequestModel friendRequestModel) { UserProfile requester = db.UserProfiles.Where(up => up.UserProfileId == friendRequestModel.AdderUserProfileId).FirstOrDefault(); UserProfile accepter = db.UserProfiles.Where(up => up.UserProfileId == friendRequestModel.AddedUserProfileId).FirstOrDefault(); if ((requester != null && accepter != null) && (requester != accepter)) { if (!Utilities.AreFriends(requester, accepter)) { Friendship friendship = new Friendship(); friendship.AddingParty = requester; friendship.AddedParty = accepter; db.AddToFriendships(friendship); FriendRequest friendRequest = db.FriendRequests.Where(x => x.AdderId == friendRequestModel.AdderUserProfileId && x.AddedId == friendRequestModel.AddedUserProfileId).FirstOrDefault(); db.DeleteObject(friendRequest); db.SaveChanges(); return true; } else { return false; } } else { return false; } }
/// <summary> /// Deprecated Method for adding a new object to the Friendships EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToFriendships(Friendship friendship) { base.AddObject("Friendships", friendship); }
/// <summary> /// Create a new Friendship object. /// </summary> /// <param name="adderId">Initial value of the AdderId property.</param> /// <param name="addedId">Initial value of the AddedId property.</param> public static Friendship CreateFriendship(global::System.Int32 adderId, global::System.Int32 addedId) { Friendship friendship = new Friendship(); friendship.AdderId = adderId; friendship.AddedId = addedId; return friendship; }