public PartialFindResult <PVForSongContract> GetList(string name = null, string author = null, PVService?service = null, int maxResults = 10, bool getTotalCount = false, ContentLanguagePreference lang = ContentLanguagePreference.Default) { return(_repository.HandleQuery(db => { var query = db.Query <PVForSong>(); if (!string.IsNullOrEmpty(name)) { query = query.Where(pv => pv.Name == name); } if (!string.IsNullOrEmpty(author)) { query = query.Where(pv => pv.Author == author); } if (service.HasValue) { query = query.Where(pv => pv.Service == service); } var count = getTotalCount ? query.Count() : 0; query = query.Take(maxResults); var results = query.Select(p => new PVForSongContract(p, lang)).ToArray(); return PartialFindResult.Create(results, count); })); }
public PartialFindResult <DiscussionTopicContract> GetTopics( int?folderId = null, int start = 0, int maxResults = DefaultMax, bool getTotalCount = false, DiscussionTopicSortRule sort = DiscussionTopicSortRule.DateCreated, DiscussionTopicOptionalFields fields = DiscussionTopicOptionalFields.None) { return(HandleQuery(ctx => { var query = ctx.OfType <DiscussionTopic>() .Query() .WhereNotDeleted() .WhereIsInFolder(folderId); var topics = query .OrderBy(sort) .Paged(new PagingProperties(start, maxResults, getTotalCount)) .ToArray() .Select(f => new DiscussionTopicContract(f, _userIconFactory, fields)) .ToArray(); var count = (getTotalCount ? query.Count() : 0); return PartialFindResult.Create(topics, count); })); }
public PartialFindResult <ActivityEntryForApiContract> GetList( DateTime?before = null, DateTime?since = null, int?userId = null, EntryEditEvent?editEvent = null, int maxResults = defaultMax, bool getTotalCount = false, ActivityEntryOptionalFields fields = ActivityEntryOptionalFields.None, EntryOptionalFields entryFields = EntryOptionalFields.None, ContentLanguagePreference lang = ContentLanguagePreference.Default) { maxResults = Math.Min(maxResults, absoluteMax); bool ssl = WebHelper.IsSSL(Request); return(repository.HandleQuery(ctx => { var query = ctx.Query <ActivityEntry>(); if (before.HasValue && !since.HasValue) { query = query.Where(a => a.CreateDate < before.Value); } if (!before.HasValue && since.HasValue) { query = query.Where(a => a.CreateDate > since.Value); } if (before.HasValue && since.HasValue) { query = query.Where(a => a.CreateDate > since.Value && a.CreateDate < before.Value); } if (userId.HasValue) { query = query.Where(a => a.Author.Id == userId.Value); } if (editEvent.HasValue) { query = query.Where(a => a.EditEvent == editEvent.Value); } var activityEntries = query .OrderByDescending(a => a.CreateDate) .Take(maxResults) .ToArray() .Where(a => !a.EntryBase.Deleted) .Select(a => new ActivityEntryForApiContract(a, fields.HasFlag(ActivityEntryOptionalFields.Entry) ? entryForApiContractFactory.Create(a.EntryBase, entryFields, lang, ssl) : null, userIconFactory, permissionContext, fields)) .ToArray(); var count = getTotalCount ? query.Count() : 0; return PartialFindResult.Create(activityEntries, count); })); }
public PartialFindResult <Tag> Find(TagQueryParams queryParams, bool onlyMinimalFields) { var isMoveToTopQuery = queryParams.Common.MoveExactToTop && queryParams.Common.NameMatchMode != NameMatchMode.StartsWith && queryParams.Common.NameMatchMode != NameMatchMode.Exact && queryParams.Paging.Start == 0 && !queryParams.Common.TextQuery.IsEmpty; if (isMoveToTopQuery) { return(GetTagsMoveExactToTop(queryParams)); } var query = CreateQuery(queryParams, queryParams.Common.Query, queryParams.Common.NameMatchMode); var orderedAndPaged = query .OrderBy(queryParams.SortRule, _languagePreference) .Paged(queryParams.Paging); Tag[] tags; if (onlyMinimalFields) { tags = orderedAndPaged.Select(t => new Tag { Id = t.Id, CategoryName = t.CategoryName, CreateDate = t.CreateDate, Status = t.Status, Version = t.Version, Names = new NameManager <TagName> { SortNames = { English = t.Names.SortNames.English, Romaji = t.Names.SortNames.Romaji, Japanese = t.Names.SortNames.Japanese, DefaultLanguage = t.Names.SortNames.DefaultLanguage } } }).ToArray(); } else { tags = orderedAndPaged.ToArray(); } var count = 0; if (queryParams.Paging.GetTotalCount) { count = query.Count(); } return(PartialFindResult.Create(tags, count)); }
public PartialFindResult <TagMappingContract> GetMappings(PagingProperties paging) { return(HandleQuery(ctx => { var query = ctx.Query <TagMapping>(); var result = query .OrderByName(LanguagePreference) .Paged(paging) .ToArray() .Select(t => new TagMappingContract(t, LanguagePreference)) .ToArray(); return PartialFindResult.Create(result, paging.GetTotalCount ? query.Count() : 0); })); }
public PartialFindResult <TResult> FindSeries <TResult>(Func <ReleaseEventSeries, TResult> fac, SearchTextQuery textQuery, PagingProperties paging) { return(HandleQuery(ctx => { var q = ctx.Query <ReleaseEventSeries>() .WhereHasName(textQuery) .Paged(paging); var entries = q .OrderBy(s => s.Name) .ToArray() .Select(fac) .ToArray(); var count = paging.GetTotalCount ? q.Count() : 0; return PartialFindResult.Create(entries, count); })); }
public PartialFindResult <TResult> Find <TResult>(Func <Venue, TResult> fac, VenueQueryParams queryParams) { return(HandleQuery(ctx => { var q = ctx.Query <Venue>() .WhereNotDeleted() .WhereHasName(queryParams.TextQuery) .WhereInCircle(queryParams.Coordinates, queryParams.Radius, queryParams.DistanceUnit) .Paged(queryParams.Paging); var entries = q .OrderBy(queryParams.SortRule, PermissionContext.LanguagePreference, queryParams.Coordinates, queryParams.DistanceUnit) .ToArray() .Select(fac) .ToArray(); var count = queryParams.Paging.GetTotalCount ? q.Count() : 0; return PartialFindResult.Create(entries, count); })); }