コード例 #1
0
        public ProductDTO GetProductById(int productId)
        {
            var dbProduct = broker.GetProductById(productId);

            var dto = DBProductMapper.DBProductToProductDTO(dbProduct, dbProduct.ProductCategory);

            return(dto);
        }
コード例 #2
0
        public ProductDTO GetRandomProduct()
        {
            var dbProducts = broker.GetAllProducts();

            var dto = new ProductDTO();

            Random ran = new Random();

            var ranNum = ran.Next(dbProducts.Count - 1);

            dto = DBProductMapper.DBProductToProductDTO(dbProducts[ranNum], dbProducts[ranNum].ProductCategory);

            return(dto);
        }
コード例 #3
0
        public List <ProductDTO> GetAllProducts()
        {
            //var tempList = broker.GetAllProducts();
            List <ProductDTO> productList = new List <ProductDTO>();

            var catList = broker.GetAllCategoriesWithProducts();

            foreach (var category in catList)
            {
                foreach (var product in category.Product)
                {
                    productList.Add(DBProductMapper.DBProductToProductDTO(product, category));
                }
            }

            return(productList);
        }