예제 #1
0
        public static Poll Create(int groupId, string name, string description = null, DateTime?votingEndDate = null, bool?hideResultsUntilVotingComplete = false)
        {
            var group = TEApi.Groups.Get(new GroupsGetOptions()
            {
                Id = groupId
            });

            try
            {
                var poll = new Internal.Poll();
                poll.ApplicationId    = group.ApplicationId;
                poll.AuthorUserId     = TEApi.Users.AccessingUser.Id.Value;
                poll.Name             = name;
                poll.Description      = description;
                poll.IsEnabled        = true;
                poll.VotingEndDateUtc = votingEndDate;
                poll.HideResultsUntilVotingComplete = hideResultsUntilVotingComplete.HasValue && hideResultsUntilVotingComplete.Value;

                Internal.PollingService.AddUpdatePoll(poll);

                return(Get(poll.Id));
            }
            catch (Exception ex)
            {
                return(new Poll(new AdditionalInfo(new Error(ex.GetType().FullName, ex.Message))));
            }
        }
예제 #2
0
        public static Poll Create(int groupId, string name, string description = null, DateTime? votingEndDate = null, bool? hideResultsUntilVotingComplete = false)
        {
            var group = TEApi.Groups.Get(new GroupsGetOptions() { Id = groupId });

            try
            {
                var poll = new Internal.Poll();
                poll.ApplicationId = group.ApplicationId;
                poll.AuthorUserId = TEApi.Users.AccessingUser.Id.Value;
                poll.Name = name;
                poll.Description = description;
                poll.IsEnabled = true;
                poll.VotingEndDateUtc = votingEndDate;
                poll.HideResultsUntilVotingComplete = hideResultsUntilVotingComplete.HasValue && hideResultsUntilVotingComplete.Value;

                Internal.PollingService.AddUpdatePoll(poll);

                return Get(poll.Id);
            }
            catch (Exception ex)
            {
                return new Poll(new AdditionalInfo(new Error(ex.GetType().FullName, ex.Message)));
            }
        }
예제 #3
0
        public void HandlePollVote(System.Web.HttpContext context)
        {
            var user = TEApi.Users.AccessingUser;

            if (user.IsSystemAccount.HasValue && user.IsSystemAccount.Value)
            {
                context.Response.RedirectLocation = TEApi.CoreUrls.LogIn(new CoreUrlLoginOptions()
                {
                    ReturnToCurrentUrl = true
                });
                context.Response.StatusCode = 302;
                context.Response.End();
            }

            var pollContextItem = TEApi.Url.CurrentContext.ContextItems.GetItemByContentType(PublicApi.Polls.ContentTypeId);

            Telligent.BigSocial.Polling.InternalApi.Poll poll = null;
            if (pollContextItem != null && pollContextItem.ContentId.HasValue)
            {
                poll = InternalApi.PollingService.GetPoll(pollContextItem.ContentId.Value);
            }

            if (poll == null)
            {
                throw new PollException(_translatablePluginController.GetLanguageResourceValue("poll_NotFound"));
            }

            var  pollAnswerIdObj = TEApi.Url.CurrentContext.GetTokenValue("PollAnswerId");
            Guid pollAnswerId;

            if (pollAnswerIdObj != null && Guid.TryParse(pollAnswerIdObj.ToString(), out pollAnswerId))
            {
                var answer = InternalApi.PollingService.GetPollAnswer(pollAnswerId);
                if (answer != null)
                {
                    try
                    {
                        InternalApi.PollingService.AddUpdatePollVote(new Telligent.BigSocial.Polling.InternalApi.PollVote()
                        {
                            PollId = poll.Id, UserId = user.Id.Value, PollAnswerId = pollAnswerId
                        });

                        var url = TEApi.Url.Adjust(InternalApi.PollingUrlService.PollUrl(poll.Id), "voted=" + pollAnswerId.ToString());
                        context.Response.RedirectLocation = url;
                        context.Response.StatusCode       = 302;
                        context.Response.End();
                    }
                    catch (Exception ex)
                    {
                        throw new PollException(_translatablePluginController.GetLanguageResourceValue("vote_UnknownError"), ex);
                    }
                }
                else
                {
                    var url = TEApi.Url.Adjust(InternalApi.PollingUrlService.PollUrl(poll.Id), "votefailed=true");
                    context.Response.RedirectLocation = url;
                    context.Response.StatusCode       = 302;
                    context.Response.End();
                }
            }
        }
예제 #4
0
 internal Poll(Internal.Poll poll)
     : base()
 {
     _poll = poll;
 }
예제 #5
0
 internal Poll(Internal.Poll poll)
     : base()
 {
     _poll = poll;
 }