//[HttpGet("rtrvp")] //[Route("products")] public IEnumerable <Product> GetProducts() { try { return(_repository.GetProducts()); } catch (Exception ex) { _logger.LogInformation($"Failed to get the products: {ex}"); return(null); } }
//[Authorize] : to use authorization through Angular: -we want people to shop before even they //login but while checkout they should have the login authrozied public IActionResult Shop() { //var result = _context.Products.ToList(); //var result = _context.Products.OrderBy(p => p.Category).ToList(); //var result = from p in _context.Products orderby p.Category select p; var result = _repository.GetProducts(); return(View(result.ToList())); }
// Use ActionResult instead of IEnumerable/Json to be flexible on return type // Can be further serialized according to the accept type from the request, eg xml or any newly invented data types // Tie the method calls to actual status codes // Json is the only built-in type that MVC 6 enables by default // IActionResult makes API documentation hard as it hides the actual retur type // So Use ActionResult<> to allow API to define what's returned public ActionResult <IEnumerable <Product> > Get() { try { return(Ok(_repository.GetProducts())); } catch (Exception e) { _logger.LogError($"Failed to get products: {e}"); return(BadRequest()); } }
public IActionResult Get() { try { return(Ok(_repository.GetProducts())); } catch (Exception ex) { _logger.LogError($"An Error occurred {ex}"); return(BadRequest("Not Found")); } }
public IActionResult Get() { try { return(Ok(_repository.GetProducts())); } catch (Exception ex) { _logger.LogError($"Failed to get products: {ex}"); return(BadRequest("Failed to get products")); } }
public IActionResult Index() { var results = _repository.GetProducts(); return(View()); }
public IActionResult Shop() { return(View(_repository.GetProducts().ToList())); }
public IActionResult Shop() { var results = _repository.GetProducts(); return(View(results)); }