internal static void DeletePoll(Poll poll) { ValidatePoll(poll); PublicApi.Polls.Events.OnBeforeDelete(poll); PollingDataService.DeletePoll(poll.Id); ExpirePolls(poll.ApplicationId); PublicApi.Polls.Events.OnAfterDelete(poll); }
internal static void AddUpdatePoll(Poll poll) { bool isCreate = poll.Id == Guid.Empty; ValidatePoll(poll); if (isCreate) PublicApi.Polls.Events.OnBeforeCreate(poll); else PublicApi.Polls.Events.OnBeforeUpdate(poll); PollingDataService.AddUpdatePoll(poll); ExpirePolls(poll.ApplicationId); if (isCreate) PublicApi.Polls.Events.OnAfterCreate(poll); else PublicApi.Polls.Events.OnAfterUpdate(poll); }
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."); }
internal static string RenderPollDescription(Poll poll, string target) { if (string.IsNullOrEmpty(target)) target = "web"; else target = target.ToLowerInvariant(); if (target == "raw") return poll.Description ?? string.Empty; else return PublicApi.Polls.Events.OnRender(poll, "Description", poll.Description ?? string.Empty, target); }