public IHttpActionResult Get(int id) { try { // throw new Exception("Invalid operation occured"); Product product; var productRepository = new ProductRepository(); if (id > 0) { var res = productRepository.Retrieve(); product = res.Find(x => x.ProductId.Equals(id)); if (product == null) return NotFound(); } else { product = productRepository.Create(); } return Ok(product); } catch (Exception ex) { return InternalServerError(ex); } }
public IHttpActionResult Get() { try { var productRepository = new ProductRepository(); return Ok(productRepository.Retrieve().AsQueryable()); } catch (Exception ex) { return InternalServerError(ex); } }