示例#1
0
        public static IQueryable <Album> AddOrder(IQueryable <Album> criteria, AlbumSortRule sortRule, ContentLanguagePreference languagePreference)
        {
            switch (sortRule)
            {
            case AlbumSortRule.Name:
                return(FindHelpers.AddNameOrder(criteria, languagePreference));

            case AlbumSortRule.ReleaseDate:
                return(AddReleaseRestriction(criteria)
                       .OrderByDescending(a => a.OriginalRelease.ReleaseDate.Year)
                       .ThenByDescending(a => a.OriginalRelease.ReleaseDate.Month)
                       .ThenByDescending(a => a.OriginalRelease.ReleaseDate.Day));

            case AlbumSortRule.AdditionDate:
                return(criteria.OrderByDescending(a => a.CreateDate));

            case AlbumSortRule.RatingAverage:
                return(criteria.OrderByDescending(a => a.RatingAverageInt)
                       .ThenByDescending(a => a.RatingCount));

            case AlbumSortRule.NameThenReleaseDate:
                return(FindHelpers.AddNameOrder(criteria, languagePreference)
                       .ThenBy(a => a.OriginalRelease.ReleaseDate.Year)
                       .ThenBy(a => a.OriginalRelease.ReleaseDate.Month)
                       .ThenBy(a => a.OriginalRelease.ReleaseDate.Day));
            }

            return(criteria);
        }
示例#2
0
        private PartialFindResult <Album> FindAdvanced(
            ISession session, string query, PagingProperties paging, AlbumSortRule sortRule)
        {
            var queryPlan = new AlbumQueryBuilder().BuildPlan(query);

            return(FindAdvanced(session, queryPlan, paging, sortRule));
        }
示例#3
0
        private PartialFindResult <Album> FindAdvanced(
            ISession session, QueryPlan <Album> queryPlan, PagingProperties paging, AlbumSortRule sortRule)
        {
            if (!queryPlan.Any())
            {
                return(new PartialFindResult <Album>(new Album[] {}, 0));
            }

            IQueryable <Album> albums = null;

            foreach (var filter in queryPlan)
            {
                if (albums == null)
                {
                    albums = filter.Query(session);
                }
                else
                {
                    albums = filter.Filter(albums, session);
                }
            }

            var result = albums
                         .Skip(paging.Start)
                         .Take(paging.MaxEntries)
                         .ToArray();

            return(new PartialFindResult <Album>(result, albums.Count()));
        }
示例#4
0
		public static IQueryable<Album> AddOrder(IQueryable<Album> criteria, AlbumSortRule sortRule, ContentLanguagePreference languagePreference) {

			switch (sortRule) {
				case AlbumSortRule.Name:
					return FindHelpers.AddNameOrder(criteria, languagePreference);
				case AlbumSortRule.ReleaseDate:
					return AddReleaseRestriction(criteria)
						.OrderByDescending(a => a.OriginalRelease.ReleaseDate.Year)
						.ThenByDescending(a => a.OriginalRelease.ReleaseDate.Month)
						.ThenByDescending(a => a.OriginalRelease.ReleaseDate.Day);
				case AlbumSortRule.AdditionDate:
					return criteria.OrderByDescending(a => a.CreateDate);
				case AlbumSortRule.RatingAverage:
					return criteria.OrderByDescending(a => a.RatingAverageInt)
						.ThenByDescending(a => a.RatingCount);
				case AlbumSortRule.NameThenReleaseDate:
					return FindHelpers.AddNameOrder(criteria, languagePreference)
						.ThenBy(a => a.OriginalRelease.ReleaseDate.Year)
						.ThenBy(a => a.OriginalRelease.ReleaseDate.Month)
						.ThenBy(a => a.OriginalRelease.ReleaseDate.Day);
			}

			return criteria;

		}
		public static IQueryable<AlbumForUser> OrderBy(this IQueryable<AlbumForUser> query, AlbumSortRule sortRule, ContentLanguagePreference languagePreference) {

			switch (sortRule) {
				case AlbumSortRule.Name:
					return AddNameOrder(query, languagePreference);
				case AlbumSortRule.CollectionCount:
					return query.OrderByDescending(a => a.Album.UserCollections.Count);
				case AlbumSortRule.ReleaseDate:
					return query
						.WhereHasReleaseDate()
						.OrderByReleaseDate();
				case AlbumSortRule.ReleaseDateWithNulls:
					return query.OrderByReleaseDate();
				case AlbumSortRule.AdditionDate:
					return query.OrderByDescending(a => a.Album.CreateDate);
				case AlbumSortRule.RatingAverage:
					return query.OrderByDescending(a => a.Album.RatingAverageInt)
						.ThenByDescending(a => a.Album.RatingCount);
				case AlbumSortRule.RatingTotal:
					return query.OrderByDescending(a => a.Album.RatingTotal)
						.ThenByDescending(a => a.Album.RatingAverageInt);
				case AlbumSortRule.NameThenReleaseDate:
					return AddNameOrder(query, languagePreference)
						.ThenBy(a => a.Album.OriginalRelease.ReleaseDate.Year)
						.ThenBy(a => a.Album.OriginalRelease.ReleaseDate.Month)
						.ThenBy(a => a.Album.OriginalRelease.ReleaseDate.Day);
			}

			return query;

		}
示例#6
0
        public PartialFindResult <AlbumContract> Find(
            string query, DiscType discType, int start, int maxResults, bool draftsOnly, bool getTotalCount,
            NameMatchMode nameMatchMode = NameMatchMode.Auto, AlbumSortRule sortRule = AlbumSortRule.Name, bool moveExactToTop = false)
        {
            var queryParams = new AlbumQueryParams(query, discType, start, maxResults, draftsOnly, getTotalCount, nameMatchMode, sortRule, moveExactToTop);

            return(Find(queryParams));
        }
示例#7
0
        public PartialFindResult <AlbumContract> Find(
            SearchTextQuery textQuery, DiscType discType, int start, int maxResults, bool getTotalCount,
            AlbumSortRule sortRule = AlbumSortRule.Name, bool moveExactToTop = false)
        {
            var queryParams = new AlbumQueryParams(textQuery, discType, start, maxResults, getTotalCount, sortRule, moveExactToTop);

            return(Find(queryParams));
        }
示例#8
0
        private PartialFindResult <Album> FindAdvanced(
            ISession session, QueryPlan <Album> queryPlan, PagingProperties paging, AlbumSortRule sortRule)
        {
            var querySource = new QuerySourceSession(session);
            var processor   = new QueryProcessor <Album>(querySource);

            return(processor.Query(queryPlan, paging, q => AlbumSearchSort.AddOrder(q, sortRule, LanguagePreference)));
        }
示例#9
0
        public AlbumQueryParams(SearchTextQuery textQuery, DiscType discType, int start, int maxResults, bool getTotalCount,
                                AlbumSortRule sortRule = AlbumSortRule.Name, bool moveExactToTop = false)
        {
            Common = new CommonSearchParams(textQuery, false, moveExactToTop);
            Paging = new PagingProperties(start, maxResults, getTotalCount);

            AlbumType = discType;
            SortRule  = sortRule;
        }
示例#10
0
        public AlbumQueryParams(string query, DiscType discType, int start, int maxResults, bool draftsOnly, bool getTotalCount,
            NameMatchMode nameMatchMode = NameMatchMode.Auto, AlbumSortRule sortRule = AlbumSortRule.Name, bool moveExactToTop = false)
        {
            Common = new CommonSearchParams(query, draftsOnly, nameMatchMode, false, moveExactToTop);
            Paging = new PagingProperties(start, maxResults, getTotalCount);

            AlbumType = discType;
            SortRule = sortRule;
        }
示例#11
0
        public AlbumQueryParams(string query, DiscType discType, int start, int maxResults, bool draftsOnly, bool getTotalCount,
                                NameMatchMode nameMatchMode = NameMatchMode.Auto, AlbumSortRule sortRule = AlbumSortRule.Name, bool moveExactToTop = false)
        {
            Common = new CommonSearchParams(query, draftsOnly, nameMatchMode, false, moveExactToTop);
            Paging = new PagingProperties(start, maxResults, getTotalCount);

            AlbumType = discType;
            SortRule  = sortRule;
        }
示例#12
0
        public ActionResult Index(string query, DiscType discType = DiscType.Unknown,
                                  int start = 0, bool getTotalCount = false, AlbumSortRule sort = AlbumSortRule.Name,
                                  NameMatchMode nameMatchMode = NameMatchMode.Exact, DataFormat format = DataFormat.Auto)
        {
            var queryParams = new AlbumQueryParams(query, discType, start, maxResults, false, getTotalCount, nameMatchMode, sort);

            var entries = Service.Find(a => new AlbumForApiContract(a, LoginManager.LanguagePreference), queryParams);

            return(Object(entries, format));
        }
示例#13
0
        public AlbumContract GetAlbumDetails(string term, AlbumSortRule sort = AlbumSortRule.NameThenReleaseDate)
        {
            var matchMode = NameMatchMode.Auto;

            term = FindHelpers.GetMatchModeAndQueryForSearch(term, ref matchMode);

            var albums = Services.Albums.Find(term, DiscType.Unknown, 0, 10, false, false, moveExactToTop: true, sortRule: sort, nameMatchMode: matchMode);

            return(albums.Items.FirstOrDefault());
        }
示例#14
0
        public ActionResult Index(string query, DiscType discType = DiscType.Unknown,
            int start = 0, bool getTotalCount = false, AlbumSortRule sort = AlbumSortRule.Name,
            NameMatchMode nameMatchMode = NameMatchMode.Exact, DataFormat format = DataFormat.Auto)
        {
            var queryParams = new AlbumQueryParams(query, discType, start, maxResults, false, getTotalCount, nameMatchMode, sort);

            var entries = Service.Find(a => new AlbumForApiContract(a, LoginManager.LanguagePreference), queryParams);

            return Object(entries, format);
        }
示例#15
0
        public PartialFindResult <AlbumWithAdditionalNamesContract> FindAdvanced(
            string query, PagingProperties paging, AlbumSortRule sortRule)
        {
            return(HandleQuery(session => {
                var results = FindAdvanced(session, query, paging, sortRule);

                return new PartialFindResult <AlbumWithAdditionalNamesContract>(
                    results.Items.Select(a => new AlbumWithAdditionalNamesContract(a, PermissionContext.LanguagePreference)).ToArray(),
                    results.TotalCount, results.Term, results.FoundExactMatch);
            }));
        }
示例#16
0
        /// <summary>
        /// Makes sure that the query is filtered by restrictions of the sort rule.
        /// This can be used to separate the filtering from the actual sorting, when sorting is not needed (for example, only count is needed).
        /// </summary>
        public static IQueryable <Album> WhereSortBy(this IQueryable <Album> query, AlbumSortRule sort)
        {
            switch (sort)
            {
            case AlbumSortRule.ReleaseDate:
                return(query.WhereHasReleaseDate());

            default:
                return(query);
            }
        }
示例#17
0
 public Index(PartialFindResult <AlbumContract> result, string filter, DiscType discType,
              AlbumSortRule sortRule, EntryViewMode view, int?page, bool?draftsOnly, IndexRouteParams routeParams)
 {
     Page   = page ?? 1;
     Albums = new StaticPagedList <AlbumContract>(result.Items,
                                                  Page, 30, result.TotalCount);
     DiscType    = discType;
     DraftsOnly  = draftsOnly ?? false;
     Filter      = filter;
     Sort        = sortRule;
     View        = view;
     RouteParams = routeParams;
 }
示例#18
0
 public Index(PartialFindResult<AlbumContract> result, string filter, DiscType discType, 
     AlbumSortRule sortRule, EntryViewMode view, int? page, bool? draftsOnly, IndexRouteParams routeParams)
 {
     Page = page ?? 1;
     Albums = new StaticPagedList<AlbumContract>(result.Items,
         Page, 30, result.TotalCount);
     DiscType = discType;
     DraftsOnly = draftsOnly ?? false;
     Filter = filter;
     Sort = sortRule;
     View = view;
     RouteParams = routeParams;
 }
示例#19
0
        public ActionResult Index(string query, DiscType discType = DiscType.Unknown,
            int start = 0, bool getTotalCount = false, AlbumSortRule sort = AlbumSortRule.Name,
            NameMatchMode nameMatchMode = NameMatchMode.Exact,
            bool includeArtists = true, bool includeNames = true, bool includePVs = false, bool includeTags = true, bool includeWebLinks = false,
            DataFormat format = DataFormat.Auto,
            ContentLanguagePreference lang = ContentLanguagePreference.Default)
        {
            var queryParams = new AlbumQueryParams(query, discType, start, maxResults, false, getTotalCount, nameMatchMode, sort);

            var entries = Service.Find(a => new AlbumForApiContract(a, null, lang, includeArtists, includeNames, includePVs, includeTags, includeWebLinks), queryParams);

            return Object(entries, format);
        }
示例#20
0
        public ActionResult Index(string query, DiscType discType = DiscType.Unknown,
                                  int start = 0, bool getTotalCount = false, AlbumSortRule sort = AlbumSortRule.Name,
                                  NameMatchMode nameMatchMode    = NameMatchMode.Exact,
                                  bool includeArtists            = true, bool includeNames = true, bool includePVs = false, bool includeTags = true, bool includeWebLinks = false,
                                  DataFormat format              = DataFormat.Auto,
                                  ContentLanguagePreference lang = ContentLanguagePreference.Default)
        {
            var queryParams = new AlbumQueryParams(query, discType, start, maxResults, false, getTotalCount, nameMatchMode, sort);

            var entries = Service.Find(a => new AlbumForApiContract(a, null, lang, includeArtists, includeNames, includePVs, includeTags, includeWebLinks), queryParams);

            return(Object(entries, format));
        }
示例#21
0
        public static IQueryable <Album> OrderBy(this IQueryable <Album> criteria, AlbumSortRule sortRule, ContentLanguagePreference languagePreference)
        {
            switch (sortRule)
            {
            case AlbumSortRule.Name:
                return(FindHelpers.AddNameOrder(criteria, languagePreference));

            case AlbumSortRule.CollectionCount:
                return(criteria.OrderByDescending(a => a.UserCollections.Count));

            case AlbumSortRule.ReleaseDate:
                return(criteria
                       .WhereHasReleaseDate()
                       .OrderByReleaseDate());

            case AlbumSortRule.ReleaseDateWithNulls:
                return(criteria.OrderByReleaseDate());

            case AlbumSortRule.AdditionDate:
                return(criteria.OrderByDescending(a => a.CreateDate));

            case AlbumSortRule.RatingAverage:
                return(criteria.OrderByDescending(a => a.RatingAverageInt)
                       .ThenByDescending(a => a.RatingCount));

            case AlbumSortRule.RatingTotal:
                return(criteria.OrderByDescending(a => a.RatingTotal)
                       .ThenByDescending(a => a.RatingAverageInt));

            case AlbumSortRule.NameThenReleaseDate:
                return(FindHelpers.AddNameOrder(criteria, languagePreference)
                       .ThenBy(a => a.OriginalRelease.ReleaseDate.Year)
                       .ThenBy(a => a.OriginalRelease.ReleaseDate.Month)
                       .ThenBy(a => a.OriginalRelease.ReleaseDate.Day));
            }

            return(criteria);
        }
示例#22
0
        public AlbumContract GetAlbumDetails(string term, AlbumSortRule sort = AlbumSortRule.NameThenReleaseDate)
        {
            var matchMode = NameMatchMode.Auto;
            term = FindHelpers.GetMatchModeAndQueryForSearch(term, ref matchMode);

            var albums = Services.Albums.Find(term, DiscType.Unknown, 0, 10, false, false, moveExactToTop: true, sortRule: sort, nameMatchMode: matchMode);
            return albums.Items.FirstOrDefault();
        }
示例#23
0
        public int GetAlbumCount(
            AlbumQueryParams queryParams, string query, DiscType discType, bool draftsOnly, NameMatchMode nameMatchMode, AlbumSortRule sortRule)
        {
            query = query ?? string.Empty;

            if (queryParams.ArtistId == 0 && string.IsNullOrWhiteSpace(query))
            {
                var albumQ = Query <Album>()
                             .Where(s => !s.Deleted);

                if (draftsOnly)
                {
                    albumQ = albumQ.Where(a => a.Status == EntryStatus.Draft);
                }

                if (sortRule == AlbumSortRule.ReleaseDate)
                {
                    albumQ = AddReleaseRestriction(albumQ);
                }

                albumQ = AddDiscTypeRestriction(albumQ, discType);

                return(albumQ.Count());
            }

            if (query.StartsWith("tag:"))
            {
                var tagName = query.Substring(4);

                var tagQ = Query <AlbumTagUsage>()
                           .Where(m => !m.Album.Deleted && m.Tag.Name == tagName);

                if (draftsOnly)
                {
                    tagQ = tagQ.Where(a => a.Album.Status == EntryStatus.Draft);
                }

                tagQ = AddDiscTypeRestriction(tagQ, discType);

                return(tagQ.Count());
            }

            if (query.StartsWith("artist:") || queryParams.ArtistId != 0)
            {
                int artistId;
                if (queryParams.ArtistId != 0)
                {
                    artistId = queryParams.ArtistId;
                }
                else
                {
                    int.TryParse(query.Substring(7), out artistId);
                }

                var albumQ = Query <ArtistForAlbum>()
                             .Where(m => !m.Album.Deleted && m.Artist.Id == artistId);

                if (draftsOnly)
                {
                    albumQ = albumQ.Where(a => a.Album.Status == EntryStatus.Draft);
                }

                albumQ = AddDiscTypeRestriction(albumQ, discType);
                return(albumQ.Count());
            }

            var directQ = Query <Album>()
                          .Where(s => !s.Deleted);

            if (draftsOnly)
            {
                directQ = directQ.Where(a => a.Status == EntryStatus.Draft);
            }

            if (sortRule == AlbumSortRule.ReleaseDate)
            {
                directQ = AddReleaseRestriction(directQ);
            }

            directQ = AddDiscTypeRestriction(directQ, discType);

            directQ = AddNameMatchFilter(directQ, query, nameMatchMode);

            var direct = directQ.ToArray();

            var additionalNamesQ = Query <AlbumName>()
                                   .Where(m => !m.Album.Deleted);

            if (draftsOnly)
            {
                additionalNamesQ = additionalNamesQ.Where(a => a.Album.Status == EntryStatus.Draft);
            }

            additionalNamesQ = AddDiscTypeRestriction(additionalNamesQ, discType);

            additionalNamesQ = additionalNamesQ.AddEntryNameFilter(query, nameMatchMode);

            var additionalNamesAlbumQ = additionalNamesQ.Select(a => a.Album);

            if (sortRule == AlbumSortRule.ReleaseDate)
            {
                additionalNamesAlbumQ = AddReleaseRestriction(additionalNamesAlbumQ);
            }

            var additionalNames = additionalNamesAlbumQ
                                  .Distinct()
                                  .ToArray()
                                  .Where(a => !direct.Contains(a))
                                  .ToArray();

            return(direct.Count() + additionalNames.Count());
        }
示例#24
0
        public PartialFindResult<AlbumForApiContract> GetList(
            string query = "",
            DiscType discTypes = DiscType.Unknown,
            string tag = null,
            int? artistId = null,
            ArtistAlbumParticipationStatus artistParticipationStatus = ArtistAlbumParticipationStatus.Everything,
            bool childVoicebanks = false,
            string barcode = null,
            EntryStatus? status = null,
            int start = 0,
            int maxResults = defaultMax,
            bool getTotalCount = false,
            AlbumSortRule? sort = null,
            NameMatchMode nameMatchMode = NameMatchMode.Exact,
            AlbumOptionalFields fields = AlbumOptionalFields.None,
            ContentLanguagePreference lang = ContentLanguagePreference.Default)
        {
            query = FindHelpers.GetMatchModeAndQueryForSearch(query, ref nameMatchMode);

            var queryParams = new AlbumQueryParams(query, discTypes, start, Math.Min(maxResults, absoluteMax), false, getTotalCount, nameMatchMode, sort ?? AlbumSortRule.Name) {
                Tag = tag,
                ArtistId = artistId ?? 0,
                ArtistParticipationStatus = artistParticipationStatus,
                ChildVoicebanks = childVoicebanks,
                Barcode = barcode
            };
            queryParams.Common.EntryStatus = status;

            var ssl = WebHelper.IsSSL(Request);

            var entries = service.Find(a => new AlbumForApiContract(a, null, lang, thumbPersister, ssl, fields), queryParams);

            return entries;
        }
示例#25
0
 public PartialFindResult <AlbumContract> FindAlbums(string term, int maxResults,
                                                     NameMatchMode nameMatchMode = NameMatchMode.Auto, AlbumSortRule sort = AlbumSortRule.NameThenReleaseDate)
 {
     return(Services.Albums.Find(term, DiscType.Unknown, 0, maxResults, false, true, moveExactToTop: true, nameMatchMode: nameMatchMode, sortRule: sort));
 }
示例#26
0
 public AlbumContract GetAlbumDetails(string term, AlbumSortRule sort = AlbumSortRule.NameThenReleaseDate)
 {
     var albums = Services.Albums.Find(term, DiscType.Unknown, 0, 10, false, false, moveExactToTop: true, sortRule: sort);
     return albums.Items.FirstOrDefault();
 }
示例#27
0
 public PartialFindResult <AlbumContract> FindAlbums(string term, int maxResults,
                                                     NameMatchMode nameMatchMode = NameMatchMode.Auto, AlbumSortRule sort = AlbumSortRule.NameThenReleaseDate)
 {
     return(albumService.Find(SearchTextQuery.Create(term, nameMatchMode), DiscType.Unknown, 0, maxResults, true, moveExactToTop: true, sortRule: sort));
 }
示例#28
0
        public AlbumContract GetAlbumDetails(string term, AlbumSortRule sort = AlbumSortRule.NameThenReleaseDate)
        {
            var albums = albumService.Find(SearchTextQuery.Create(term), DiscType.Unknown, 0, 10, false, moveExactToTop: true, sortRule: sort);

            return(albums.Items.FirstOrDefault());
        }
示例#29
0
        public PartialFindResult<AlbumForUserForApiContract> GetAlbumCollection(
            int userId,
            string query = "",
            string tag = null,
            int? artistId = null,
            [FromUri] PurchaseStatuses? purchaseStatuses = null,
            string releaseEventName = null,
            int start = 0,
            int maxResults = defaultMax,
            bool getTotalCount = false,
            AlbumSortRule? sort = null,
            NameMatchMode nameMatchMode = NameMatchMode.Exact,
            AlbumOptionalFields fields = AlbumOptionalFields.None,
            ContentLanguagePreference lang = ContentLanguagePreference.Default)
        {
            maxResults = Math.Min(maxResults, absoluteMax);
            query = FindHelpers.GetMatchModeAndQueryForSearch(query, ref nameMatchMode);
            var ssl = WebHelper.IsSSL(Request);

            var queryParams = new AlbumCollectionQueryParams(userId, new PagingProperties(start, maxResults, getTotalCount)) {
                ArtistId = artistId ?? 0,
                FilterByStatus = purchaseStatuses != null ? purchaseStatuses.Value.ToIndividualSelections().ToArray() : null,
                NameMatchMode = nameMatchMode,
                Query = query,
                ReleaseEventName = releaseEventName,
                Sort = sort ?? AlbumSortRule.Name,
                Tag = tag
            };

            var albums = queries.GetAlbumCollection(queryParams, (afu, shouldShowCollectionStatus) =>
                new AlbumForUserForApiContract(afu, lang, thumbPersister, ssl, fields, shouldShowCollectionStatus));

            return albums;
        }
示例#30
0
		public static IQueryable<Album> OrderBy(this IQueryable<Album> criteria, AlbumSortRule sortRule, ContentLanguagePreference languagePreference) => sortRule switch
		{
示例#31
0
 public PartialFindResult<AlbumContract> FindAlbums(string term, int maxResults, 
     NameMatchMode nameMatchMode = NameMatchMode.Auto, AlbumSortRule sort = AlbumSortRule.NameThenReleaseDate)
 {
     return Services.Albums.Find(term, DiscType.Unknown, 0, maxResults, false, true, moveExactToTop: true, nameMatchMode: nameMatchMode, sortRule: sort);
 }
示例#32
0
        public static IQueryable <AlbumForUser> OrderBy(this IQueryable <AlbumForUser> query, AlbumSortRule sortRule, ContentLanguagePreference languagePreference)
        {
            switch (sortRule)
            {
            case AlbumSortRule.Name:
                return(OrderByAlbumName(query, languagePreference));

            case AlbumSortRule.CollectionCount:
                return(query.OrderByDescending(a => a.Album.UserCollections.Count));

            case AlbumSortRule.ReleaseDate:
                return(query
                       .WhereHasReleaseDate()
                       .OrderByReleaseDate());

            case AlbumSortRule.ReleaseDateWithNulls:
                return(query.OrderByReleaseDate());

            case AlbumSortRule.AdditionDate:
                return(query.OrderByDescending(a => a.Album.CreateDate));

            case AlbumSortRule.RatingAverage:
                return(query.OrderByDescending(a => a.Album.RatingAverageInt)
                       .ThenByDescending(a => a.Album.RatingCount));

            case AlbumSortRule.RatingTotal:
                return(query.OrderByDescending(a => a.Album.RatingTotal)
                       .ThenByDescending(a => a.Album.RatingAverageInt));

            case AlbumSortRule.NameThenReleaseDate:
                return(OrderByAlbumName(query, languagePreference)
                       .ThenBy(a => a.Album.OriginalRelease.ReleaseDate.Year)
                       .ThenBy(a => a.Album.OriginalRelease.ReleaseDate.Month)
                       .ThenBy(a => a.Album.OriginalRelease.ReleaseDate.Day));
            }

            return(query);
        }