public ProductDTO GetProductById(int productId) { var dbProduct = broker.GetProductById(productId); var dto = DBProductMapper.DBProductToProductDTO(dbProduct, dbProduct.ProductCategory); return(dto); }
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); }
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); }