Ejemplo n.º 1
0
        public List <Product> GetProductsByCriteria(GetProductBySearchTypeDto getProductBySearchTypeDto)
        {
            IEnumerable <ProductDto> productDtos = new List <ProductDto>();

            if (getProductBySearchTypeDto == null)
            {
                return(new List <Product>());
            }

            switch (getProductBySearchTypeDto.ProductSearchTypeId)
            {
            case 1:
                productDtos = _productDao.GetAllProducts();
                break;

            case 2:
                productDtos = _productDao.GetAllActiveProductsWithStatus(new ProductStatus().Active.Id);
                break;

            case 3:
                if (getProductBySearchTypeDto.ExtraParams == null || !getProductBySearchTypeDto.ExtraParams.ContainsKey("ZoneId"))
                {
                    productDtos = new List <ProductDto>();
                    break;
                }

                var zones = _zoneService.GetAllChildZones(int.Parse(getProductBySearchTypeDto.ExtraParams["ZoneId"]));

                productDtos = _productDao.GetAllActiveProductsForZones(zones.Select(x => x.ToDto()).ToList());
                break;

            case 4:
                productDtos = _productDao.GetAllActiveProductsWithStatus(new ProductStatus().Missing.Id);
                break;

            default:
                productDtos = new List <ProductDto>();
                break;
            }

            List <Product> products = new List <Product>();

            foreach (var productDto in productDtos)
            {
                Product product = Product.FromDto(productDto);

                product.Zone  = _zoneService.GetZoneById(productDto.ZoneId);
                product.Owner = _ownerService.GetOwnerById(productDto.OwnerId);

                products.Add(product);
            }

            return(products);
        }
Ejemplo n.º 2
0
        public Product GetProductById(int id)
        {
            ProductDto productDto = _productDao.GetProductById(id);

            return(Product.FromDto(productDto));
        }