Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pollId"></param>
        /// <param name="pollChoiceId"></param>
        public void AnswerPoll(long pollId, long pollChoiceId)
        {
            awPollChoice choice = (from l in _context.awPollChoices
                                   where l.pollId.Equals(pollId) && l.pollChoiceId.Equals(pollChoiceId) &&
                                   l.awPoll.isEnabled && l.awPoll.awSite_Poll.isEnabled
                                   select l).FirstOrDefault <awPollChoice>();

            if (choice == null)
            {
                throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.POLL.DOES_NOT_EXIST));
            }

            int dateBetween = MiscLibrary.IsDateBetween(DateTime.Now,
                                                        choice.awPoll.pubDate,
                                                        choice.awPoll.pubEndDate);

            switch (dateBetween)
            {
            case -1:
                throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.POLL.NOT_PUBLISHED));
                break;

            case 0:
                throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.POLL.EXPIRED));
                break;
            }

            choice.numberOfVotes += 1;
            choice.lastBuildDate  = DateTime.Now;

            _context.SubmitChanges();
        }
Beispiel #2
0
        /// <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);
        }