Ejemplo n.º 1
0
 //[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);
     }
 }
Ejemplo n.º 2
0
        //[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());
     }
 }
Ejemplo n.º 4
0
 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());
        }
Ejemplo n.º 7
0
 public IActionResult Shop()
 {
     return(View(_repository.GetProducts().ToList()));
 }
Ejemplo n.º 8
0
        public IActionResult Shop()
        {
            var results = _repository.GetProducts();

            return(View(results));
        }