protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                return;
            }

            var fetch = new Fetch
            {
                Entity = new FetchEntity("adx_poll")
                {
                    Filters = new[]
                    {
                        new Filter
                        {
                            Conditions =
                                new[]
                            {
                                new Condition("adx_websiteid", ConditionOperator.Equal, Website.Id),
                                new Condition("adx_expirationdate", ConditionOperator.LessEqual, DateTime.UtcNow)
                            }
                        }
                    }
                }
            };

            var polls = PortalOrganizationService.RetrieveMultiple(fetch).Entities;

            PollsArchiveListView.DataSource = polls;
            PollsArchiveListView.DataBind();
        }
        protected void PollsArchiveListView_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            var listItem = e.Item as ListViewDataItem;

            if (listItem == null || listItem.DataItem == null)
            {
                return;
            }

            var poll = listItem.DataItem as Entity;

            var listView   = (ListView)e.Item.FindControl("PollResponsesListView");
            var totalLabel = (System.Web.UI.WebControls.Label)e.Item.FindControl("Total");

            var fetch = new Fetch
            {
                Entity = new FetchEntity("adx_polloption")
                {
                    Filters = new[]
                    {
                        new Filter
                        {
                            Conditions =
                                new[]
                            {
                                new Condition("adx_pollid", ConditionOperator.Equal, poll.Id)
                            }
                        }
                    }
                }
            };

            var pollResponses = PortalOrganizationService.RetrieveMultiple(fetch).Entities.ToList();

            var totalVotes = pollResponses.Sum(p => p.GetAttributeValue <int?>("adx_votes").GetValueOrDefault(0));

            totalLabel.Text = totalVotes.ToString(CultureInfo.InvariantCulture);

            if (totalVotes <= 0)
            {
                return;
            }

            var results = from response in pollResponses
                          select new
            {
                Response   = response.GetAttributeValue <string>("adx_answer"),
                Count      = response.GetAttributeValue <int?>("adx_votes").GetValueOrDefault(0),
                Percentage = Convert.ToInt32((response.GetAttributeValue <int?>("adx_votes").GetValueOrDefault(0)) / ((float)totalVotes) * (100))
            };

            listView.DataSource = results;

            listView.DataBind();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            RedirectToLoginIfAnonymous();

            if (ForceRegistration && !ServiceContext.ValidateProfileSuccessfullySaved(Contact))
            {
                MissingFieldsMessage.Visible = true;
            }

            if (ShowMarketingOptionsPanel)
            {
                MarketingOptionsPanel.Visible = true;
            }

            ProfileDataSource.FetchXml       = _userFetchXmlFormat.FormatWith(Contact.Id);
            ProfileDataSource.IsSingleSource = true;

            ProfileAlertInstructions.Visible = Contact.GetAttributeValue <bool?>("adx_profilealert") ?? false;

            if (Session[ConfirmationOneTimeMessageSessionKey] != null)
            {
                ConfirmationMessage.Visible = true;
                Session.Remove(ConfirmationOneTimeMessageSessionKey);
            }

            if (IsPostBack)
            {
                return;
            }

            var contact = !Contact.Contains("donotemail") || !Contact.Contains("donotfax") || !Contact.Contains("donotphone") || !Contact.Contains("donotpostalmail")
                                ? PortalOrganizationService.RetrieveSingle(
                "contact",
                new[] { "donotemail", "donotfax", "donotphone", "donotpostalmail" },
                new[] {
                new Condition("statecode", ConditionOperator.Equal, 0),
                new Condition("contactid", ConditionOperator.Equal, Contact.Id)
            })
                                : Contact;

            if (contact == null)
            {
                throw new ApplicationException(string.Format("Couldn't retrieve contact record with contactid equal to {0}.", Contact.Id));
            }

            if (ShowMarketingOptionsPanel)
            {
                marketEmail.Checked = !contact.GetAttributeValue <bool>("donotemail");
                marketFax.Checked   = !contact.GetAttributeValue <bool>("donotfax");
                marketPhone.Checked = !contact.GetAttributeValue <bool>("donotphone");
                marketMail.Checked  = !contact.GetAttributeValue <bool>("donotpostalmail");
            }

            PopulateMarketingLists();
        }
        public bool IsListChecked(object listoption)
        {
            var list = (Entity)listoption;

            if (Request.IsAuthenticated)
            {
                var lists = PortalOrganizationService.RetrieveRelatedEntities(this.Contact, "listcontact_association").Entities;

                return(lists.Any(l => l.GetAttributeValue <Guid>("listid") == list.Id));
            }

            return(false);
        }
Exemplo n.º 5
0
        protected void Page_Init(object sender, EventArgs args)
        {
            if (!System.Web.SiteMap.Enabled)
            {
                return;
            }

            var currentNode = System.Web.SiteMap.CurrentNode;

            if (currentNode == null)
            {
                return;
            }

            var templateIdString = currentNode["adx_webtemplateid"];

            if (string.IsNullOrEmpty(templateIdString))
            {
                return;
            }

            Guid templateId;

            if (!Guid.TryParse(templateIdString, out templateId))
            {
                return;
            }

            var fetch = new Fetch
            {
                Entity = new FetchEntity("adx_webtemplate")
                {
                    Attributes = new[] { new FetchAttribute("adx_source"), new FetchAttribute("adx_mimetype") },
                    Filters    = new[]
                    {
                        new Filter
                        {
                            Conditions = new[]
                            {
                                new Condition("adx_webtemplateid", ConditionOperator.Equal, templateId),
                                new Condition("statecode", ConditionOperator.Equal, 0)
                            }
                        }
                    }
                }
            };

            var webTemplate = PortalOrganizationService.RetrieveSingle(fetch);

            if (webTemplate == null)
            {
                return;
            }

            var source = webTemplate.GetAttributeValue <string>("adx_source");

            using (var output = new System.IO.StringWriter())
            {
                Html.RenderLiquid(source, string.Format("{0}:{1}", webTemplate.LogicalName, webTemplate.Id), output);
                Liquid.Html = output.ToString();
            }

            var mimetype = webTemplate.GetAttributeValue <string>("adx_mimetype");

            if (!string.IsNullOrWhiteSpace(mimetype))
            {
                ContentType = mimetype;
            }
        }