Exemple #1
0
 private void btnActivateDeactivate_Click(object sender, EventArgs e)
 {
     Poll poll = new Poll(new Guid(btnActivateDeactivate.CommandArgument));
     if (btnActivateDeactivate.CommandName == "Activate")
     {
         poll.Activate();
         poll.Save();
         WebUtils.SetupRedirect(this,
             SiteRoot + "/Poll/PollEdit.aspx?PollGuid=" + pollGuid.ToString()
             + "&pageid=" + pageId.ToInvariantString()
             + "&mid=" + moduleId.ToInvariantString()
             );
     }
     else if (btnActivateDeactivate.CommandName == "Deactivate")
     {
         poll.Deactivate();
         poll.Save();
         WebUtils.SetupRedirect(this,
             SiteRoot + "/Poll/PollEdit.aspx?PollGuid=" + pollGuid.ToString()
             + "&pageid=" + pageId.ToInvariantString()
             + "&mid=" + moduleId.ToInvariantString()
             );
     }
 }
Exemple #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Page.Validate("poll");
            if (Page.IsValid)
            {
                Poll poll = new Poll(pollGuid);
                poll.SiteGuid = siteSettings.SiteGuid;
                poll.Question = txtQuestion.Text;
                poll.AnonymousVoting = chkAnonymousVoting.Checked;
                poll.AllowViewingResultsBeforeVoting = chkAllowViewingResultsBeforeVoting.Checked;
                poll.ShowOrderNumbers = chkShowOrderNumbers.Checked;
                poll.ShowResultsWhenDeactivated = chkShowResultsWhenDeactivated.Checked;

                if (dpActiveFrom.Text.Length > 0 && poll.ActiveFrom >= DateTime.UtcNow)
                {
                    // You can't change date if poll has started.

                    // TODO: promt user if invalid format/date

                    DateTime activeFrom;
                    DateTime.TryParse(dpActiveFrom.Text, out activeFrom);

                    if (timeZone != null)
                    {
                        activeFrom = activeFrom.ToUtc(timeZone);
                    }
                    else
                    {
                        activeFrom = activeFrom.AddHours(-timeOffset);
                    }

                    poll.ActiveFrom = activeFrom;
                }

                if (dpActiveTo.Text.Length > 0)
                {
                    // TODO: promt user if invalid format/date
                    DateTime activeTo;
                    DateTime.TryParse(dpActiveTo.Text, out activeTo);

                    if (timeZone != null)
                    {
                        activeTo = activeTo.ToUtc(timeZone);
                    }
                    else
                    {
                        activeTo = activeTo.AddHours(-timeOffset);
                    }

                    // Make time 23:59:59
                    //activeTo = activeTo.AddHours(23).AddMinutes(59).AddSeconds(59);

                    // You can't change to past date.
                    if (activeTo >= DateTime.UtcNow)
                    {
                        poll.ActiveTo = activeTo;
                    }
                }

                if (chkStartDeactivated.Checked)
                {
                    // This only happens when new poll.
                    poll.Deactivate();
                }
                else
                {
                    poll.Activate();
                }

                poll.Save();

                // Get options
                PollOption option;
                int order = 1;
                foreach (ListItem item in lbOptions.Items)
                {
                    if (item.Text == item.Value)
                    {
                        option = new PollOption();
                    }
                    else
                    {
                        if (item.Value.Length == 36)
                        {
                            option = new PollOption(new Guid(item.Value));
                        }
                        else
                        {
                            option = new PollOption();
                        }
                    }

                    option.PollGuid = poll.PollGuid;
                    option.Answer = item.Text;
                    option.Order = order++;
                    option.Save();
                }

                WebUtils.SetupRedirect(this,
                    SiteRoot + "/Poll/PollChoose.aspx"
                    + "?pageid=" + pageId.ToInvariantString()
                    + "&mid=" + moduleId.ToInvariantString()
                    );

            }
        }