Exemplo n.º 1
0
        public List <ProductDataAccessResponse> GetCatalogFilter(GetCatalogRequest 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 (p.Price > request.PriceMin && p.Price < request.PriceMax && 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.GetCatalogAll : ERROR : " + ex.Message);
                throw;
            }
            return(_dataAccessResponse);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a waiter using the provided configuration.
        /// </summary>
        /// <param name="request">Request to send.</param>
        /// <param name="config">Wait Configuration</param>
        /// <param name="targetStates">Desired resource states. If multiple states are provided then the waiter will return once the resource reaches any of the provided states</param>
        /// <returns>a new Oci.common.Waiter instance</returns>
        public Waiter <GetCatalogRequest, GetCatalogResponse> ForCatalog(GetCatalogRequest request, WaiterConfiguration config, params LifecycleState[] targetStates)
        {
            var agent = new WaiterAgent <GetCatalogRequest, GetCatalogResponse>(
                request,
                request => client.GetCatalog(request),
                response => targetStates.Contains(response.Catalog.LifecycleState.Value),
                targetStates.Contains(LifecycleState.Deleted)
                );

            return(new Waiter <GetCatalogRequest, GetCatalogResponse>(config, agent));
        }
Exemplo n.º 3
0
        public GetCatalogResponse GetCatalogByFilter(GetCatalogRequest request)
        {
            var getCatalogResponse = new GetCatalogResponse();

            try
            {
                var _dataAccessResponse = _productDataAccess.GetCatalogFilter(request);
                if (_dataAccessResponse != null)
                {
                    getCatalogResponse = _productHelper.CatalogFilter(_dataAccessResponse, request);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("ProductModel.GetCatalogByFilter : ERROR : " + ex.Message);
                throw;
            }
            return(getCatalogResponse);
        }
Exemplo n.º 4
0
        private void HandleOutput(GetCatalogRequest request)
        {
            var waiterConfig = new WaiterConfiguration
            {
                MaxAttempts           = MaxWaitAttempts,
                GetNextDelayInSeconds = (_) => WaitIntervalSeconds
            };

            switch (ParameterSetName)
            {
            case LifecycleStateParamSet:
                response = client.Waiters.ForCatalog(request, waiterConfig, WaitForLifecycleState).Execute();
                break;

            case Default:
                response = client.GetCatalog(request).GetAwaiter().GetResult();
                break;
            }
            WriteOutput(response, response.Catalog);
        }
Exemplo n.º 5
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            GetCatalogRequest request;

            try
            {
                request = new GetCatalogRequest
                {
                    CatalogId    = CatalogId,
                    OpcRequestId = OpcRequestId
                };

                HandleOutput(request);
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
 /// <summary>
 /// Creates a waiter using default wait configuration.
 /// </summary>
 /// <param name="request">Request to send.</param>
 /// <param name="targetStates">Desired resource states. If multiple states are provided then the waiter will return once the resource reaches any of the provided states</param>
 /// <returns>a new Oci.common.Waiter instance</returns>
 public Waiter <GetCatalogRequest, GetCatalogResponse> ForCatalog(GetCatalogRequest request, params LifecycleState[] targetStates)
 {
     return(this.ForCatalog(request, WaiterConfiguration.DefaultWaiterConfiguration, targetStates));
 }
        public List <ProductDataAccessResponse> GetCatalogFilter(GetCatalogRequest 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 (p.Price > request.PriceMin && p.Price < request.PriceMax && 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     = m.IdMarca,
                            Description = m.Description
                        }
                    }
                };
                if (query != null)
                {
                    foreach (var obj in query)
                    {
                        _dataAccessResponse.Add(obj.ProductDataAccessResponse);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("ProductDataAccess.GetCatalogFilter : ERROR : " + ex.Message);
                throw;
            }
            return(_dataAccessResponse);
        }