Exemple #1
0
        public IHttpActionResult Get(int id)
        {
            try
            {
                //throw new ArgumentNullException("This is a test");
                Product product;
                var productRepository = new ProductRepository();

                if (id > 0)
                {
                    var products = productRepository.Retrieve(); //retrieves everything, pretty bad
                    product = products.FirstOrDefault(p => p.ProductId == id); //LINQ
                    if (product == null)
                    {
                        return NotFound();
                    }
                }
                else
                {
                    product = productRepository.Create();
                }
                return Ok(product);
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }
        }
Exemple #2
0
 public IHttpActionResult Get()
 {
     try
     {
         var productRepository = new ProductRepository();
         return Ok(productRepository.Retrieve().AsQueryable());
     }
     catch (Exception ex)
     {
         return InternalServerError(ex);
     }
 }