// If we not find method with this parameter then we will return Get above // parameter name must match with query string parameter public IEnumerable<Product> Get(string search) { // repository var res = new ProductRepository(); var products = res.Retrieve(); if (string.IsNullOrEmpty(search)) return products; else return products.Where(c => c.ProductCode.Contains(search)); }
// GET: api/Products/5 public Product Get(int id) { Product product; var res = new ProductRepository(); if (id > 0) { var products = res.Retrieve(); product = products.FirstOrDefault(c => c.ProductId == id); } else { product = res.Create(); } return product; }
// GET: api/Products public IEnumerable<Product> Get() { // repository var res = new ProductRepository(); return res.Retrieve(); }
public ProductsController() { res = new ProductRepository(); }