internal PollsQueryBuilder(Group group, User accessingUser, Guid[] groupsToQuery, PollsApi.PollsListOptions options) { query = options; _group = group; _accessingUser = accessingUser; _groupsToQuery = groupsToQuery; _parameters = new List<SqlParameter>(); }
internal PollsQueryBuilder(Group group, User accessingUser, Guid[] groupsToQuery, PollsApi.PollsListOptions options) { query = options; _group = group; _accessingUser = accessingUser; _groupsToQuery = groupsToQuery; _parameters = new List <SqlParameter>(); }
private static string PollsCacheKey(Guid applicationId, PollsApi.PollsListOptions options) { return(string.Concat("Polling_PK_Polls:" , TEApi.Users.AccessingUser.Id.Value , ":", applicationId , ":", options.IsEnabled , ":", options.IsSuspectedAbusive , ":", options.AuthorUserId , ":", options.PageIndex , ":", options.PageSize , ":", options.SortBy , ":", options.SortOrder)); }
internal static PagedList <Poll> ListPolls(int groupId, PollsApi.PollsListOptions options) { var group = TEApi.Groups.Get(new GroupsGetOptions() { Id = groupId }); if (group == null) { return(new PagedList <Poll>()); } Guid[] filterGroupIds = null; if (options.IncludeSubGroups == true) { var groupsToQuery = TEApi.Groups.List(new GroupsListOptions() { IncludeAllSubGroups = true, ParentGroupId = groupId, PageSize = 9999 }); groupsToQuery.Add(group); IEnumerable <Guid> ids; ids = from g1 in groupsToQuery select g1.ApplicationId; filterGroupIds = ids.ToArray(); if (filterGroupIds.Length == 0) { return(new PagedList <Poll>()); } } //PagedList<Poll> polls = (PagedList<Poll>)CacheService.Get(PollsCacheKey(group.ApplicationId, options), CacheScope.Context | CacheScope.Process); //if (polls == null) //{ var polls = PollingDataService.ListPolls(group, TEApi.Users.AccessingUser, filterGroupIds, options); //CacheService.Put(PollsCacheKey(group.ApplicationId, options), polls, CacheScope.Context | CacheScope.Process, new string[] { PollTag(group.ApplicationId) }); //} return(polls); }
public static PagedList<Poll> List(int groupId, PollsListOptions options) { if (options == null) options = new PollsListOptions(); if (options.PageSize > 100) options.PageSize = 100; else if (options.PageSize < 1) options.PageSize = 1; if (options.PageIndex < 0) options.PageIndex = 0; try { if (string.Equals(options.SortBy, "TopPollsScore", StringComparison.OrdinalIgnoreCase)) { var group = TEApi.Groups.Get(new GroupsGetOptions { Id = groupId }); if (group == null || group.HasErrors()) return new PagedList<Poll>(); var scores = TEApi.CalculatedScores.List(Plugins.TopPollsScore.ScoreId, new CalculatedScoreListOptions { ApplicationId = group.ApplicationId, ContentTypeId = ContentTypeId, PageIndex = options.PageIndex, PageSize = options.PageSize, SortOrder = "Descending" }); var polls = new List<Poll>(); foreach (var score in scores) { if (score.Content != null) { var poll = Get(score.Content.ContentId); if (poll != null) polls.Add(poll); } } return new PagedList<Poll>(polls, scores.PageSize, scores.PageIndex, scores.TotalCount); } else { var polls = InternalApi.PollingService.ListPolls(groupId, options); return new PagedList<Poll>(polls.Select(x => new Poll(x)), polls.PageSize, polls.PageIndex, polls.TotalCount); } } catch (Exception ex) { return new PagedList<Poll>(new AdditionalInfo(new Error(ex.GetType().FullName, ex.Message))); } }
internal static PagedList <Poll> ListPolls(Telligent.Evolution.Extensibility.Api.Entities.Version1.Group group, User user, Guid[] filterGroupIds, PollsApi.PollsListOptions options) { List <Poll> polls = new List <Poll>(); using (var connection = GetSqlConnection()) { using (var command = CreateSprocCommand("[polling_Polls_List]", connection)) { PollsQueryBuilder queryBuilder = new PollsQueryBuilder(group, user, filterGroupIds, options); command.Parameters.Add("@sql", SqlDbType.NVarChar, -1).Value = queryBuilder.BuildQuery(); command.Parameters.Add("@TotalRecords", SqlDbType.Int).Direction = ParameterDirection.Output; for (int i = 0; i < queryBuilder.SqlParameters.Length; i++) { command.Parameters.Add(queryBuilder.SqlParameters[i]); } connection.Open(); using (var reader = command.ExecuteReader()) { Dictionary <Guid, Poll> pollsById = new Dictionary <Guid, Poll>(); while (reader.Read()) { var poll = PopulatePoll(reader); pollsById[poll.Id] = poll; polls.Add(poll); } reader.NextResult(); while (reader.Read()) { var pollAnswer = PopulatePollAnswer(reader); Poll poll; if (pollsById.TryGetValue(pollAnswer.PollId, out poll)) { poll.Answers.Add(pollAnswer); } } reader.Close(); } connection.Close(); return(new PagedList <Poll>(polls, options.PageSize, options.PageIndex, (int)command.Parameters["@TotalRecords"].Value)); } } }
public static PagedList <Poll> List(int groupId, PollsListOptions options) { if (options == null) { options = new PollsListOptions(); } if (options.PageSize > 100) { options.PageSize = 100; } else if (options.PageSize < 1) { options.PageSize = 1; } if (options.PageIndex < 0) { options.PageIndex = 0; } try { if (string.Equals(options.SortBy, "TopPollsScore", StringComparison.OrdinalIgnoreCase)) { var group = TEApi.Groups.Get(new GroupsGetOptions { Id = groupId }); if (group == null || group.HasErrors()) { return(new PagedList <Poll>()); } var scores = TEApi.CalculatedScores.List(Plugins.TopPollsScore.ScoreId, new CalculatedScoreListOptions { ApplicationId = group.ApplicationId, ContentTypeId = ContentTypeId, PageIndex = options.PageIndex, PageSize = options.PageSize, SortOrder = "Descending" }); var polls = new List <Poll>(); foreach (var score in scores) { if (score.Content != null) { var poll = Get(score.Content.ContentId); if (poll != null) { polls.Add(poll); } } } return(new PagedList <Poll>(polls, scores.PageSize, scores.PageIndex, scores.TotalCount)); } else { var polls = InternalApi.PollingService.ListPolls(groupId, options); return(new PagedList <Poll>(polls.Select(x => new Poll(x)), polls.PageSize, polls.PageIndex, polls.TotalCount)); } } catch (Exception ex) { return(new PagedList <Poll>(new AdditionalInfo(new Error(ex.GetType().FullName, ex.Message)))); } }