public PaginationDto <Domain.Dto.Product.ProductDto> SearchProducts(ProductUserSearchDto dto) { var query = _dbContext.Products .AsQueryable(); if (!string.IsNullOrEmpty(dto.Title)) { query = query.Where(c => c.Title.Contains(dto.Title)); } IOrderedQueryable <Product> orderedQery = query.OrderByDescending(c => c.Id); return(orderedQery.ToPaginated(dto).ToDto()); }
public ServiceResult <CategoryProductsDto> GetProducts(ProductUserSearchDto dto) { var serviceResult = new ServiceResult <CategoryProductsDto>(true); var category = _dbContext .Categories .AsEnumerable() .Where(c => c.Id == dto.CategoryId) .ToList() .FirstOrDefault(); if (category == null) { serviceResult.AddError("دسته بندی یافت نشد"); } else { _catIds.Add(category.Id); if (category.Children != null && category.Children.Count > 0) { GetCategoryIds_Recursive(category.Children.ToList()); } var query = _dbContext.Products .Where(c => _catIds.Any(i => i == c.CategoryId)) .AsQueryable(); if (!string.IsNullOrEmpty(dto.Title)) { query = query.Where(c => c.Title.Contains(dto.Title)); } IOrderedQueryable <Product> orderedQery = query.OrderByDescending(c => c.Id); serviceResult.Data = new CategoryProductsDto(); serviceResult.Data.Products = orderedQery.ToPaginated(dto).ToDto(); serviceResult.Data.CategoryName = category.Title; } return(serviceResult); }