/// <summary> /// Gets and bulk updates polls. Called when the "Get and bulk update polls" button is pressed. /// Expects the CreatePoll method to be run first. /// </summary> private bool GetAndBulkUpdatePolls() { // Prepare the parameters string where = "PollCodeName LIKE N'MyNewPoll%'"; // Get the data DataSet polls = PollInfoProvider.GetPolls(where, null); if (!DataHelper.DataSourceIsEmpty(polls)) { // Loop through the individual items foreach (DataRow pollDr in polls.Tables[0].Rows) { // Create object from DataRow PollInfo modifyPoll = new PollInfo(pollDr); // Update the properties modifyPoll.PollDisplayName = modifyPoll.PollDisplayName.ToUpper(); // Save the changes PollInfoProvider.SetPollInfo(modifyPoll); } return(true); } return(false); }
/// <summary> /// Button OK click handler. /// </summary> protected void btnOk_Click(object sender, EventArgs e) { if (!CheckModifyPermissions()) { return; } if (poll != null) { if (radAllUsers.Checked) { poll.PollAccess = SecurityAccessEnum.AllUsers; } else if (radOnlyUsers.Checked) { poll.PollAccess = SecurityAccessEnum.AuthenticatedUsers; } else if (radGroupMembers.Checked) { poll.PollAccess = SecurityAccessEnum.GroupMembers; } else if (radOnlyRoles.Checked) { poll.PollAccess = SecurityAccessEnum.AuthorizedRoles; } PollInfoProvider.SetPollInfo(poll); ShowChangesSaved(); } else { throw new Exception("Poll with given ID not found!"); } }
/// <summary> /// Gets and updates poll. Called when the "Get and update poll" button is pressed. /// Expects the CreatePoll method to be run first. /// </summary> private bool GetAndUpdatePoll() { // Get the poll PollInfo updatePoll = PollInfoProvider.GetPollInfo("MyNewPoll", SiteContext.CurrentSiteID); if (updatePoll != null) { // Update the properties updatePoll.PollDisplayName = updatePoll.PollDisplayName.ToLower(); // Save the changes PollInfoProvider.SetPollInfo(updatePoll); return(true); } return(false); }
/// <summary> /// Creates poll. Called when the "Create poll" button is pressed. /// </summary> private bool CreatePoll() { // Create new poll object PollInfo newPoll = new PollInfo(); // Set the properties newPoll.PollDisplayName = "My new poll"; newPoll.PollCodeName = "MyNewPoll"; newPoll.PollTitle = "My title"; newPoll.PollQuestion = "My question"; newPoll.PollResponseMessage = "My response message."; newPoll.PollAllowMultipleAnswers = false; newPoll.PollAccess = 0; // Save the poll PollInfoProvider.SetPollInfo(newPoll); return(true); }
/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { if (CreateGlobal) { if (!CheckPermissions("cms.polls", PERMISSION_GLOBALMODIFY)) { return; } } else { if (!CheckPermissions("cms.polls", PERMISSION_MODIFY)) { return; } } // Generate code name in simple mode string codeName = txtCodeName.Text.Trim(); if (DisplayMode == ControlDisplayModeEnum.Simple) { codeName = ValidationHelper.GetCodeName(txtDisplayName.Text.Trim(), null, null); } // Perform validation string errorMessage = new Validator().NotEmpty(codeName, rfvCodeName.ErrorMessage) .NotEmpty(txtDisplayName.Text, rfvDisplayName.ErrorMessage).NotEmpty(txtQuestion.Text.Trim(), rfvQuestion.ErrorMessage).Result; // Check CodeName for identifier format if (!ValidationHelper.IsCodeName(codeName)) { errorMessage = GetString("General.ErrorCodeNameInIdentifierFormat"); } if (string.IsNullOrEmpty(errorMessage)) { // Create new Poll.PollAllowMultipleAnswers = false; Poll.PollAccess = SecurityAccessEnum.AllUsers; // Check if codename already exists on a group or is a global PollInfo pi; if (CreateGlobal) { pi = PollInfoProvider.GetPollInfo("." + codeName, 0); if ((pi != null) && (pi.PollSiteID <= 0)) { errorMessage = GetString("polls.codenameexists"); } } else { pi = PollInfoProvider.GetPollInfo(codeName, SiteID, GroupID); if ((pi != null) && (pi.PollSiteID > 0)) { errorMessage = GetString("polls.codenameexists"); } } if (string.IsNullOrEmpty(errorMessage)) { // Set the fields Poll.PollCodeName = codeName; Poll.PollDisplayName = txtDisplayName.Text.Trim(); Poll.PollTitle = txtTitle.Text.Trim(); Poll.PollQuestion = txtQuestion.Text.Trim(); Poll.PollLogActivity = true; if (GroupID > 0) { if (SiteID <= 0) { ShowError(GetString("polls.nositeid")); return; } Poll.PollGroupID = GroupID; Poll.PollSiteID = SiteID; } else { // Assigned poll to particular site if it is not global poll if (!CreateGlobal) { if (!PollInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Polls, ObjectActionEnum.Insert)) { LicenseError = GetString("LicenseVersion.Polls"); } else { Poll.PollSiteID = SiteID; } } } // Save the object PollInfoProvider.SetPollInfo(Poll); ItemID = Poll.PollID; // Add global poll to current site if ((SiteContext.CurrentSite != null) && CreateGlobal) { if (PollInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Polls, ObjectActionEnum.Insert)) { if ((Poll.PollGroupID == 0) && (Poll.PollSiteID == 0)) { // Bind only global polls to current site PollInfoProvider.AddPollToSite(Poll.PollID, SiteContext.CurrentSiteID); } } else { LicenseError = GetString("LicenseVersion.Polls"); } } // Redirect to edit mode if (!error) { RaiseOnSaved(); } } else { // Error message - code name already exists ShowError(GetString("polls.codenameexists")); } } if (!string.IsNullOrEmpty(errorMessage)) { // Error message - validation ShowError(errorMessage); } }
/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { if ((this.SiteID > 0) && !CheckPermissions("cms.polls", CMSAdminControl.PERMISSION_MODIFY)) { return; } if ((this.SiteID <= 0) && !CheckPermissions("cms.polls", CMSAdminControl.PERMISSION_GLOBALMODIFY)) { return; } // Get trimmed inputs string codeName = txtCodeName.Text.Trim(); string displayName = txtDisplayName.Text.Trim(); string question = txtQuestion.Text.Trim(); // Validate the fields string errorMessage = new Validator() .NotEmpty(codeName, rfvCodeName.ErrorMessage) .NotEmpty(displayName, rfvDisplayName.ErrorMessage) .NotEmpty(question, rfvQuestion.ErrorMessage) .Result; if (!ValidationHelper.IsCodeName(codeName)) { errorMessage = GetString("General.ErrorCodeNameInIdentificatorFormat"); } else { // From/to date validation if (!dtPickerOpenFrom.IsValidRange() || !dtPickerOpenTo.IsValidRange()) { errorMessage = GetString("general.errorinvaliddatetimerange"); } if (string.IsNullOrEmpty(errorMessage) && (!ValidationHelper.IsIntervalValid(dtPickerOpenFrom.SelectedDateTime, dtPickerOpenTo.SelectedDateTime, true))) { errorMessage = GetString("General.DateOverlaps"); } } if (!string.IsNullOrEmpty(errorMessage)) { // Error message - validation lblError.Visible = true; lblError.Text = errorMessage; return; } // Check uniqeness PollInfo secondPoll = null; if (this.SiteID <= 0) { // Try to find poll in global polls (leading period denotes global poll) secondPoll = PollInfoProvider.GetPollInfo("." + codeName, 0); } else { // Try to find poll in site polls secondPoll = PollInfoProvider.GetPollInfo(codeName, this.SiteID, this.GroupID); } if (secondPoll != null && (secondPoll.PollID != this.ItemID)) { // Error message - Code name already exist lblError.Visible = true; lblError.Text = GetString("polls.codenameexists"); return; } pollObj = pollObj ?? PollInfoProvider.GetPollInfo(this.ItemID); if (pollObj == null) { // Error message - Poll does not exist lblError.Visible = true; lblError.Text = GetString("polls.pollnotexist"); return; } if (pollObj.PollSiteID != this.SiteID) { throw new Exception("[PollProperties.ascx]: Wrong poll object received since SiteID parameter wasn't provided."); } // Store the fields pollObj.PollCodeName = codeName; pollObj.PollDisplayName = displayName; pollObj.PollTitle = txtTitle.Text.Trim(); pollObj.PollQuestion = question; pollObj.PollOpenFrom = dtPickerOpenFrom.SelectedDateTime; pollObj.PollOpenTo = dtPickerOpenTo.SelectedDateTime; pollObj.PollResponseMessage = txtResponseMessage.Text.Trim(); pollObj.PollAllowMultipleAnswers = chkAllowMultipleAnswers.Checked; if (plcOnline.Visible) { pollObj.PollLogActivity = chkLogActivity.Checked; } // Save the data try { PollInfoProvider.SetPollInfo(pollObj); } catch (Exception ex) { lblError.Visible = true; lblError.Text = ex.Message; return; } lblInfo.Visible = true; lblInfo.Text = GetString("General.ChangesSaved"); // Raise on saved event RaiseOnSaved(); }
/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { if (this.CreateGlobal) { if (!CheckPermissions("cms.polls", CMSAdminControl.PERMISSION_GLOBALMODIFY)) { return; } } else { if (!CheckPermissions("cms.polls", CMSAdminControl.PERMISSION_MODIFY)) { return; } } // Generate code name in simple mode string codeName = txtCodeName.Text.Trim(); if (DisplayMode == ControlDisplayModeEnum.Simple) { codeName = ValidationHelper.GetCodeName(txtDisplayName.Text.Trim(), null, null); } // Perform validation string errorMessage = new Validator().NotEmpty(codeName, rfvCodeName.ErrorMessage) .NotEmpty(txtDisplayName.Text, rfvDisplayName.ErrorMessage).NotEmpty(txtQuestion.Text.Trim(), rfvQuestion.ErrorMessage).Result; // Check CodeName for identificator format if (!ValidationHelper.IsCodeName(codeName)) { errorMessage = GetString("General.ErrorCodeNameInIdentificatorFormat"); } if (string.IsNullOrEmpty(errorMessage)) { bool isnew = false; // Create new PollInfo pollObj = new PollInfo(); pollObj.PollAllowMultipleAnswers = false; pollObj.PollAccess = SecurityAccessEnum.AllUsers; // Check if codename already exists on a group or is a global PollInfo pi = null; if (this.CreateGlobal) { pi = PollInfoProvider.GetPollInfo("." + codeName, 0); if ((pi != null) && (pi.PollSiteID <= 0)) { errorMessage = GetString("polls.codenameexists"); } } else { pi = PollInfoProvider.GetPollInfo(codeName, this.SiteID, this.GroupID); if ((pi != null) && (pi.PollSiteID > 0)) { errorMessage = GetString("polls.codenameexists"); } } if (string.IsNullOrEmpty(errorMessage)) { // Set the fields pollObj.PollCodeName = codeName; pollObj.PollDisplayName = txtDisplayName.Text.Trim(); pollObj.PollTitle = txtTitle.Text.Trim(); pollObj.PollQuestion = txtQuestion.Text.Trim(); pollObj.PollLogActivity = true; if (this.GroupID > 0) { if (this.SiteID <= 0) { lblError.Text = GetString("polls.nositeid"); lblError.Visible = true; return; } pollObj.PollGroupID = this.GroupID; pollObj.PollSiteID = this.SiteID; } else { // Assigned poll to particular site if it is not global poll if (!this.CreateGlobal) { if (!PollInfoProvider.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Polls, VersionActionEnum.Insert)) { this.LicenseError = GetString("LicenseVersion.Polls"); } else { pollObj.PollSiteID = this.SiteID; } } } // Save the object PollInfoProvider.SetPollInfo(pollObj); this.ItemID = pollObj.PollID; isnew = true; // Add global poll to current site if ((CMSContext.CurrentSite != null) && this.CreateGlobal) { if (PollInfoProvider.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Polls, VersionActionEnum.Insert)) { if ((pollObj.PollGroupID == 0) && (pollObj.PollSiteID == 0)) { // Bind only global polls to current site PollInfoProvider.AddPollToSite(pollObj.PollID, CMSContext.CurrentSiteID); } } else { this.LicenseError = GetString("LicenseVersion.Polls"); } } // Redirect to edit mode if ((isnew) && (!lblError.Visible)) { RaiseOnSaved(); } } else { // Error message - code name already exists lblError.Visible = true; lblError.Text = GetString("polls.codenameexists"); } } if (!string.IsNullOrEmpty(errorMessage)) { // Error message - validation lblError.Visible = true; lblError.Text = errorMessage; } }