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); }
private static SimplePredicate FilterItemName(ItemFilterDto filter) { return(string.IsNullOrWhiteSpace(filter.Name) ? null : new SimplePredicate(nameof(Item.Name), ValueComparingOperator.StringContains, filter.Name)); }
private IPredicate FilterItemOwner(ItemFilterDto filter) { return(!filter.OwnerId.HasValue ? null : new SimplePredicate(nameof(Item.OwnerId), ValueComparingOperator.Equal, filter.OwnerId.Value)); }
private IPredicate FilterItemType(ItemFilterDto filter) { return(!filter.ItemType.HasValue ? null : new SimplePredicate(nameof(Item.ItemType), ValueComparingOperator.Equal, filter.ItemType.Value)); }
private IPredicate FilterIsEquipped(ItemFilterDto filter) { return(!filter.IsEquipped.HasValue ? null : new SimplePredicate(nameof(Item.Equipped), ValueComparingOperator.Equal, filter.IsEquipped.Value)); }
private static SimplePredicate FilterAuction(ItemFilterDto filter) { if (filter.AuctionID == 0) { return(null); } return(new SimplePredicate(nameof(Item.AuctionID), ValueComparingOperator.Equal, filter.AuctionID)); }
private static SimplePredicate FilterName(ItemFilterDto filter) { if (string.IsNullOrWhiteSpace(filter.SearchedName)) { return(null); } return(new SimplePredicate(nameof(Item.Name), ValueComparingOperator.StringContains, filter.SearchedName)); }
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)); } }
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)); }
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)); }
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)); }
/// <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)); } }