public static ProfileQuestion[] Fetch() { const string cacheKey = "ProfileQuestion_Fetch"; if (HttpContext.Current != null && HttpContext.Current.Cache[cacheKey] != null) { return HttpContext.Current.Cache[cacheKey] as ProfileQuestion[]; } using (SqlConnection conn = Config.DB.Open()) { SqlDataReader reader = SqlHelper.ExecuteReader(conn, "FetchProfileQuestion", null); var lQuestions = new List<ProfileQuestion>(); while (reader.Read()) { var question = new ProfileQuestion { id = ((int) reader["ID"]), topicId = ((int) reader["TopicID"]), name = ((string) reader["Name"]), altName = ((string) reader["AltName"]), description = ((string) reader["Description"]), hint = ((string) reader["Hint"]), editStyle = ((eEditStyle) reader["EditStyle"]), showStyle = ((eShowStyle) reader["ShowStyle"]), searchStyle = ((eSearchStyle) reader["SearchStyle"]), required = ((bool) reader["Required"]), priority = ((int) reader["Priority"]), requiresApproval = ((bool) reader["RequiresApproval"]), visibleForMale = ((bool) reader["VisibleForMale"]), visibleForFemale = ((bool) reader["VisibleForFemale"]), visibleForCouple = ((bool) reader["VisibleForCouple"]), matchField = (reader["MatchField"] != DBNull.Value ? (int?) reader["MatchField"] : null), visibleForPaidOnly = (bool)reader["ViewPaidOnly"], editableForPaidOnly = (bool)reader["EditPaidOnly"], parentQuestionID = reader["ParentQuestionID"] != DBNull.Value ? (int?)reader["ParentQuestionID"] : null, parentQuestionChoices = reader["ParentQuestionChoices"] != DBNull.Value ? (string)reader["ParentQuestionChoices"] : null }; lQuestions.Add(question); } ProfileQuestion[] profileQuestions = lQuestions.ToArray(); if (HttpContext.Current != null) { HttpContext.Current.Cache.Insert(cacheKey, profileQuestions, null, Cache.NoAbsoluteExpiration, TimeSpan.FromHours(1), CacheItemPriority.NotRemovable, null); } return profileQuestions; } }
private void PopulateChildrenIDs(ProfileQuestion question, ProfileQuestion[] questions, Dictionary<int, object> dicQuestions, List<string> childClientIDs) { ProfileQuestion[] childQuestions = questions.Where(q => q.ParentQuestionID.HasValue && q.ParentQuestionID.Value == question.Id).ToArray(); if (childQuestions.Length > 0) { foreach (ProfileQuestion childQuestion in childQuestions) { // child question is not visible so skip it if (dicQuestions.ContainsKey(childQuestion.Id)) { string childClientID = ((IProfileSearchComponent)dicQuestions[childQuestion.Id]).UserControlPanel.ClientID; childClientIDs.Add(childClientID); } PopulateChildrenIDs(childQuestion, questions, dicQuestions, childClientIDs); } } }
/// <summary> /// Fetches Profile Question from the DB. Throws NotFoundException if the question doesn't exist. /// </summary> /// <param name="Id">Id of the question</param> /// <returns>ProfileQuestion object</returns> /// <exception cref="NotFoundException">No question was found with the requested Id</exception> public static ProfileQuestion Fetch(int Id) { string cacheKey = String.Format("ProfileQuestion_Fetch_{0}", Id); if (HttpContext.Current != null && HttpContext.Current.Cache[cacheKey] != null) { return HttpContext.Current.Cache[cacheKey] as ProfileQuestion; } using (SqlConnection conn = Config.DB.Open()) { SqlDataReader reader = SqlHelper.ExecuteReader(conn, "FetchProfileQuestion", Id); var question = new ProfileQuestion {id = Id}; if (reader.Read()) { question.topicId = (int) reader["TopicID"]; question.name = (string) reader["Name"]; question.altName = (string) reader["AltName"]; question.description = (string) reader["Description"]; question.hint = (string) reader["Hint"]; question.editStyle = (eEditStyle) reader["EditStyle"]; question.showStyle = (eShowStyle) reader["ShowStyle"]; question.searchStyle = (eSearchStyle) reader["SearchStyle"]; question.required = (bool) reader["Required"]; question.priority = (int) reader["Priority"]; question.requiresApproval = (bool) reader["RequiresApproval"]; question.visibleForMale = (bool) reader["VisibleForMale"]; question.visibleForFemale = (bool) reader["VisibleForFemale"]; question.visibleForCouple = (bool) reader["VisibleForCouple"]; question.matchField = reader["MatchField"] != DBNull.Value ? (int?) reader["MatchField"] : null; question.visibleForPaidOnly = (bool) reader["ViewPaidOnly"]; question.editableForPaidOnly = (bool)reader["EditPaidOnly"]; question.parentQuestionID = reader["ParentQuestionID"] != DBNull.Value ? (int?) reader["ParentQuestionID"] : null; question.parentQuestionChoices = reader["ParentQuestionChoices"] != DBNull.Value ? (string) reader["ParentQuestionChoices"] : null; } else { throw new NotFoundException (Lang.Trans("The requested question does not exist!")); } if (HttpContext.Current != null) { HttpContext.Current.Cache.Insert(cacheKey, question, null, Cache.NoAbsoluteExpiration, TimeSpan.FromHours(1), CacheItemPriority.NotRemovable, null); } return question; } }
private void SetCascadeQuestions(ProfileQuestion[] questions, Dictionary<int, object> dicQuestions) { List<int> lHiddenParentQuestions = new List<int>(); foreach (ProfileQuestion question in questions) { ProfileQuestion[] childQuestions = questions.Where(q => q.ParentQuestionID.HasValue && q.ParentQuestionID.Value == question.Id).ToArray(); bool isParent = childQuestions.Length > 0; bool isChild = question.ParentQuestionID.HasValue; if (!dicQuestions.ContainsKey(question.Id)) // if current question is hidden continue; Control currentQuestionControl = (Control)dicQuestions[question.Id]; if ((currentQuestionControl as ICascadeQuestionComponent) != null) ((ICascadeQuestionComponent)currentQuestionControl).GenerateResetValuesJS(); if (isParent) { Dictionary<string, object[]> childClientIDsWithParentQuestionChoices = new Dictionary<string, object[]>(); GetChildrenClientIDs(question, questions, dicQuestions, childClientIDsWithParentQuestionChoices); if ((currentQuestionControl as ICascadeQuestionComponent) != null) ((ICascadeQuestionComponent)currentQuestionControl).GenerateJSForChildVisibility(childClientIDsWithParentQuestionChoices); else new Exception(String.Format("{0} control must implement ICascadeQuestionComponent", currentQuestionControl.ID)); } if (isChild) { // if parent question is hidden hide the child if (!dicQuestions.ContainsKey(question.ParentQuestionID.Value) || lHiddenParentQuestions.Contains(question.ParentQuestionID.Value)) { lHiddenParentQuestions.Add(question.Id); ((IProfileSearchComponent)currentQuestionControl).UserControlPanel.Attributes.Add("style", "display:none"); ((IProfileSearchComponent)currentQuestionControl).ClearAnswers(); continue; } Control currentQuestionParentControl = (Control)dicQuestions[question.ParentQuestionID.Value]; List<string> parentAnswers = new List<string>(); foreach (ProfileAnswer answer in ((IProfileSearchComponent)currentQuestionParentControl).Answers) { parentAnswers.Add(answer.Value); } if (!question.ParentQuestionChoices.Split(':').Any(parentChoice => parentAnswers.Contains(parentChoice))) { lHiddenParentQuestions.Add(question.Id); ((IProfileSearchComponent)currentQuestionControl).UserControlPanel.Attributes.Add("style", "display:none"); ((IProfileSearchComponent)currentQuestionControl).ClearAnswers(); } } } }
private void GetChildrenClientIDs(ProfileQuestion question, ProfileQuestion[] questions, Dictionary<int, object> dicQuestions, Dictionary<string, object[]> childClientIDsWithParentQuestionChoices) { ProfileQuestion[] childQuestions = questions.Where(q => q.ParentQuestionID.HasValue && q.ParentQuestionID.Value == question.Id).ToArray(); if (childQuestions.Length > 0) { foreach (ProfileQuestion childQuestion in childQuestions) { var childClientIDs = new List<string>(); // child question is not visible so skip it if (dicQuestions.ContainsKey(childQuestion.Id)) { string childClientID = ((IProfileSearchComponent)dicQuestions[childQuestion.Id]).UserControlPanel.ClientID; string[] parentQuestionChoices = childQuestion.ParentQuestionChoices.Split(new[] { ":" }, StringSplitOptions.RemoveEmptyEntries); childClientIDsWithParentQuestionChoices.Add(childClientID, new object[] { parentQuestionChoices, childClientIDs }); } PopulateChildrenIDs(childQuestion, questions, dicQuestions, childClientIDs); } } }
private static int CalculateMatchPercentage(ProfileQuestion[] profileQuestions, List<ProfileAnswer> profileAnswers1, List<ProfileAnswer> profileAnswers2) { decimal points = 0; int count = 0; foreach (ProfileQuestion profileQuestion in profileQuestions) { if (profileQuestion.MatchField == null || profileQuestion.EditStyle == ProfileQuestion.eEditStyle.Hidden || profileQuestion.EditStyle == ProfileQuestion.eEditStyle.MultiLine || profileQuestion.EditStyle == ProfileQuestion.eEditStyle.SingleLine) { continue; } count++; List<string> lChoices1 = new List<string>(); List<string> lChoices2 = new List<string>(); var answer1 = profileAnswers1.SingleOrDefault(a => a.Question.Id == profileQuestion.Id); var answer2 = profileAnswers2.SingleOrDefault(a => a.Question.Id == profileQuestion.MatchField); if (answer1 == null || answer2 == null) { points += 0.5m; continue; } if (profileQuestion.EditStyle == ProfileQuestion.eEditStyle.SingleChoiceRadio || profileQuestion.EditStyle == ProfileQuestion.eEditStyle.SingleChoiceSelect) { lChoices1.Add(answer1.Value); } else if (profileQuestion.EditStyle == ProfileQuestion.eEditStyle.MultiChoiceCheck || profileQuestion.EditStyle == ProfileQuestion.eEditStyle.MultiChoiceSelect) { foreach (string answer in answer1.Value.Split(':')) { lChoices1.Add(answer); } } ProfileQuestion profileQuestion2 = ProfileQuestion.Fetch(profileQuestion.MatchField.Value); if (profileQuestion2.EditStyle == ProfileQuestion.eEditStyle.SingleChoiceRadio || profileQuestion2.EditStyle == ProfileQuestion.eEditStyle.SingleChoiceSelect) { lChoices2.Add(answer2.Value); } else if (profileQuestion2.EditStyle == ProfileQuestion.eEditStyle.MultiChoiceCheck || profileQuestion2.EditStyle == ProfileQuestion.eEditStyle.MultiChoiceSelect) { foreach (string answer in answer2.Value.Split(':')) { lChoices2.Add(answer); } } var choices = lChoices1.Intersect(lChoices2); points += choices.Count() / (decimal)lChoices1.Count; } if (count != 0) return (int)(points / count * 100); else return -1; }
protected void btnAddNewQuestion_Click(object sender, EventArgs e) { if (!HasWriteAccess) return; ProfileQuestion question = new ProfileQuestion(); question.Name = "NewName"; question.AltName = "New alternative name"; question.Description = "New description"; question.Hint = "New hint"; question.EditStyle = ProfileQuestion.eEditStyle.Hidden; question.ShowStyle = ProfileQuestion.eShowStyle.Hidden; question.SearchStyle = ProfileQuestion.eSearchStyle.Hidden; question.Required = true; question.TopicID = Convert.ToInt32(TopicID); question.Save(); PopulateDataGrid(); }
private void BindQuestionDetails(ProfileQuestion[] questions) { DataTable dtQuestions = new DataTable("Questions"); dtQuestions.Columns.Add("QuestionID"); dtQuestions.Columns.Add("Name"); dtQuestions.Columns.Add("Description"); dtQuestions.Columns.Add("Required", typeof (Boolean)); foreach (ProfileQuestion question in questions) { dtQuestions.Rows.Add(new object[] { question.Id, question.Name, question.Description, question.Required } ); } DataSource = dtQuestions; dgQuestions.DataSource = dtQuestions; dgQuestions.DataBind(); }
private bool SetCascadeQuestions(ProfileQuestion[] questions, Dictionary<int, object> dicQuestions) { bool hasCascadeQuestions = false; List<int> lHiddenParentQuestions = new List<int>(); foreach (ProfileQuestion question in questions) { ProfileQuestion[] childQuestions = questions.Where(q => q.ParentQuestionID.HasValue && q.ParentQuestionID.Value == question.Id).ToArray(); bool isParent = childQuestions.Length > 0; bool isChild = question.ParentQuestionID.HasValue; if (!dicQuestions.ContainsKey(question.Id)) continue; // if current question is hidden Control currentQuestionControl = (Control)dicQuestions[question.Id]; if ((currentQuestionControl as ICascadeQuestionComponent) != null) ((ICascadeQuestionComponent)currentQuestionControl).GenerateResetValuesJS(); if (isParent) { hasCascadeQuestions = true; Dictionary<string, object[]> childClientIDsWithParentQuestionChoices = new Dictionary<string, object[]>(); GetChildrenClientIDs(question, questions, dicQuestions, childClientIDsWithParentQuestionChoices); if ((currentQuestionControl as ICascadeQuestionComponent) != null) ((ICascadeQuestionComponent)currentQuestionControl).GenerateJSForChildVisibility(childClientIDsWithParentQuestionChoices); else new Exception(String.Format("{0} control must implement ICascadeQuestionComponent", currentQuestionControl.ID)); } if (isChild) { // if parent question is hidden hide the child if (!dicQuestions.ContainsKey(question.ParentQuestionID.Value) || lHiddenParentQuestions.Contains(question.ParentQuestionID.Value)) { lHiddenParentQuestions.Add(question.Id); ((IProfileQuestionComponent)currentQuestionControl).UserControlPanel.Attributes.Add("style", "display:none"); ((IProfileQuestionComponent) currentQuestionControl).Answer.Value = String.Empty; continue; } Control currentQuestionParentControl = (Control)dicQuestions[question.ParentQuestionID.Value]; string[] parentAnswers = new string[0]; try { parentAnswers = ((IProfileQuestionComponent)currentQuestionParentControl).Answer.Value.Split( new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries); } catch (AnswerRequiredException) { } if (!question.ParentQuestionChoices.Split(':').Any(parentChoice => parentAnswers.Contains(parentChoice))) { lHiddenParentQuestions.Add(question.Id); ((IProfileQuestionComponent) currentQuestionControl).UserControlPanel.Attributes.Add("style", "display:none"); ((IProfileQuestionComponent)currentQuestionControl).Answer.Value = String.Empty; } } } return hasCascadeQuestions; }
private void StoreAllSettings() { var billingPlanOptions = Config.Users.GetNonPayingMembersOptions(); #region step 1 Config.Misc.SiteTitle = txtSiteName.Text; Config.Misc.SiteEmail = txtSiteEmail.Text; //var siteModel = (SiteModel)Int32.Parse(rblSiteModel.SelectedValue); //switch(siteModel) //{ // case SiteModel.SubscriptionBased: // Config.Users.PaymentRequired = true; // Config.Credits.Required = false; // break; // case SiteModel.PerContact: // Config.Credits.Required = true; // Config.Users.PaymentRequired = false; // break; // case SiteModel.Free: // Config.Credits.Required = false; // Config.Users.PaymentRequired = false; // break; //} #region activate selected languages foreach (ListItem item in cblSiteLanguages.Items) { var language = Language.Fetch(Int32.Parse(item.Value)); if (item.Selected) { language.Active = true; } else { language.Active = false; } language.Save(); } if (cbOtherLanguage.Checked && txtOtherLanguage.Text.Trim().Length > 0) { var language = Language.Create(txtOtherLanguage.Text, true); language.Save(); } #endregion #endregion #region step 2 Config.Misc.EnableAjaxChat = cbEnableAjaxChatRoom.Checked; billingPlanOptions.UserCanUseChat.Value = cbEnableAjaxChatRoom.Checked; Config.Misc.EnableIntegratedIM = cbEnableMessenger.Checked; Config.Misc.EnableCoolIris = cbEnableCoolIris.Checked; Config.Users.EnablePhotoAlbums = cbEnablePhotoAlbums.Checked; Config.Ads.Enable = cbEnableClassifiedAds.Checked; if (Config.Ads.Enable) { Config.Ads.OnlyRegisteredUsersCanBrowseClassifieds = cbOnlyRegisteredUsersCanBrowseClassifiedAds.Checked; Config.Ads.EnableAdComments = cbAllowUsersToLeaveCommentsOnTheClassifiedAds.Checked; } Config.Misc.EnableBlogs = cbEnableBlogs.Checked; if (Config.Misc.EnableBlogs) { Config.Misc.EnableBlogPostApproval = cbEnableBlogPostApproval.Checked; } Config.Groups.EnableGroups = cbEnableCommunityGroups.Checked; if (Config.Groups.EnableGroups) { Config.Groups.EnableAjaxChat = cbEnableAjaxChatRoomsInGroups.Checked; billingPlanOptions.CanCreateGroups.Value = cbAllowUsersToCreateGroups.Checked; billingPlanOptions.MaxGroupsPerMember.Value = Int32.Parse(txtMaximumGroupsToJoin.Text); } Config.Misc.EnableVideoUpload = cbEnableVideoFileUploads.Checked; if (Config.Misc.EnableVideoUpload) { billingPlanOptions.MaxVideoUploads.Value = Int32.Parse(txtMaximumUploadedVideosPerUser.Text); } Config.Misc.EnableYouTubeVideos = cbEnableYouTubeVideosEmbedding.Checked; if (Config.Misc.EnableYouTubeVideos) { billingPlanOptions.MaxVideos.Value = Int32.Parse(txtMaximumYouTubeVideosPerUser.Text); //Config.Misc.MaxYouTubeVideos = Int32.Parse(txtMaximumYouTubeVideosPerUser.Text); } Config.Misc.EnableAudioUpload = cbEnableMP3FileUploads.Checked; if (Config.Misc.EnableAudioUpload) { billingPlanOptions.MaxAudioUploads.Value = Int32.Parse(txtMaximumMP3FilesPerUser.Text); } Config.Misc.EnableProfileVideoBroadcast = cbEnableLiveWebcamVideoStreaming.Checked; Config.Misc.EnableGadgets = cbEnableGadgets.Checked; Config.Misc.StopUsersWithAdBlocker = cbEnableAdBlockerBlocker.Checked; if (cbEnableSkypeIntegration.Checked) { //create question ProfileQuestion question = new ProfileQuestion(); question.Name = "Skype"; question.AltName = String.Empty; question.Description = "Skype"; question.Hint = String.Empty; question.EditStyle = ProfileQuestion.eEditStyle.SingleLine; question.ShowStyle = ProfileQuestion.eShowStyle.SkypeLink; question.SearchStyle = ProfileQuestion.eSearchStyle.Hidden; question.Required = false; question.TopicID = 2;//hardcoded value question.Save(); } //Config.Users.EnableEcards = cbEnableECards.Checked; Config.Users.EnableFriends = cbEnableFriends.Checked; Config.Users.EnableFavorites = cbEnableFavorites.Checked; Config.Search.DistanceSearchEnabled = cbEnableDistanceSearch.Checked; #endregion #region step 3 Config.Photos.AutoApprovePhotos = !cbPhotoApprovalRequiredByAdministrator.Checked; Config.Photos.EnableExplicitPhotos = cbAllowExplicitPhotos.Checked; if (Config.Photos.EnableExplicitPhotos) { Config.Photos.MakeExplicitPhotosPrivate = cbAlwaysMakeExplicitPhotosPrivate.Checked; Config.Users.MinAgeForExplicitPhotos = Int32.Parse(txtMinimumAgeToSeeExplicitPhotos.Text); } Config.Photos.EnablePrivatePhotos = cbAllowPrivatePhotos.Checked; Config.Photos.MaxPhotos = Int32.Parse(txtMaximumPhotosPerUser.Text); Config.Users.EnableProfileComments = cbAllowUsersToCommentOnProfiles.Checked; Config.Photos.EnablePhotoComments = cbAllowUsersToCommentOnPhotos.Checked; Config.Ratings.EnableProfileRatings = cbAllowUsersToRateProfiles.Checked; Config.Ratings.EnablePhotoRatings = cbAllowUsersToRatePhotos.Checked; if (Config.Ratings.EnablePhotoRatings) { Config.Ratings.EnableRatePhotos = cbEnableHotOrNotStyle.Checked; } Config.Users.EnableUserStatusText = cbAllowUsersToSetStatus.Checked; Config.Users.EnableProfileSkins = cbAllowUsersToUseSkins.Checked; if (Config.Users.EnableProfileSkins) { billingPlanOptions.UserCanUseSkin.Value = cbAllowUsersToUseSkins.Checked; billingPlanOptions.UserCanEditSkin.Value = cbAllowUsersToCustomizeSkin.Checked; } Config.Users.EnableRelationshipStatus = cbAllowUsersToSpecifyRelationships.Checked; #endregion #region step 4 //Config.Misc.EnableSpamDetection = cbEnableSpamDetection.Checked; Config.Misc.EnableCaptcha = cbEnableCaptchaValidation.Checked; Config.Users.AutoActivateUsers = !cbRequireEmailConfirmation.Checked; Config.Misc.EnableMessageFilter = cbEnableEmailAndPhoneNumberFiltering.Checked; Config.Misc.EnableSpamDetection = cbBlockSendingMultipleSimilarMessages.Checked; if (Config.Misc.EnableSpamDetection) { Config.Misc.MaxSameMessages = Int32.Parse(txtNumberOfSimilarMessages.Text); } Config.Users.MessageVerificationEnabled = cbManuallyApproveInitialUserMessages.Checked; if (Config.Users.MessageVerificationEnabled) { Config.Users.MessageVerificationsCount = Int32.Parse(txtMessagesPerUserToBeApproved.Text); } //Config.Users.MembersMaxMessagesPerDay billingPlanOptions.MaxMessagesPerDay.Value = Int32.Parse(txtMaximumMessagesPerDay.Text); Config.Users.MaxContactedUsersPerDay = Int32.Parse(txtMaximumUsersContactedPerDay.Text); Config.AbuseReports.UserCanReportProfileAbuse = cbAllowUsersToReportProfileAbuse.Checked; Config.AbuseReports.UserCanReportPhotoAbuse = cbAllowUsersToReportPhotoAbuse.Checked; Config.AbuseReports.UserCanReportMessageAbuse = cbAllowUsersToReportMessageAbuse.Checked; #endregion Config.Users.SetNonPayingMembersOptions(billingPlanOptions); }