Esempio n. 1
0
        public List <ProductDataAccessResponse> GetCatalogSearchBar(GetSearchBarRequest request)
        {
            List <ProductDataAccessResponse> _dataAccessResponse = new List <ProductDataAccessResponse>();

            try
            {
                MASFARMACIADEVContext context = new MASFARMACIADEVContext();
                var query = from p in context.ProductsEntity
                            join m in context.MarcasEntity on p.IdMarca equals m.IdMarca
                            join path in context.ResourcesEntity on p.IdResoruce equals path.IdResource
                            join cat in context.CategorysEntity on p.IdCategory equals cat.IdCategory
                            join subcat in context.SubCategorysEntity on p.IdSubCategory equals subcat.IdSubCategory
                            where (m.Description.Contains(request.SearchBarText) || p.Description.Contains(request.SearchBarText)) && p.Stock > 0
                            select new
                {
                    ProductDataAccessResponse = new ProductDataAccessResponse
                    {
                        ProductCard = new ProductCardResponse
                        {
                            IdProduct = p.IdProduct,
                            Name      = p.Name,
                            Marca     = m.Description,
                            Price     = p.Price,
                            Path      = path.Path
                        },
                        CategoryUsed = new CategorysEntity
                        {
                            IdCategory  = p.IdCategory,
                            Description = cat.Description
                        },
                        SubCategoryUsed = new SubCategorysEntity
                        {
                            IdSubCategory = p.IdSubCategory,
                            Description   = subcat.Description,
                            IdCategory    = subcat.IdCategory
                        },
                        MarcaUsed = new MarcasEntity
                        {
                            IdMarca     = m.IdMarca,
                            Description = m.Description
                        }
                    }
                };
                if (query != null)
                {
                    foreach (var obj in query)
                    {
                        _dataAccessResponse.Add(obj.ProductDataAccessResponse);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("ProductDataAccess.GetCatalogSearchBar : ERROR : " + ex.Message);
                throw;
            }
            return(_dataAccessResponse);
        }
Esempio n. 2
0
        public GetCatalogResponse GetCatalogSearchBar(GetSearchBarRequest request)
        {
            var getCatalogResponse = new GetCatalogResponse();

            try
            {
                var _dataAccessResponse = _productDataAccess.GetCatalogSearchBar(request);
                if (_dataAccessResponse != null)
                {
                    getCatalogResponse = _productHelper.CreateList(_dataAccessResponse);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("ProductModel.GetCatalogSearchBar : ERROR : " + ex.Message);
                throw;
            }
            return(getCatalogResponse);
        }
        public List <ProductDataAccessResponse> GetCatalogSearchBar(GetSearchBarRequest request)
        {
            var _dataAccessResponse = new List <ProductDataAccessResponse>();

            try
            {
                var query = from p in context.ProductsEntity
                            join m in context.MarcasEntity on p.IdMarca equals m.IdMarca
                            join cat in context.CategorysEntity on p.IdCategory equals cat.IdCategory
                            join subcat in context.SubCategorysEntity on p.IdSubCategory equals subcat.IdSubCategory
                            where (m.Description.Contains(request.SearchBarText) || p.Description.Contains(request.SearchBarText)) && p.Stock > 0
                            select new
                {
                    ProductDataAccessResponse = new ProductDataAccessResponse
                    {
                        ProductEntity = new GetProductResponse
                        {
                            IdProduct     = p.IdProduct,
                            Description   = p.Description,
                            Name          = p.Name,
                            IdMarca       = p.IdMarca,
                            Marca         = m.Description,
                            Price         = p.Price,
                            Stock         = p.Stock,
                            IdCategory    = p.IdCategory,
                            Category      = cat.Description,
                            IdSubCategory = p.IdSubCategory,
                            SubCategory   = subcat.Description,
                            EAN           = p.EAN,
                            ImgCount      = p.ImgCount
                        },
                        CategoryUsed = new CategorysEntity
                        {
                            IdCategory  = p.IdCategory,
                            Description = cat.Description
                        },
                        SubCategoryUsed = new SubCategorysEntity
                        {
                            IdSubCategory = p.IdSubCategory,
                            Description   = subcat.Description,
                            IdCategory    = subcat.IdCategory
                        },
                        MarcaUsed = new MarcasEntity
                        {
                            IdMarca     = p.IdMarca,
                            Description = m.Description
                        }
                    }
                };
                if (query != null)
                {
                    foreach (var obj in query)
                    {
                        _dataAccessResponse.Add(obj.ProductDataAccessResponse);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("ProductDataAccess.GetCatalogSearchBar : ERROR : " + ex.Message);
                throw;
            }
            return(_dataAccessResponse);
        }