Esempio n. 1
0
        //----------------------------------------------------------------------

        public static String GetRealExpiryDate(PollBase poll)
        {
            DateTime expiryDate = poll.ExpiryDate;
            DateTime created    = poll.Created;

            if (cvt.IsDayEqual(expiryDate, created))
            {
                return("");
            }

            TimeSpan span        = expiryDate.Date.Subtract(DateTime.Now.Date);
            int      leavingDays = span.Days;

            if (leavingDays <= 0)
            {
                return(lang.get("pollEnd"));
            }
            if (leavingDays == 1)
            {
                return(lang.get("pollEndToday"));
            }
            if (leavingDays == 2)
            {
                return(lang.get("pollEndTomorrow"));
            }

            return(string.Format(lang.get("pollEndDays"), expiryDate.ToShortDateString(), leavingDays));
        }
Esempio n. 2
0
        private String getMsg(PollBase poll)
        {
            String expiryDateInfo = PollUtil.GetRealExpiryDate(poll);

            //ForumBoard fb = ctx.getItems( "forumBoard" ) as ForumBoard;
            //Boolean isModerator = fb == null ? true : moderatorService.IsModerator( fb, (User)ctx.viewer.obj );

            Boolean isOpen = false;

            if ((poll.IsOpenVoter == 0) || ((poll.IsOpenVoter == 1) && isModerator()))
            {
                isOpen = true;
            }


            String voteInfo = string.Empty;
            String vstr     = lang.get("pollAllVoter");

            if (!isOpen)
            {
                voteInfo = vstr.Replace("{0}", "<span id='voterCount'>" + poll.VoteCount + "</span>");
            }
            else
            {
                String lnkView = string.Format("<a href=\"{1}\" id=\"pollVoterList\" class=\"frmBox\"><span id=\"voterCount\">{0}</span></a>", poll.VoteCount, lnkVoter);
                voteInfo = vstr.Replace("{0}", lnkView);
            }

            return(expiryDateInfo + voteInfo);
        }
Esempio n. 3
0
 public PollViewFactory(User viewer, PollBase poll, String postLink, String lnkVoter)
 {
     this.user     = viewer;
     this.poll     = poll;
     this.postLink = postLink;
     this.lnkVoter = lnkVoter;
 }
Esempio n. 4
0
        public OptionResult(PollBase poll, int optionCount, int optionIndex)
        {
            string[] arrGuestResults  = getResults(poll.AnonymousResult, optionCount);
            string[] arrMemberResults = getResults(poll.MemberResult, optionCount);

            // 100%时候的宽度
            int imgWidth = 200;

            int currentItemVotes = cvt.ToInt(arrGuestResults[optionIndex]) + cvt.ToInt(arrMemberResults[optionIndex]);

            double percent = ((double)currentItemVotes) / ((double)poll.GetTotalVotes());

            percent  = Math.Round(percent, 2);
            imgWidth = (int)(imgWidth * percent);

            if (imgWidth == 0)
            {
                imgWidth = 1;
            }

            this.ImgWidth        = imgWidth;
            this.Votes           = currentItemVotes;
            this.Percent         = Convert.ToString((double)(percent * 100.0));
            this.VotesAndPercent = Votes + "(" + Percent + "%)";
        }
Esempio n. 5
0
        private String getSubmit(PollBase poll)
        {
            String voteLink = postLink;

            Boolean hasVote = checkHasVote();

            Html html = new Html();

            if (!user.IsRegisterUser)
            {
                html.Code("<input type=button disabled=disabled value=\"" + lang.get("pollLoginRequire") + "\" />");
            }
            else if (hasVote)
            {
                html.Code("<input type=button disabled=disabled value=\"" + lang.get("pollVoted") + "\" />");
            }
            else
            {
                html.Code("<input id=\"btnPoll\" class=\"btn\" type=button value=\" " + lang.get("pollVote") + " \" />");
            }
            if (!(hasVote || (poll.IsVisible != 1)))
            {
                html.Code(" <span class='red font12'>[" + lang.get("pollViewTip") + "]</span>");
            }

            String js = getAjaxJs(voteLink, lang.get("pollSelectRequire"), lang.get("pollVoted"));

            html.Code(js);

            return(html.ToString());
        }
Esempio n. 6
0
 public PollViewFactory( User viewer, PollBase poll, String postLink, String lnkVoter )
 {
     this.user = viewer;
     this.poll = poll;
     this.postLink = postLink;
     this.lnkVoter = lnkVoter;
 }
Esempio n. 7
0
        public String GetViewById(int topicId, String typeFullName, MvcContext ctx)
        {
            PollBase poll = getByTopic(topicId);

            ctx.SetItem("poll", poll);

            return(ctx.controller.loadHtml(new PollController().Detail));
        }
Esempio n. 8
0
        public static Boolean IsClosed( PollBase poll ) {
            DateTime expiryDate = poll.ExpiryDate;
            DateTime created = poll.Created;

            if (cvt.IsDayEqual( expiryDate, created )) return false;

            TimeSpan span = expiryDate.Date.Subtract( DateTime.Now.Date );
            int leavingDays = span.Days + 1;

            if (leavingDays <= 0) return true;
            return false;
        }
        public String GetViewById(int topicId, String typeFullName, MvcContext ctx)
        {
            User viewer = ctx.viewer.obj as User;

            PollBase poll    = getByTopic(topicId);
            int      boardId = getBoard(topicId);

            String lnkVote  = ctx.GetLink().To(new wojilu.Web.Controller.Forum.Users.PollController().Vote, poll.Id) + "?boardId=" + boardId;
            String lnkVoter = ctx.GetLink().To(new wojilu.Web.Controller.Forum.Users.PollController().Voter, poll.Id) + "?boardId=" + boardId;


            return(new PollViewFactory(viewer, poll, lnkVote, lnkVoter).GetPollView().GetBody(false));
        }
Esempio n. 10
0
 public static List<PollViewItem> GetPollViewItems( PollBase poll )
 {
     string[] optionList = poll.OptionList;
     List<PollViewItem> list = new List<PollViewItem>();
     for (int i = 0; i < optionList.Length; i++) {
         PollViewItem item = new PollViewItem();
         item.SetPoll( poll );
         item.SetOptionString( optionList[i] );
         item.SetOptionIndex( i );
         item.SetOptionCount( optionList.Length );
         item.Init();
         list.Add( item );
     }
     return list;
 }
Esempio n. 11
0
 public async Task<bool> AssociatePicturesWithPoll<TQuestion>(PollBase<TQuestion> pollBase,PicturesAssociateMode mode) where TQuestion:Question
 {
     var pollId = pollBase.Id;
     var resultsTasks = pollBase.Questions.Select(async question =>
     {
         var questionResultsTasks = question.AnswerOptions!=null?
             question.AnswerOptions.Select(async option =>
             option.PictureId != null ? await UpdatePictureMetadataAsync(option.PictureId, pollId, mode) : null).ToList()
             :new List<Task<UpdateResult>>();
         var questionResults = (await Task.WhenAll(questionResultsTasks)).ToList();
         questionResults.Add(question?.PictureId != null ? await UpdatePictureMetadataAsync(question.PictureId, pollId, mode) : null);
         return questionResults;
     });
     var results=(await Task.WhenAll(resultsTasks)).SelectMany(list=>list).ToList();
     return results.Where(result=>result!=null).All(result => result.ModifiedCount == 1);
 }
Esempio n. 12
0
        public static String GetRealExpiryDate( PollBase poll )
        {
            DateTime expiryDate = poll.ExpiryDate;
            DateTime created = poll.Created;

            if (cvt.IsDayEqual( expiryDate, created )) return "";

            TimeSpan span = expiryDate.Date.Subtract( DateTime.Now.Date );
            int leavingDays = span.Days + 1;

            if (leavingDays <= 0) return lang.get( "pollEnd" );
            if (leavingDays == 1) return lang.get( "pollEndToday" );
            if (leavingDays == 2) return lang.get( "pollEndTomorrow" );

            return string.Format( lang.get( "pollEndDays" ), expiryDate.ToShortDateString(), leavingDays );
        }
Esempio n. 13
0
        public AnswersUnitValidatorFromData(PollBase <TQuestion> pollBase)
        {
            ValidatorOptions.LanguageManager.Culture = new CultureInfo("en-US");

            RuleFor(answersUnit => answersUnit.PollBaseId).Must(_ => pollBase != null).WithMessage("PollBase with this Id does not exist");

            if (pollBase != null)
            {
                RuleFor(answersUnit => answersUnit.AnswerDate).Must(_ => DateTime.Now <= pollBase.ExpireDate).WithMessage("This poll is expired");

                RuleFor(answersUnit => answersUnit.AnswerDate).Must(_ => DateTime.Now > pollBase.StartDate).WithMessage("This poll is not yet started");

                RuleForEach(answersUnit => answersUnit.Answers)
                .Must(answer => pollBase.Questions.Select(q => q.Id).Contains(answer.QuestionId))
                .WithMessage("PollQuestion with this Id does not exist");
            }
        }
Esempio n. 14
0
        public static List <PollViewItem> GetPollViewItems(PollBase poll)
        {
            string[]            optionList = poll.OptionList;
            List <PollViewItem> list       = new List <PollViewItem>();

            for (int i = 0; i < optionList.Length; i++)
            {
                PollViewItem item = new PollViewItem();
                item.SetPoll(poll);
                item.SetOptionString(optionList[i]);
                item.SetOptionIndex(i);
                item.SetOptionCount(optionList.Length);
                item.Init();
                list.Add(item);
            }
            return(list);
        }
Esempio n. 15
0
        public String GetViewById(int pollId, String typeFullName, MvcContext ctx)
        {
            User viewer = ctx.viewer.obj as User;

            int sectionId = (int)ctx.GetItem("sectionId");

            PollBase poll = getByTopic(pollId);

            if (poll == null)
            {
                throw new NullReferenceException(lang.get("exPollNotFound"));
            }
            String lnkVote  = ctx.GetLink().To(new wojilu.Web.Controller.Content.Section.PollController().Vote, poll.Id) + "?sectionId=" + sectionId;
            String lnkVoter = ctx.GetLink().To(new wojilu.Web.Controller.Content.Section.PollController().Voter, poll.Id) + "?sectionId=" + sectionId;


            return(new PollViewFactory(viewer, poll, lnkVote, lnkVoter).GetPollView().GetBody(false));
        }
Esempio n. 16
0
        public static Boolean IsClosed(PollBase poll)
        {
            DateTime expiryDate = poll.ExpiryDate;
            DateTime created    = poll.Created;

            if (cvt.IsDayEqual(expiryDate, created))
            {
                return(false);
            }

            TimeSpan span        = expiryDate.Date.Subtract(DateTime.Now.Date);
            int      leavingDays = span.Days + 1;

            if (leavingDays <= 0)
            {
                return(true);
            }
            return(false);
        }
Esempio n. 17
0
        public PollHelper( PollBase poll, int optionCount, int optionIndex )
        {
            string[] arrGuestResults = getResults( poll.AnonymousResult, optionCount );
            string[] arrMemberResults = getResults( poll.MemberResult, optionCount );

            // 100%时候的宽度
            int imgWidth = 200;

            int currentItemVotes = cvt.ToInt( arrGuestResults[optionIndex] ) + cvt.ToInt( arrMemberResults[optionIndex] );

            double percent = poll.GetMemberVotes() == 0 ? 0 : ((double)currentItemVotes) / ((double)poll.GetMemberVotes());

            percent = Math.Round( percent, 2 );
            imgWidth = (int)(imgWidth * percent);

            this.ImgWidth = imgWidth;
            this.Votes = currentItemVotes;
            this.Percent = Convert.ToString( (double)(percent * 100.0) );
            this.VotesAndPercent = Votes + "<span class=\"poll-option-percent\">(" + Percent + "%)</span>";
        }
Esempio n. 18
0
        public PollHelper(PollBase poll, int optionCount, int optionIndex)
        {
            string[] arrGuestResults  = getResults(poll.AnonymousResult, optionCount);
            string[] arrMemberResults = getResults(poll.MemberResult, optionCount);

            // 100%时候的宽度
            int imgWidth = 200;

            int currentItemVotes = cvt.ToInt(arrGuestResults[optionIndex]) + cvt.ToInt(arrMemberResults[optionIndex]);

            double percent = poll.GetMemberVotes() == 0 ? 0 : ((double)currentItemVotes) / ((double)poll.GetMemberVotes());

            percent  = Math.Round(percent, 2);
            imgWidth = (int)(imgWidth * percent);

            this.ImgWidth        = imgWidth;
            this.Votes           = currentItemVotes;
            this.Percent         = Convert.ToString((double)(percent * 100.0));
            this.VotesAndPercent = Votes + "<span class=\"poll-option-percent\">(" + Percent + "%)</span>";
        }
Esempio n. 19
0
        public OptionResult( PollBase poll, int optionCount, int optionIndex )
        {
            string[] arrGuestResults = getResults( poll.AnonymousResult, optionCount );
            string[] arrMemberResults = getResults( poll.MemberResult, optionCount );

            // 100%时候的宽度
            int imgWidth = 200;

            int currentItemVotes = cvt.ToInt( arrGuestResults[optionIndex] ) + cvt.ToInt( arrMemberResults[optionIndex] );

            double percent = ((double)currentItemVotes) / ((double)poll.TotalVotes);

            percent = Math.Round( percent, 2 );
            imgWidth = (int)(imgWidth * percent);

            if (imgWidth == 0) imgWidth = 1;

            this.ImgWidth = imgWidth;
            this.Votes = currentItemVotes;
            this.Percent = Convert.ToString( (double)(percent * 100.0) );
            this.VotesAndPercent = Votes + "(" + Percent + "%)";
        }
        public async Task <ActionResult <TPoll> > Update(string id, [FromBody][CustomizeValidator(RuleSet = Strings.UpdateRuleSet + "," + Strings.DefaultRuleSet)] TPoll pollBase)
        {
            if (id != pollBase.Id)
            {
                return(BadRequest("Id's must match"));
            }
            var oldPollBase = await _pollBaseRepository.GetByIdAsync(id);

            if (oldPollBase == null)
            {
                return(NotFound(id));
            }

            if (!SenderPermissions.Contains("CanUpdateAnyPoll"))
            {
                if (oldPollBase.CreatorUserId != SenderObjectId)
                {
                    return(StatusCode(StatusCodes.Status403Forbidden, "Only creator or admin can update"));
                }
            }

            var groups = await _groupManager.GetAllGroups();

            var result = new PollBaseValidatorFromData <TQuestion>(_fileRepository, groups.Select(groupModel => groupModel.Name))
                         .Validate(pollBase, ruleSet: Strings.DefaultRuleSet);

            result.AddToModelState(ModelState, null);
            if (!result.IsValid)
            {
                return(BadRequest(ModelState));
            }

            PollBase <TQuestion> .GetReplacedPicturesList(oldPollBase, pollBase)
            .ForEach(pictureId => _fileRepository.DeletePollFromMetadata(pictureId, id));

            await _pollBaseRepository.UpdateAsync(pollBase);

            return(Ok(pollBase));
        }
Esempio n. 21
0
 public virtual void SetPoll(PollBase mypoll)
 {
     poll = mypoll;
 }
Esempio n. 22
0
        private String getSubmit( PollBase poll )
        {
            String voteLink = postLink;

            Boolean hasVote = checkHasVote();

            Html html = new Html();
            if (!user.IsRegisterUser) {
                html.Code( "<input type=button disabled=disabled value=\"" + lang.get( "pollLoginRequire" ) + "\" />" );
            }
            else if (hasVote) {
                html.Code( "<input type=button disabled=disabled value=\"" + lang.get( "pollVoted" ) + "\" />" );
            }
            else {

                html.Code( "<input id=\"btnPoll\" class=\"btn\" type=button value=\" " + lang.get( "pollVote" ) + " \" />" );

            }
            if (!(hasVote || (poll.IsVisible != 1))) {
                html.Code( " <span class='red font12'>[" + lang.get( "pollViewTip" ) + "]</span>" );
            }

            String js = getAjaxJs( voteLink, lang.get( "pollSelectRequire" ), lang.get( "pollVoted" ) );
            html.Code( js );

            return html.ToString();
        }
Esempio n. 23
0
        private String getMsg( PollBase poll )
        {
            String expiryDateInfo = PollUtil.GetRealExpiryDate( poll );

            //ForumBoard fb = ctx.getItems( "forumBoard" ) as ForumBoard;
            //Boolean isModerator = fb == null ? true : moderatorService.IsModerator( fb, (User)ctx.viewer.obj );

            Boolean isOpen = false;
            if ((poll.IsOpenVoter == 0) || ((poll.IsOpenVoter == 1) && isModerator()))
                isOpen = true;

            String voteInfo = string.Empty;
            String vstr = lang.get( "pollAllVoter" );
            if (!isOpen) {
                voteInfo = vstr.Replace( "{0}", "<span id='voterCount'>" + poll.VoteCount + "</span>" );
            }
            else {
                String lnkView = string.Format( "<a href=\"{1}\" id=\"pollVoterList\" class=\"frmBox\"><span id=\"voterCount\">{0}</span></a>", poll.VoteCount, lnkVoter );
                voteInfo = vstr.Replace( "{0}", lnkView );

            }

            return (expiryDateInfo + voteInfo);
        }
Esempio n. 24
0
 public void SetPoll( PollBase mypoll )
 {
     poll = mypoll;
 }
Esempio n. 25
0
 public void SetPoll(PollBase mypoll)
 {
     poll = mypoll;
 }
Esempio n. 26
0
 public virtual void SetPoll( PollBase mypoll )
 {
     poll = mypoll;
 }