/// <summary> /// Approves the friendship. Called when the "Approve friendship" button is pressed. /// Expects the RequestFriendship method to be run first. /// </summary> private bool ApproveFriendship() { // Get the users involved in the friendship UserInfo user = MembershipContext.AuthenticatedUser; UserInfo friend = UserInfoProvider.GetUserInfo("MyNewFriend"); if (friend != null) { // Get the friendship with current user FriendInfo updateFriendship = FriendInfoProvider.GetFriendInfo(user.UserID, friend.UserID); if (updateFriendship != null) { // Set its properties updateFriendship.FriendStatus = FriendshipStatusEnum.Approved; updateFriendship.FriendRejectedBy = 0; updateFriendship.FriendApprovedBy = user.UserID; updateFriendship.FriendApprovedWhen = DateTime.Now; // Save the changes to database FriendInfoProvider.SetFriendInfo(updateFriendship); return(true); } } return(false); }
protected void btnRemoveSelected_Click(object sender, EventArgs e) { // If there user selected some items if (gridElem.SelectedItems.Count > 0) { RaiseOnCheckPermissions(PERMISSION_MANAGE, this); // Get all needed friendships DataSet friendships = FriendInfoProvider.GetFriends() .WhereIn("FriendID", gridElem.SelectedItems.Select(id => ValidationHelper.GetInteger(id, 0)).ToList()); if (!DataHelper.DataSourceIsEmpty(friendships)) { // Delete all these friendships foreach (DataRow friendship in friendships.Tables[0].Rows) { FriendInfo fi = new FriendInfo(friendship); if (fi.FriendStatus != FriendshipStatusEnum.Rejected) { FriendInfoProvider.DeleteFriendInfo(fi); } } } gridElem.ResetSelection(); // Reload grid gridElem.ReloadData(); } }
/// <summary> /// Creates friend. Called when the "Create friend" button is pressed. /// </summary> private bool RequestFriendship() { // First create a new user which the friendship request will be sent to UserInfo newFriend = new UserInfo(); newFriend.UserName = "******"; newFriend.FullName = "My new friend"; newFriend.UserGUID = Guid.NewGuid(); UserInfoProvider.SetUserInfo(newFriend); // Create new friend object FriendInfo newFriendship = new FriendInfo(); // Set the properties newFriendship.FriendUserID = MembershipContext.AuthenticatedUser.UserID; newFriendship.FriendRequestedUserID = newFriend.UserID; newFriendship.FriendRequestedWhen = DateTime.Now; newFriendship.FriendComment = "Sample friend request comment."; newFriendship.FriendStatus = FriendshipStatusEnum.Waiting; newFriendship.FriendGUID = Guid.NewGuid(); // Save the friend FriendInfoProvider.SetFriendInfo(newFriendship); return(true); }
/// <summary> /// Gets and bulk updates friends. Called when the "Get and bulk update friends" button is pressed. /// Expects the RequestFriendship method to be run first. /// </summary> private bool GetAndBulkUpdateFriends() { // Get the user UserInfo friend = UserInfoProvider.GetUserInfo("MyNewFriend"); if (friend != null) { // Prepare the parameters string where = "FriendRequestedUserID = " + friend.UserID; // Get the data DataSet friends = FriendInfoProvider.GetFriends(where, null); if (!DataHelper.DataSourceIsEmpty(friends)) { // Loop through the individual items foreach (DataRow friendDr in friends.Tables[0].Rows) { // Create object from DataRow FriendInfo modifyFriend = new FriendInfo(friendDr); // Update the properties modifyFriend.FriendStatus = FriendshipStatusEnum.Approved; modifyFriend.FriendRejectedBy = 0; modifyFriend.FriendApprovedBy = MembershipContext.AuthenticatedUser.UserID; modifyFriend.FriendApprovedWhen = DateTime.Now; // Save the changes FriendInfoProvider.SetFriendInfo(modifyFriend); } return(true); } } return(false); }
protected void btnRemoveSelected_Click(object sender, EventArgs e) { // If there user selected some items if (gridElem.SelectedItems.Count > 0) { RaiseOnCheckPermissions(PERMISSION_MANAGE, this); // Create where condition string where = "FriendID IN ("; foreach (string friendId in gridElem.SelectedItems) { where += ValidationHelper.GetInteger(friendId, 0) + ","; } where = where.TrimEnd(',') + ")"; // Get all needed friendships DataSet friendships = FriendInfoProvider.GetFriends(where, null); if (!DataHelper.DataSourceIsEmpty(friendships)) { // Delete all these friendships foreach (DataRow friendship in friendships.Tables[0].Rows) { FriendInfoProvider.DeleteFriendInfo(new FriendInfo(friendship)); } } gridElem.ResetSelection(); // Reload grid gridElem.ReloadData(); } }
/// <summary> /// Handles the UniGrid's OnAction event. /// </summary> /// <param name="actionName">Name of item (button) that throws event</param> /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param> protected void gridElem_OnAction(string actionName, object actionArgument) { RaiseOnCheckPermissions(PERMISSION_MANAGE, this); switch (actionName) { case "remove": FriendInfoProvider.DeleteFriendInfo(ValidationHelper.GetInteger(actionArgument, 0)); gridElem.ReloadData(); break; } }
protected void btnApprove_Click(object sender, EventArgs e) { lblInfo.Text = ApprovedCaption; friendship.FriendStatus = FriendshipStatusEnum.Approved; friendship.FriendApprovedBy = friendship.FriendRequestedUserID; friendship.FriendApprovedWhen = DateTime.Now; FriendInfoProvider.SetFriendInfo(friendship); plcConfirm.Visible = false; plcMessage.Visible = true; action = FriendsActionEnum.Approve; // Send notification SentNotification(); }
/// <summary> /// Handles the UniGrid's OnAction event. /// </summary> /// <param name="actionName">Name of item (button) that throws event</param> /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param> protected void gridElem_OnAction(string actionName, object actionArgument) { RaiseOnCheckPermissions(PERMISSION_MANAGE, this); FriendInfo fi = FriendInfoProvider.GetFriendInfo(ValidationHelper.GetInteger(actionArgument, 0)); if (fi != null) { switch (actionName) { case "remove": if (fi.FriendStatus != FriendshipStatusEnum.Rejected) { FriendInfoProvider.DeleteFriendInfo(fi); } gridElem.ReloadData(); break; } } }
/// <summary> /// Deletes all friends of "My new user". Called when the "Delete friends" button is pressed. /// Expects the CreateFriend method to be run first. /// </summary> private bool DeleteFriends() { // Get the user UserInfo friend = UserInfoProvider.GetUserInfo("MyNewFriend"); if (friend != null) { // Prepare the parameters string where = "FriendRequestedUserID = " + friend.UserID; // Get all user's friendships DataSet friends = FriendInfoProvider.GetFriends(where, null); if (!DataHelper.DataSourceIsEmpty(friends)) { // Delete all the friendships foreach (DataRow friendDr in friends.Tables[0].Rows) { FriendInfo deleteFriend = new FriendInfo(friendDr); FriendInfoProvider.DeleteFriendInfo(deleteFriend); } } else { // Change the info message apiDeleteFriends.InfoMessage = "The user 'My new friend' doesn't have any friends. The user has been deleted."; } // Finally delete the user "My new friend" UserInfoProvider.DeleteUser(friend); return(true); } return(false); }
protected void Page_Load(object sender, EventArgs e) { // Check license if (DataHelper.GetNotEmpty(RequestContext.CurrentDomain, string.Empty) != string.Empty) { LicenseHelper.CheckFeatureAndRedirect(RequestContext.CurrentDomain, FeatureEnum.Friends); } userId = QueryHelper.GetInteger("userid", 0); currentUser = MembershipContext.AuthenticatedUser; int requestedId = QueryHelper.GetInteger("requestid", 0); int friendshipId = 0; // Check if request is for current user or another user with permission to manage it if (currentUser.IsPublic() || ((currentUser.UserID != userId) && !currentUser.IsAuthorizedPerResource("CMS.Friends", "Manage"))) { RedirectToAccessDenied("CMS.Friends", "Manage"); } FriendsApprove.SelectedFriends = null; FriendsApprove.IsLiveSite = true; PageTitle.TitleText = GetString("friends.approvefriendship"); // Multiple selection if (Request["ids"] != null) { string[] items = Request["ids"].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); if (items.Length > 0) { ArrayList friends = new ArrayList(); foreach (string item in items) { friends.Add(ValidationHelper.GetInteger(item, 0)); } FriendsApprove.SelectedFriends = friends; if (friends.Count == 1) { friendshipId = Convert.ToInt32(friends[0]); } } } // For one user else { FriendsApprove.RequestedUserID = requestedId; } FriendInfo fi = null; if (friendshipId != 0) { fi = FriendInfoProvider.GetFriendInfo(friendshipId); // Set edited object EditedObject = fi; } else if (requestedId != 0) { fi = FriendInfoProvider.GetFriendInfo(userId, requestedId); // Set edited object EditedObject = fi; } if (fi != null) { UserInfo requestedUser = (userId == fi.FriendRequestedUserID) ? UserInfoProvider.GetFullUserInfo(fi.FriendUserID) : UserInfoProvider.GetFullUserInfo(fi.FriendRequestedUserID); string fullUserName = Functions.GetFormattedUserName(requestedUser.UserName, requestedUser.FullName, requestedUser.UserNickName, true); Page.Title = GetString("friends.approvefriendshipwith") + " " + HTMLHelper.HTMLEncode(fullUserName); PageTitle.TitleText = Page.Title; } // Set current user FriendsApprove.UserID = userId; }
protected void Page_Load(object sender, EventArgs e) { userId = QueryHelper.GetInteger("userid", 0); currentUser = MembershipContext.AuthenticatedUser; // Check license if (DataHelper.GetNotEmpty(RequestContext.CurrentDomain, string.Empty) != string.Empty) { LicenseHelper.CheckFeatureAndRedirect(RequestContext.CurrentDomain, FeatureEnum.Friends); } FriendsReject.SelectedFriends = null; FriendsReject.OnCheckPermissions += FriendsReject_OnCheckPermissions; int requestedId = QueryHelper.GetInteger("requestid", 0); int friendshipId = 0; Page.Title = GetString("friends.rejectfriendship"); PageTitle.TitleText = Page.Title; // Multiple selection if (Request["ids"] != null) { string[] items = Request["ids"].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); if (items.Length > 0) { ArrayList friends = new ArrayList(); foreach (string item in items) { friends.Add(ValidationHelper.GetInteger(item, 0)); } FriendsReject.SelectedFriends = friends; if (friends.Count == 1) { friendshipId = Convert.ToInt32(friends[0]); } } } // For one user else { FriendsReject.RequestedUserID = requestedId; } FriendInfo fi = null; if (friendshipId != 0) { fi = FriendInfoProvider.GetFriendInfo(friendshipId); // Set edited object EditedObject = fi; } else if (requestedId != 0) { fi = FriendInfoProvider.GetFriendInfo(userId, requestedId); // Set edited object EditedObject = fi; } if (fi != null) { UserInfo requestedUser = (userId == fi.FriendRequestedUserID) ? UserInfoProvider.GetFullUserInfo(fi.FriendUserID) : UserInfoProvider.GetFullUserInfo(fi.FriendRequestedUserID); string fullUserName = Functions.GetFormattedUserName(requestedUser.UserName, requestedUser.FullName, requestedUser.UserNickName, false); Page.Title = GetString("friends.rejectfriendshipwith") + " " + HTMLHelper.HTMLEncode(fullUserName); PageTitle.TitleText = Page.Title; } // Set current user FriendsReject.UserID = userId; }
protected void btnRequest_Click(object senderObject, EventArgs e) { RaiseOnCheckPermissions(PERMISSION_MANAGE, this); string message = string.Empty; // Requested user id not set explicitly if (RequestedUserID == 0) { RequestedUserID = ValidationHelper.GetInteger(selectUser.Value, 0); } // Both users have to be specified if ((RequestedUserID == 0) || (UserID == 0)) { message = GetString("friends.friendrequired"); } else { UserInfo requestedUser = UserInfoProvider.GetUserInfo(RequestedUserID); message = requestedUser == null?GetString("user.error_doesnoteexist") : VerifyRequestedUser(requestedUser); if (String.IsNullOrEmpty(message)) { if (!FriendInfoProvider.FriendshipExists(UserID, RequestedUserID)) { // Set up control Comment = txtComment.Text; SendMail = chkSendEmail.Checked; SendMessage = chkSendMessage.Checked; SelectedFriends = new ArrayList(); SelectedFriends.Add(RequestedUserID); AutomaticApprovment = chkAutomaticApprove.Checked; message = PerformAction(FriendsActionEnum.Request); } else { message = GetString("friends.friendshipexists"); } } } if (!String.IsNullOrEmpty(message)) { ShowError(message); } else { // Register wopener script ScriptHelper.RegisterWOpenerScript(Page); btnRequest.Enabled = false; selectUser.Enabled = false; txtComment.Enabled = false; chkAutomaticApprove.Enabled = false; chkSendEmail.Enabled = false; chkSendMessage.Enabled = false; ShowConfirmation(GetString("friends.friendshiprequested")); const string refreshScript = "if (window.top && window.top.refreshFriendsList) { window.top.refreshFriendsList(); } else if (window.opener && window.opener.refreshFriendsList) { window.opener.refreshFriendsList(); }"; ScriptHelper.RegisterStartupScript(Page, typeof(string), "closeFriendsDialogFriendsList", refreshScript, true); ScriptHelper.RegisterStartupScript(Page, typeof(string), "closeFriendsDialog", "CloseDialog(true);", true); } }
protected void btnRequest_Click(object senderObject, EventArgs e) { RaiseOnCheckPermissions(PERMISSION_MANAGE, this); string message = string.Empty; // Requested user id not set explicitly if (RequestedUserID == 0) { RequestedUserID = ValidationHelper.GetInteger(selectUser.Value, 0); } // Both users have to be specified if ((RequestedUserID == 0) || (UserID == 0)) { message = GetString("friends.friendrequired"); } else { bool friendshipExists = FriendInfoProvider.FriendshipExists(UserID, RequestedUserID); if (!friendshipExists) { // Set up control Comment = txtComment.Text; SendMail = chkSendEmail.Checked; SendMessage = chkSendMessage.Checked; SelectedFriends = new ArrayList(); SelectedFriends.Add(RequestedUserID); AutomaticApprovment = chkAutomaticApprove.Checked; message = PerformAction(FriendsActionEnum.Request); } else { message = GetString("friends.friendshipexists"); } } bool error = (message != string.Empty); lblError.Visible = error; lblInfo.Visible = !error; if (error) { lblError.Text = message; } else { // Register wopener script ScriptHelper.RegisterWOpenerScript(Page); btnRequest.Enabled = false; selectUser.Enabled = false; txtComment.Enabled = false; chkAutomaticApprove.Enabled = false; chkSendEmail.Enabled = false; chkSendMessage.Enabled = false; btnCancel.ResourceString = "general.close"; lblInfo.ResourceString = "friends.friendshiprequested"; btnCancel.OnClientClick = "if((wopener != null) && (wopener.refreshList != null)){wopener.refreshList();}window.close();return false;"; } }