public ActionResult AddToFavorites(string itemId) { try { Sitecore.Security.Accounts.User user = Sitecore.Context.User; Sitecore.Security.UserProfile profile = user.Profile; string favorites = profile.GetCustomProperty("Favorites"); // determine if we are adding or removing. // We don't know the text of the button because it is managed in the CMS, so we will see it is already a favorite. if (favorites.Contains(Sitecore.Context.Item.ID.ToString())) { favorites = favorites.Replace(Sitecore.Context.Item.ID.ToString(), String.Empty); favorites = favorites.Replace("||", "|"); // when removing we may leave a double pipe if (favorites == "|") { favorites = String.Empty; } } else // it must be an add { if (favorites == String.Empty) { favorites = Sitecore.Context.Item.ID.ToString(); } else { favorites = favorites + "|" + Sitecore.Context.Item.ID.ToString(); } // Capture the goal AnalyticsHelper.RegisterGoalOnCurrentPage("Add a Favorite", "[Add a Favorite] : \"" + Sitecore.Context.Item.Name + "\""); } profile.SetCustomProperty("Favorites", favorites); profile.Save(); } catch { } return(View("AddToFavorites", IsAddToFavorites)); }
private bool AddUser(string email, string password, string firstName, string lastName, string twitterHandle, string githubUsername, string linkedInUsername) { string userName = email; var success = false; //userName = string.Format(@"{0}\{1}", domain, userName); //string newPassword = Membership.GeneratePassword(10, 3); try { if (!User.Exists(userName)) { var domain = Sitecore.Context.Domain; var accountName = domain.GetFullName(userName); Membership.CreateUser(accountName, password, email); // Edit the profile information User user = User.FromName(accountName, true); Sitecore.Security.UserProfile userProfile = user.Profile; userProfile.FullName = string.Format("{0} {1}", firstName, lastName); //userProfile.Comment = comment; // Assigning the user profile template userProfile.SetPropertyValue("ProfileItemId", "{BBCCF1F4-A638-4FE3-9B2E-8E5D7D73AE9E}"); userProfile.SetCustomProperty("Twitter Handle", twitterHandle != null ? twitterHandle : string.Empty); userProfile.SetCustomProperty("Github Username", githubUsername); userProfile.SetCustomProperty("LinkedIn Username", linkedInUsername != null ? linkedInUsername : string.Empty); userProfile.Save(); success = true; } } catch (Exception ex) { Sitecore.Diagnostics.Log.Error(string.Format("Error in Client.Project.Security.UserMaintenance (AddUser): Message: {0}; Source:{1}", ex.Message, ex.Source), this); } return(success); }
protected void btnAddtoFavs_Click(object sender, EventArgs e) { Sitecore.Security.Accounts.User user = Sitecore.Context.User; Sitecore.Security.UserProfile profile = user.Profile; string favorites = profile.GetCustomProperty("Favorites"); // determine if we are adding or removing. // We don't know the text of the button because it is managed in the CMS, so we will see it is already a favorite. if (favorites.Contains(Sitecore.Context.Item.ID.ToString())) { favorites = favorites.Replace(Sitecore.Context.Item.ID.ToString(), String.Empty); favorites = favorites.Replace("||", "|"); // when removeing we may leave a double pipe if (favorites == "|") { favorites = String.Empty; } } else // it must be an add { if (favorites == String.Empty) { favorites = Sitecore.Context.Item.ID.ToString(); } else { favorites = favorites + "|" + Sitecore.Context.Item.ID.ToString(); } // Capture the goal using our helper method AnalyticsHelper.RegisterGoalOnCurrentPage("Add a Favorite", "[Add a Favorite] : \"" + Sitecore.Context.Item.Name + "\""); //Tracker.CurrentVisit.CurrentPage.Register("Add a Favorite", "[Add a Favorite] : \"" + Sitecore.Context.Item.Name + "\""); } profile.SetCustomProperty("Favorites", favorites); profile.Save(); SetButtonText(sender as LinkButton); }