コード例 #1
0
 static Expression <Func <Publisher, bool> > GetFilterCondition(PublisherMaintenanceFilterCondition condition)
 {
     return(condition switch
     {
         PublisherMaintenanceFilterCondition.NoFilter => p => true,
         PublisherMaintenanceFilterCondition.NoDescription => p => string.IsNullOrEmpty(p.Description),
         PublisherMaintenanceFilterCondition.NoBooks => p => p.Books.Count == 0,
         PublisherMaintenanceFilterCondition.NoLogoPicture => p => p.LogoPath.Contains("placeholder"),
         _ => throw new ArgumentOutOfRangeException(nameof(condition), "Invalid filter condition!")
     });
コード例 #2
0
        public async Task <IEnumerable <LookupItem> > GetPublisherLookupAsync(string viewModelName,
                                                                              PublisherMaintenanceFilterCondition publisherMaintenanceFilterCondition = PublisherMaintenanceFilterCondition.NoFilter)
        {
            var filter = GetFilterCondition(publisherMaintenanceFilterCondition);

            await using var ctx = _contextCreator();
            return(await ctx.Publishers
                   .AsNoTracking()
                   .Where(filter)
                   .OrderBy(p => p.Name)
                   .Select(p =>
                           new LookupItem
            {
                Id = p.Id,
                DisplayMember = p.Name,
                Picture = GetPictureThumbnail(p.LogoPath) ?? _placeholderPic,
                ViewModelName = viewModelName,
                InfoText = $"Books: {p.Books.Count}",
            })
                   .ToListAsync());