Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        /// <exception cref="NullResultException">Query result returns null/empty list.</exception>
        List <Product> IProductRepository.GetProduct(ProductFetchingFilter filter)
        {
            var rawProductList = dbContext.Products
                                 .Include(p => p.Company)
                                 .Include(p => p.Builds);
            var queryResult = (from products in rawProductList
                               select products).ToList();

            if (filter.ExactName != null)
            {
                queryResult = queryResult.FilterReportsByExactName(filter.ExactName).ToList();
            }

            if (filter.Name != null)
            {
                queryResult = queryResult.FilterReportsByName(filter.Name).ToList();
            }

            if (filter.CompanyId != null)
            {
                queryResult = queryResult.FilterReportsByCompanyId(filter.CompanyId.Value).ToList();
            }

            if (queryResult == null)
            {
                throw new NullResultException("Could not fetch any product.");
            }
            //if (!queryResult.Any()) { throw new NullResultException("Could not fetch any product."); }
            return(queryResult);
        }
Пример #2
0
        List <ProductQueryData> IProductService.GetProduct(ProductFetchingFilter filter)
        {
            List <DAL.Models.Product> productList = null;

            try
            {
                productList = productRepository.GetProduct(filter);
            }
            catch (NullResultException)
            {
                throw;
            }
            List <ProductQueryData> queryResultList = new List <ProductQueryData>();

            foreach (var product in productList)
            {
                queryResultList.Add(new ProductQueryData(product));
            }
            return(queryResultList);
        }