コード例 #1
0
        public async Task <IEnumerable <ItemDto> > Get(string sort        = null,
                                                       bool asc           = true,
                                                       string characterId = null,
                                                       bool?isEquipped    = null,
                                                       int pageSize       = 50,
                                                       int pageNumber     = 1)
        {
            var filter = new ItemFilterDto
            {
                SortCriteria        = sort,
                SortAscending       = asc,
                PageSize            = pageSize,
                RequestedPageNumber = pageNumber
            };

            if (isEquipped.HasValue)
            {
                filter.IsEquipped = isEquipped.Value;
            }

            if (characterId != null)
            {
                filter.OwnerId = Guid.Parse(characterId);
            }

            var characters = (await CharacterFacade.GetItemsByFilterAsync(filter)).Items;

            return(characters);
        }
コード例 #2
0
 private static SimplePredicate FilterItemName(ItemFilterDto filter)
 {
     return(string.IsNullOrWhiteSpace(filter.Name)
         ? null
         : new SimplePredicate(nameof(Item.Name),
                               ValueComparingOperator.StringContains,
                               filter.Name));
 }
コード例 #3
0
 private IPredicate FilterItemOwner(ItemFilterDto filter)
 {
     return(!filter.OwnerId.HasValue
         ? null
         : new SimplePredicate(nameof(Item.OwnerId),
                               ValueComparingOperator.Equal,
                               filter.OwnerId.Value));
 }
コード例 #4
0
 private IPredicate FilterItemType(ItemFilterDto filter)
 {
     return(!filter.ItemType.HasValue
         ? null
         : new SimplePredicate(nameof(Item.ItemType),
                               ValueComparingOperator.Equal,
                               filter.ItemType.Value));
 }
コード例 #5
0
 private IPredicate FilterIsEquipped(ItemFilterDto filter)
 {
     return(!filter.IsEquipped.HasValue
         ? null
         : new SimplePredicate(nameof(Item.Equipped),
                               ValueComparingOperator.Equal,
                               filter.IsEquipped.Value));
 }
コード例 #6
0
        private static SimplePredicate FilterAuction(ItemFilterDto filter)
        {
            if (filter.AuctionID == 0)
            {
                return(null);
            }

            return(new SimplePredicate(nameof(Item.AuctionID), ValueComparingOperator.Equal,
                                       filter.AuctionID));
        }
コード例 #7
0
        private static SimplePredicate FilterName(ItemFilterDto filter)
        {
            if (string.IsNullOrWhiteSpace(filter.SearchedName))
            {
                return(null);
            }

            return(new SimplePredicate(nameof(Item.Name), ValueComparingOperator.StringContains,
                                       filter.SearchedName));
        }
コード例 #8
0
ファイル: ItemFacade.cs プロジェクト: MiriamaSasarakova/pv179
        public async Task <IEnumerable <ItemDto> > GetFilteredItems(ItemFilterDto filter)
        {
            using (UnitOfWorkProvider.Create())
            {
                if (filter == null)
                {
                    var temp = await itemService.ListAllAsync();

                    return(temp.Items);
                }

                return(await itemService.ListFilteredItems(filter));
            }
        }
コード例 #9
0
        private static CompositePredicate FilterCategories(ItemFilterDto filter)
        {
            if (filter.ItemCategoryTypes == null || filter.ItemCategoryTypes.Any())
            {
                return(null);
            }

            var categoryTypesPredicates = new List <IPredicate>(filter.ItemCategoryTypes
                                                                .Select(cat => new SimplePredicate
                                                                            (nameof(ItemCategory.Id),
                                                                            ValueComparingOperator.Equal,
                                                                            cat.Id)));

            return(new CompositePredicate(categoryTypesPredicates, LogicalOperator.OR));
        }
コード例 #10
0
        protected override IQuery <Item> ApplyWhereClause(IQuery <Item> query, ItemFilterDto filter)
        {
            var definedPredicates = new List <IPredicate>();

            AddIfDefined(FilterName(filter), definedPredicates);
            AddIfDefined(FilterCategories(filter), definedPredicates);
            AddIfDefined(FilterUser(filter), definedPredicates);
            AddIfDefined(FilterAuction(filter), definedPredicates);
            if (definedPredicates.Count == 0)
            {
                return(query);
            }
            if (definedPredicates.Count == 1)
            {
                return(query.Where(definedPredicates.First()));
            }
            var wherePredicate = new CompositePredicate(definedPredicates);

            return(query.Where(wherePredicate));
        }
コード例 #11
0
        protected override IQuery <Item> ApplyWhereClause(IQuery <Item> query, ItemFilterDto filter)
        {
            var predicates = new List <IPredicate>();

            AddIfDefined(FilterItemName(filter), predicates);
            AddIfDefined(FilterItemOwner(filter), predicates);
            AddIfDefined(FilterItemType(filter), predicates);
            AddIfDefined(FilterIsEquipped(filter), predicates);

            if (predicates.Count == 0)
            {
                return(query);
            }
            if (predicates.Count == 1)
            {
                return(query.Where(predicates.First()));
            }
            var wherePredicate = new CompositePredicate(predicates);

            return(query.Where(wherePredicate));
        }
コード例 #12
0
 /// <summary>
 /// Gets inventory of character
 /// </summary>
 /// <returns>all customers</returns>
 public async Task <QueryResultDto <ItemDto, ItemFilterDto> > GetItemsByFilterAsync(ItemFilterDto filter)
 {
     using (UnitOfWorkProvider.Create())
     {
         return(await _itemService.ListItemsAsync(filter));
     }
 }