public IActionResult Shop() { // Pulls the results out from the entitiy framework. var results = _repository.GetAllProducts(); return(View(results)); }
//This action is created in order to create a shop that can display products thus making use of the database we just created //Before you can do this you need access to the "DutchContext.cs" class (which will now be declared in the AppController constructor above. public IActionResult Shop() { //The variable below goes into the database to fetch the products, orders it by category and returns it to us in a list //Code //var results = _context.Products.ToList() // .OrderBy(p => p.Category) // .ToList(); //We can also do the above using LINQ query (which will be illustrated below) //var results = from p in _context.Products // orderby p.Category // select p; //We're not querying the database directly here as it's unsafe which is why this method is favored over the above queries var results = _repository.GetAllProducts(); //This code below would work well if we were using the first "results" variable (which we commented out) because that variable was going to return as a list, however because we are currently using LINQ query, we have to use another return View with the added method of returning to list, it'll be illustrated below. //Code //return View(results); //The code below returns the products (obtained using LINQ query) as a list //Note that it is possible to pass data directly into the view as shown below //return View(results.ToList()); //We're not returning the results to a list because we already use an IEnumerable in the "IDutchRepository" to make it a list return(View(results)); }
public IActionResult Shop() { //Get products from the DB and return them var results = _repository.GetAllProducts(); return(View(results)); }
public IActionResult Shop() { //ViewBag.Title = "Shop"; var results = repository.GetAllProducts(); return(View(results)); }
public IActionResult Shop() { ViewBag.Title = "Shop"; var prods = _repository.GetAllProducts(); return(View(prods)); }
public IActionResult Shop() { // var result = _context.Products.OrderBy(p=>p.Category).ToList(); var result = _repository.GetAllProducts(); return(View(result)); }
public IActionResult Index() { //throw new InvalidOperationException(); var results = _repository.GetAllProducts(); return(View()); }
public IActionResult Get() { try{ return(Ok(_repository.GetAllProducts())); }catch (Exception er) { _logger.LogError($"Faild to get all products {er}"); return(BadRequest()); } }
public IActionResult Index() { // Set in Controller as opposed to in CSHTML. ViewBag.Title = "Home"; // Testing database seeding by querying Products table. _repository.GetAllProducts(); return(View()); }
public IActionResult Shop() { //var results = _context.Products.OrderBy(p => p.Category).ToList(); //var results = from t in _context.Products // orderby t.Category // select t; var results = _repository.GetAllProducts(); return(View(results)); }
public IActionResult Shop() { //var result = from p in _context.Products // orderby p.Category // select p; var results = _repository.GetAllProducts(); return(View(results)); }
public IActionResult Get() { try { return(Ok(dutchRepository.GetAllProducts())); } catch (Exception ex) { logger.LogError(ex.ToString()); return(BadRequest("Failed to get products")); } }
public IActionResult Shop() { //var results = _context.Products // .OrderBy(p => p.Category) // .ToList(); //we can do the above With a Linq query as follows: var results = _repository.GetAllProducts(); return(View(results.ToList())); }
public ActionResult <IEnumerable <Product> > Get() { try { return(Ok(repository.GetAllProducts())); } catch (Exception ex) { logger.LogError($"Failed to get products: {ex}"); return(BadRequest("Failed to get products")); } }
public ActionResult <IEnumerable <Product> > Get() { try { return(Ok(_repository.GetAllProducts())); } catch (Exception ex) { return(BadRequest($"Unable to get products: {ex.Message}")); } }
public ActionResult <IEnumerable <Product> > GetAllProducts() { try { return(Ok(_repository.GetAllProducts())); }catch (Exception ex) { _logger.LogInformation($"Failed to get products {ex}"); return(BadRequest("Bad Request")); } }
public IActionResult GetProducts() { try { return(Ok(_dutchRepo.GetAllProducts())); } catch (System.Exception ex) { _logger.LogError($"Failed to retrieve Products: {ex}"); return(BadRequest("Failed to get Products")); } }
public ActionResult <IEnumerable <Product> > Get() { try { return(Ok(_repository.GetAllProducts())); } catch (Exception ex) { _logger.LogError($"Bad Request: {ex}"); return(BadRequest("Bad Resquest")); } }
public IActionResult Get() { try { return(Ok(_repository.GetAllProducts())); } catch (Exception ex) { _logger.LogError($"Failed to get a result {ex.Message}"); return(BadRequest("Bad Result")); //Returns a 400. } }
public IActionResult Get() { try { return(Ok(_repository.GetAllProducts())); } catch (Exception exp) { _logger.LogError("Failed to get products Get() ", exp.ToString()); return(BadRequest("Failed to get products")); } }
public ActionResult <IEnumerable <Product> > Get() //The Only Action return type will help tools like swagger, to documents apis appropritely { try { return(Ok(_dutchRepository.GetAllProducts())); } catch (Exception ex) { _logger.LogError($"Failed to fetch the Products-{ex}"); return(BadRequest("Failed to get the products")); } }
public ActionResult <IEnumerable <Product> > GetProducts() { try { return(Ok(dutchRepository.GetAllProducts())); } catch (Exception e) { logger.LogError($"An error has occured {e}"); return(BadRequest()); } }
public ActionResult <IEnumerable <Product> > Get() { try { return(Ok(_repo.GetAllProducts())); } catch (System.Exception ex) { _logger.LogCritical($"Failed to get products: {ex}"); return(BadRequest("Failed to get products")); } }
public IActionResult Get() { try { return(Ok(repository.GetAllProducts())); } catch (Exception ex) { logger.LogInformation("logging exceptions : {0}", ex); return(BadRequest("Bad Request")); } }
public IActionResult Shop() { //var results = _context.Products // .OrderBy(p => p.Category) // .ToList(); //return View(results.ToList()); var _results = _repository.GetAllProducts(); return(View(_results.ToList())); }
public IActionResult Get() { try { return(Ok(_repository.GetAllProducts())); } catch (Exception ex) { _logger.LogError($"Failed to get products:{ex}"); return(BadRequest("Failed to get products")); } }
public IActionResult Get() { try { return(Ok(repository.GetAllProducts())); } catch (Exception e) { logger.LogError($"Get all products failed {e}"); return(BadRequest("Failed to get products")); } }
public ActionResult <IEnumerable <Product> > Get() { try { return(Ok(repository.GetAllProducts())); } catch (Exception ex) { var error = $"Oy vey: {ex}"; logger.LogError(error); return(BadRequest(error)); } }
//The ActionResult<IEnumerable<Product>> helps us specify how we want the product to be returned (which is as a list) and it is especially convenient especially when we're exposing an API to the public and we want to control how it is used. public ActionResult <IEnumerable <Product> > Get() { try { //The "Ok" is used to return an "Ok" status report return(Ok(_repository.GetAllProducts())); } catch (Exception ex) { _logger.LogError($"Failed to get products: {ex}"); return(BadRequest("failed to get products")); } }
public ActionResult <IEnumerable <Product> > Get() { try { return(Ok(_repository.GetAllProducts())); } catch (Exception e) { Console.WriteLine(e); _logger.LogError($"failed to get products: {e}"); return(BadRequest("Bad Request, check url and try again")); } }