void PopulatePoll(Int64 blogId, string cultureCode) { ResetControls(); //set the default culture code if it is emmpty if (String.IsNullOrEmpty(cultureCode) && //culture code is null _culture.Items.FindByValue(App_Code.SessionInfo.CurrentSite.cultureCode) != null) //session culture code exists in the list { _culture.SelectedValue = App_Code.SessionInfo.CurrentSite.cultureCode; } AWAPI_Data.CustomEntities.PollExtended poll = _pollLibrary.GetPoll(blogId, cultureCode, false); if (poll == null) { return; } _id.Text = poll.pollId.ToString(); _title.Text = poll.title; _description.Text = poll.description; _answeredQuestion.Text = poll.answeredQuestion; _isEnabled.Checked = poll.isEnabled; //_isPublic.Checked = poll.isPublic; _isMultipleChoice.Checked = poll.isMultipleChoice; if (poll.pubDate != null) { _publishStartDate.Text = poll.pubDate.Value.ToString("MM/dd/yyyy HH:mm"); } //if (poll.pubEndDate != null) _publishEndDate.Text = poll.pubEndDate.Value.ToString("MM/dd/yyyy HH:mm"); PopulateChoiceList(); ShowHideControls(true); }
/// <summary> /// /// </summary> /// <param name="blogid"></param> /// <param name="cultureCode"></param> void GetPoll(long pollId, string cultureCode) { AWAPI_Data.CustomEntities.PollExtended poll = _pollLib.GetPoll(pollId, cultureCode, true); if (poll == null || poll.siteId != _site.siteId || !poll.isEnabled) { return; } List <SyndicationItem> items = new List <SyndicationItem>(); SyndicationItem blogitem = CreatePollSyndicationItem(poll, cultureCode); items.Add(blogitem); _feed.Items = items; }
/// <summary> /// Returns poll based on the culturecode /// </summary> /// <param name="pollId"></param> /// <param name="cultureCode"></param> /// <returns></returns> public AWAPI_Data.CustomEntities.PollExtended GetPoll(long pollId, string cultureCode, bool onlyPublished) { if (pollId <= 0) { return(null); } DateTime now = DateTime.Now; AWAPI_Data.CustomEntities.PollExtended poll = (from l in _context.awPolls where l.pollId.Equals(pollId) && (!onlyPublished || (onlyPublished && l.isEnabled && l.awSite_Poll.isEnabled)) select new AWAPI_Data.CustomEntities.PollExtended { pollId = l.pollId, title = l.title, description = l.description, answeredQuestion = l.answeredQuestion, isEnabled = l.isEnabled, isPublic = l.isPublic, isMultipleChoice = l.isMultipleChoice, siteId = l.siteId, userId = l.userId, pubDate = l.pubDate, pubEndDate = l.pubEndDate, createDate = l.createDate, lastBuildDate = l.lastBuildDate, availableToVote = ((l.pubDate.Equals(null) || l.pubDate <= now) && (l.pubEndDate.Equals(null) || l.pubEndDate > now)) ? true : false, pollChoices = this.GetPollChoiceList(l.pollId, cultureCode), siteCultureCode = l.awSite_Poll.cultureCode }).FirstOrDefault <AWAPI_Data.CustomEntities.PollExtended>(); //if (list == null && list.ToList().Count() == 0) // return null; //AWAPI_Data.CustomEntities.PollExtended poll = list.FirstOrDefault(); if (poll == null) { return(null); } if (onlyPublished) { // if not published yet.... int dateBetween = MiscLibrary.IsDateBetween(DateTime.Now, poll.pubDate, poll.pubEndDate); if (dateBetween == 0) { return(null); } //throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.POLL.NOT_PUBLISHED)); } //if site's culture code equals to cultureCode parameter if (String.IsNullOrEmpty(cultureCode) || poll.siteCultureCode.ToLower() == cultureCode.ToLower()) { return(poll); } poll.description = _cultureLib.GetValue(cultureCode.ToLower(), poll.pollId, "awpoll", "description"); poll.answeredQuestion = _cultureLib.GetValue(cultureCode.ToLower(), poll.pollId, "awpoll", "answeredQuestion"); return(poll); }
/// <summary> /// /// </summary> /// <param name="content"></param> /// <returns></returns> SyndicationItem CreatePollSyndicationItem(AWAPI_Data.CustomEntities.PollExtended poll, string cultureCode) { Uri uri = null; int totalVotes = 0; //SyndicationItem item = new SyndicationItem( // String.IsNullOrEmpty(poll.title) ? "" : AWAPI_Common.library.MiscLibrary.AddCDATA(poll.title), // String.IsNullOrEmpty(poll.description) ? "" : AWAPI_Common.library.MiscLibrary.AddCDATA(poll.description), // uri, // poll.pollId.ToString(), // poll.lastBuildDate.Value); SyndicationItem item = new SyndicationItem(); item.Title = String.IsNullOrEmpty(poll.title) ? null : new TextSyndicationContent(poll.title, TextSyndicationContentKind.Html); item.Content = String.IsNullOrEmpty(poll.description) ? null : new TextSyndicationContent(poll.description, TextSyndicationContentKind.Html); item.LastUpdatedTime = poll.lastBuildDate.Value; item.BaseUri = uri; item.Id = poll.pollId.ToString(); item.ElementExtensions.Add("pollid", null, poll.pollId); if (!string.IsNullOrEmpty(poll.answeredQuestion)) { item.ElementExtensions.Add("answeredquestion", null, AWAPI_Common.library.MiscLibrary.EncodeHtml(poll.answeredQuestion)); } item.ElementExtensions.Add("ismultiplechoice", null, poll.isMultipleChoice); if (poll.pubDate != null) { item.ElementExtensions.Add("pubdate", null, poll.pubDate); } IList <AWAPI_Data.CustomEntities.PollChoiceExtended> choiceList = _pollLib.GetPollChoiceList(poll.pollId, CultureCode); if (choiceList != null && choiceList.Count > 0) { foreach (AWAPI_Data.CustomEntities.PollChoiceExtended choice in choiceList) { totalVotes += choice.numberOfVotes; } foreach (AWAPI_Data.CustomEntities.PollChoiceExtended choice in choiceList) { double percentage = 0; if (totalVotes > 0) { percentage = choice.numberOfVotes * 100 / totalVotes; } SyndicationCategory cat = new SyndicationCategory(); cat.AttributeExtensions.Add(new XmlQualifiedName("name"), "choices"); cat.AttributeExtensions.Add(new XmlQualifiedName("pollid"), choice.pollId.ToString()); cat.AttributeExtensions.Add(new XmlQualifiedName("pollchoiceid"), choice.pollChoiceId.ToString()); cat.AttributeExtensions.Add(new XmlQualifiedName("title"), AWAPI_Common.library.MiscLibrary.EncodeHtml(choice.title)); cat.AttributeExtensions.Add(new XmlQualifiedName("description"), AWAPI_Common.library.MiscLibrary.EncodeHtml(choice.description)); cat.AttributeExtensions.Add(new XmlQualifiedName("numberofvotes"), choice.numberOfVotes.ToString()); cat.AttributeExtensions.Add(new XmlQualifiedName("voteratio"), Convert.ToInt32(percentage).ToString()); item.Categories.Add(cat); } } item.ElementExtensions.Add("totalvotes", null, totalVotes); return(item); }