private static void ValidatePollAnswer(PollAnswer answer)
        {
            if (answer.Id == Guid.Empty)
            {
                answer.Id = Guid.NewGuid();
            }

            answer.Name = TEApi.Html.Sanitize(TEApi.Html.EnsureEncoded(answer.Name));
            if (string.IsNullOrEmpty(answer.Name))
            {
                throw new PollException("The name of the poll answer must be defined.");
            }

            Poll poll = GetPoll(answer.PollId);

            if (poll == null)
            {
                throw new PollException("The poll associated to the answer does not exist.");
            }

            var group = TEApi.Groups.Get(poll.ApplicationId);

            if (group == null || group.HasErrors())
            {
                throw new PollException("The group identified on the poll is invalid.");
            }

            if (poll.AuthorUserId != TEApi.Users.AccessingUser.Id.Value && !PollingPermissionService.CanCreatePolls(TEApi.Groups.ContentTypeId, group.ApplicationId))
            {
                throw new PollException("The user does not have permission to create/edit this poll. The user must be the original creator or an have create poll permissions in the group.");
            }
        }
        private static void ValidatePoll(Poll poll)
        {
            if (poll.Id == Guid.Empty)
            {
                poll.CreatedDateUtc = DateTime.UtcNow;
                poll.Id             = Guid.NewGuid();
            }

            poll.LastUpdatedDateUtc = DateTime.UtcNow;
            poll.Name        = TEApi.Html.Sanitize(TEApi.Html.EnsureEncoded(poll.Name));
            poll.Description = TEApi.Html.Sanitize(poll.Description ?? string.Empty);

            if (poll.HideResultsUntilVotingComplete && !poll.VotingEndDateUtc.HasValue)
            {
                poll.HideResultsUntilVotingComplete = false;
            }

            if (string.IsNullOrEmpty(poll.Name))
            {
                throw new PollException("The name of the poll must be defined.");
            }

            var group = TEApi.Groups.Get(poll.ApplicationId);

            if (group == null || group.HasErrors())
            {
                throw new PollException("The group identified on the poll is invalid.");
            }

            if (!PollingPermissionService.CanCreatePolls(TEApi.Groups.ContentTypeId, group.ApplicationId))
            {
                throw new PollException("The user does not have permission to create polls in this group.");
            }

            if (poll.AuthorUserId <= 0)
            {
                poll.AuthorUserId = TEApi.Users.AccessingUser.Id.Value;
            }
            else if (poll.AuthorUserId != TEApi.Users.AccessingUser.Id.Value && !PollingPermissionService.CanCreatePolls(TEApi.Groups.ContentTypeId, group.ApplicationId))
            {
                throw new PollException("The user does not have permission to create/edit this poll. The user must be the original creator or an admin in the group.");
            }
        }