protected void btnSend_Click(object sender, EventArgs e) { // Validate date/time if (dtpMailout.SelectedDateTime == DateTimeHelper.ZERO_TIME) { 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; NewsletterTasksManager.EnsureWinnerSelectionTask(abi, issue, false, DateTime.Now); abi.TestSelectWinnerAfter = 0; abi.TestWinnerSelected = DateTime.Now; abi.TestWinnerIssueID = winner.IssueID; ABTestInfoProvider.SetABTestInfo(abi); if ((issue != null) && (winner != null)) { var parentIssue = IssueInfoProvider.GetIssueInfo(parentIssueId); NewsletterSendingStatusModifier.ResetAllEmailsInQueueForIssue(parentIssue.IssueID); // Copy data from winner to parent IssueHelper.CopyWinningVariantIssueProperties(winner, issue); IssueInfoProvider.SetIssueInfo(issue); // Remove previous scheduled task of this issue NewsletterTasksManager.DeleteMailoutTask(issue.IssueGUID, issue.IssueSiteID); DateTime mailoutTime = dtpMailout.SelectedDateTime; Service.Resolve <IIssueScheduler>().ScheduleIssue(parentIssue, mailoutTime); } } // Close dialog and refresh parent page CloseDialogAndRefreshParent(); }
private void CopyDataFromWinnerToParent(IssueInfo winner, IssueInfo parent) { IssueHelper.CopyWinningVariantIssueProperties(winner, parent); IssueInfo.Provider.Set(parent); }