public async Task <ActionResult> GetFullCatalog() { var data = await _context .ShoppingItems .AsNoTracking() .TagWith("catalog#getfullcatalog") .Where(item => item.InInventory) .ProjectTo <GetCatalogResponseSummaryItem>(_mapperConfig) //.Select(item => _mapper.Map<GetCatalogResponseSummaryItem>(item)) //.Select(item => new GetCatalogResponseSummaryItem //{ // Id = item.Id, // Description = item.Description, // Price = item.Cost * _config.GetValue<decimal>("markUp") //}) .ToListAsync(); var response = new GetCatalogResponse { Data = data }; _logger.LogInformation("Got a get on catalog."); return(Ok(response)); }
public GetCatalogResponse CatalogFilter(List <ProductDataAccessResponse> _dataAccessResponse, GetCatalogRequest request) { GetCatalogResponse getCatalogResponse = new GetCatalogResponse(); var listCardsTemp = new List <GetProductResponse>(); var listCategorysTemp = new List <CategorysEntity>(); var listSubCategorysTemp = new List <SubCategorysEntity>(); var listMarcasTemp = new List <MarcasEntity>(); var tempObj = _dataAccessResponse; if (request.IdFilteredCategories.Count > 0) { tempObj = tempObj.Select(P => P).Where(P => request.IdFilteredCategories.Contains(P.ProductEntity.IdCategory)).ToList(); } if (request.IdFilteredSubCategories.Count > 0) { tempObj = tempObj.Select(P => P).Where(P => request.IdFilteredSubCategories.Contains(P.ProductEntity.IdSubCategory)).ToList(); } if (request.IdFilteredMarcas.Count > 0) { tempObj = tempObj.Select(P => P).Where(P => request.IdFilteredMarcas.Contains(P.ProductEntity.IdMarca)).ToList(); } foreach (var obj in tempObj) { listCardsTemp.Add(obj.ProductEntity); listCategorysTemp.Add(obj.CategoryUsed); listSubCategorysTemp.Add(obj.SubCategoryUsed); listMarcasTemp.Add(obj.MarcaUsed); } getCatalogResponse.Products = listCardsTemp.Take(60).GroupBy(x => x.IdProduct).Select(y => y.First()).ToList(); var listCategorysUniques = listCategorysTemp.GroupBy(x => x.IdCategory).Select(y => y.First()).ToList(); var listSubCategorysUniques = listSubCategorysTemp.GroupBy(x => x.IdSubCategory).Select(y => y.First()).ToList(); getCatalogResponse.Marcas = listMarcasTemp.GroupBy(x => x.IdMarca).Select(y => y.First()).ToList(); var listTrees = new List <GetCatalogResponse.CategorysCatalog>(); foreach (var cat in listCategorysUniques) { var categoryTree = new GetCatalogResponse.CategorysCatalog(); categoryTree.IdCategory = cat.IdCategory; categoryTree.Description = cat.Description; var listSubCategorysTree = new List <SubCategorysEntity>(); foreach (var subcat in listSubCategorysUniques) { if (subcat.IdCategory == cat.IdCategory) { listSubCategorysTree.Add(subcat); } } categoryTree.SubCategorys = listSubCategorysTree; listTrees.Add(categoryTree); } getCatalogResponse.Categorys = listTrees; return(getCatalogResponse); }
public async Task <ActionResult> GetFullCatalog() { var data = await _context .ShoppingItems .AsNoTracking() .TagWith("catalog#getfullcatalog") .Where(item => item.InInventory) .ProjectTo <GetCatalogResponseSummaryItem>(_mapperConfig) .ToListAsync(); var response = new GetCatalogResponse { Data = data }; return(Ok(response)); }
public GetCatalogResponse CatalogFilter(List <ProductDataAccessResponse> _dataAccessResponse, GetCatalogRequest request) { GetCatalogResponse getCatalogResponse = new GetCatalogResponse(); var listCardsTemp = new List <ProductCardResponse>(); var listCategorysTemp = new List <CategorysEntity>(); var listSubCategorysTemp = new List <SubCategorysEntity>(); var listMarcasTemp = new List <MarcasEntity>(); foreach (var obj in _dataAccessResponse) { //Filtro por categoria if (request.IdFilteredCategories.Contains(obj.CategoryUsed.IdCategory)) { listCardsTemp.Add(obj.ProductCard); listCategorysTemp.Add(obj.CategoryUsed); listSubCategorysTemp.Add(obj.SubCategoryUsed); listMarcasTemp.Add(obj.MarcaUsed); } //Filtro por subcategoria if (request.IdFilteredSubCategories.Contains(obj.SubCategoryUsed.IdSubCategory)) { listCardsTemp.Add(obj.ProductCard); listCategorysTemp.Add(obj.CategoryUsed); listSubCategorysTemp.Add(obj.SubCategoryUsed); listMarcasTemp.Add(obj.MarcaUsed); } //Filtro por marca if (request.IdFilteredMarcas.Contains(obj.MarcaUsed.IdMarca)) { listCardsTemp.Add(obj.ProductCard); listCategorysTemp.Add(obj.CategoryUsed); listSubCategorysTemp.Add(obj.SubCategoryUsed); listMarcasTemp.Add(obj.MarcaUsed); } } ; //Elimino repetidos y inserto en el objeto getCatalogResponse.ProductsCards = listCardsTemp.GroupBy(x => x.IdProduct).Select(y => y.First()).ToList(); getCatalogResponse.CategorysUsed = listCategorysTemp.GroupBy(x => x.IdCategory).Select(y => y.First()).ToList(); getCatalogResponse.SubCategorysUsed = listSubCategorysTemp.GroupBy(x => x.IdSubCategory).Select(y => y.First()).ToList(); getCatalogResponse.MarcasUsed = listMarcasTemp.GroupBy(x => x.IdMarca).Select(y => y.First()).ToList(); return(getCatalogResponse); }
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 async Task <ActionResult> GetFullCatalog() { var data = await _context .ShoppingItems .TagWith("catalog#getfullcatalog") // adds tag to logs .Where(item => item.InInventory) //.Select(item => _mapper.Map<GetCatalogResponseSummaryItem>(item)) .ProjectTo <GetCatalogResponseSummaryItem>(_mapperConfig) .ToListAsync(); var response = new GetCatalogResponse { Data = data }; _logger.LogInformation("Got a get on catalog."); return(Ok(response)); }
public GetCatalogResponse CreateList(List <ProductDataAccessResponse> _dataAccessResponse) { GetCatalogResponse getCatalogResponse = new GetCatalogResponse(); var listCardsTemp = new List <GetProductResponse>(); var listCategorysTemp = new List <CategorysEntity>(); var listSubCategorysTemp = new List <SubCategorysEntity>(); var listMarcasTemp = new List <MarcasEntity>(); foreach (var obj in _dataAccessResponse) { listCardsTemp.Add(obj.ProductEntity); listCategorysTemp.Add(obj.CategoryUsed); listSubCategorysTemp.Add(obj.SubCategoryUsed); listMarcasTemp.Add(obj.MarcaUsed); } getCatalogResponse.Products = listCardsTemp.Take(60).GroupBy(x => x.IdProduct).Select(y => y.First()).ToList(); var listCategorysUniques = listCategorysTemp.GroupBy(x => x.IdCategory).Select(y => y.First()).ToList(); var listSubCategorysUniques = listSubCategorysTemp.GroupBy(x => x.IdSubCategory).Select(y => y.First()).ToList(); getCatalogResponse.Marcas = listMarcasTemp.GroupBy(x => x.IdMarca).Select(y => y.First()).ToList(); var listTrees = new List <GetCatalogResponse.CategorysCatalog>(); foreach (var cat in listCategorysUniques) { var categoryTree = new GetCatalogResponse.CategorysCatalog(); categoryTree.IdCategory = cat.IdCategory; categoryTree.Description = cat.Description; var listSubCategorysTree = new List <SubCategorysEntity>(); foreach (var subcat in listSubCategorysUniques) { if (subcat.IdCategory == cat.IdCategory) { listSubCategorysTree.Add(subcat); } } categoryTree.SubCategorys = listSubCategorysTree; listTrees.Add(categoryTree); } getCatalogResponse.Categorys = listTrees; return(getCatalogResponse); }
public GetCatalogResponse GetCatalogAll() { GetCatalogResponse getCatalogResponse = new GetCatalogResponse(); try { ProductDataAcess _dataAccess = new ProductDataAcess(); var _dataAccessResponse = _dataAccess.GetCatalogAll(); if (_dataAccessResponse != null) { ProductHelper _helper = new ProductHelper(); getCatalogResponse = _helper.CreateList(_dataAccessResponse); } } catch (Exception ex) { Console.WriteLine("ProductModel.GetCatalogAll : ERROR : " + ex.Message); throw; } return(getCatalogResponse); }
public GetCatalogResponse CreateList(List <ProductDataAccessResponse> _dataAccessResponse) { GetCatalogResponse getCatalogResponse = new GetCatalogResponse(); var listCardsTemp = new List <ProductCardResponse>(); var listCategorysTemp = new List <CategorysEntity>(); var listSubCategorysTemp = new List <SubCategorysEntity>(); var listMarcasTemp = new List <MarcasEntity>(); foreach (var obj in _dataAccessResponse) { listCardsTemp.Add(obj.ProductCard); listCategorysTemp.Add(obj.CategoryUsed); listSubCategorysTemp.Add(obj.SubCategoryUsed); listMarcasTemp.Add(obj.MarcaUsed); } getCatalogResponse.ProductsCards = listCardsTemp; getCatalogResponse.CategorysUsed = listCategorysTemp.GroupBy(x => x.IdCategory).Select(y => y.First()).ToList(); getCatalogResponse.SubCategorysUsed = listSubCategorysTemp.GroupBy(x => x.IdSubCategory).Select(y => y.First()).ToList(); getCatalogResponse.MarcasUsed = listMarcasTemp.GroupBy(x => x.IdMarca).Select(y => y.First()).ToList(); return(getCatalogResponse); }