/// <summary> /// Saves current newsletter settings. /// </summary> public bool SaveIssue() { try { switch (CurrentState) { case STATE_WAITING_TO_SEND_PAGE: case STATE_WAITING_TO_SEND_WIZARD: case STATE_TEST_READY_FOR_SENDING: case STATE_TEST_WAITING_TO_SEL_WINNER: if (abTest == null) { abTest = ABTestInfoProvider.GetABTestInfoForIssue(parentIssue.IssueID); } // Get A/B test settings from controls bool abTestChanged = SaveABTestInfo(abTest); if (abTest == null) { return(false); } if (abTest.TestWinnerOption != ABTestWinnerSelectionEnum.Manual) { // Check minimal time interval if (abTest.TestSelectWinnerAfter < 5) { ErrorMessage = GetString("newsletterissue_send.saveissuewrongwinnerselectioninterval"); return(false); } } // Check if test options has changed if (abTestChanged) { if (abTest.TestWinnerIssueID > 0) { // Options has been changed => reset previously selected winner IssueInfoProvider.DeleteMailoutTask(parentIssue.IssueGUID, parentIssue.IssueSiteID); abTest.TestWinnerIssueID = 0; abTest.TestWinnerSelected = DateTimeHelper.ZERO_TIME; // Hide/reload winner selection in issue mail-out grid ucMailout.ReloadData(false); } IssueInfoProvider.SetIssueInfo(parentIssue); } ABTestInfoProvider.SetABTestInfo(abTest); IssueHelper.EnsureWinnerSelectionTask(abTest, parentIssue, (CurrentState == STATE_TEST_WAITING_TO_SEL_WINNER), ucMailout.HighestMailoutTime); // Update info message for parent control int currentState = GetCurrentState(parentIssue); InfoMessage = GetInfoMessage(currentState, parentIssue, abTest.TestWinnerOption, GetPlannedMailoutTime(ucMailout.HighestMailoutTime)); return(true); case STATE_TEST_FINISHED: ErrorMessage = GetString("newsletterissue_send.saveissuehasbeensent"); break; } } catch (Exception e) { ErrorMessage = e.Message; return(false); } return(true); }
protected void btnSend_Click(object sender, EventArgs e) { // Validate date/time (blank date/time textbox is allowed) if ((dtpMailout.SelectedDateTime == DateTimeHelper.ZERO_TIME) && !String.IsNullOrEmpty(dtpMailout.DateTimeTextBox.Text.Trim())) { ShowError(GetString("newsletterissue_send.invaliddatetime")); return; } IssueInfo winner = (IssueInfo)EditedObject; int parentIssueId = winner.IssueVariantOfIssueID; // Get A/B test info ABTestInfo abi = ABTestInfoProvider.GetABTestInfoForIssue(parentIssueId); if (abi != null) { IssueInfo issue = IssueInfoProvider.GetIssueInfo(parentIssueId); // Check if winner was selected and sent if (abi.TestWinnerIssueID != 0) { if ((issue.IssueStatus == IssueStatusEnum.Finished) || (issue.IssueStatus == IssueStatusEnum.Sending)) { // Winner was already sent CloseDialogAndRefreshParent(); return; } } // Update A/B test info and winner selection task (if exist) abi.TestWinnerOption = ABTestWinnerSelectionEnum.Manual; IssueHelper.EnsureWinnerSelectionTask(abi, issue, false); abi.TestSelectWinnerAfter = 0; abi.TestWinnerSelected = DateTime.Now; abi.TestWinnerIssueID = winner.IssueID; ABTestInfoProvider.SetABTestInfo(abi); if ((issue != null) && (winner != null)) { // Copy data from winner to parent IssueHelper.CopyIssueProperties(winner, issue, "issuesubject;issuetext;issuetemplateid;issueshowinnewsletterarchive;issuesendername;issuesenderemail"); IssueInfoProvider.SetIssueInfo(issue); // Remove previous scheduled task of this issue IssueInfoProvider.DeleteMailoutTask(issue.IssueGUID, issue.IssueSiteID); DateTime mailoutTime = dtpMailout.SelectedDateTime; if (mailoutTime < DateTime.Now) { // Send parent issue now IssueInfoProvider.SendIssue(parentIssueId, DateTime.Now); } else { // Send winner at specified time IssueInfoProvider.SendIssue(parentIssueId, mailoutTime); } } } // Close dialog and refresh parent page CloseDialogAndRefreshParent(); }