This solution should help me explain my desire

This commit is contained in:
Tracy Pearson
2020-10-19 12:55:29 -04:00
parent 4e9964435b
commit 92445d4e7a
18 changed files with 280 additions and 71 deletions

View File

@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using RepositoryLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -10,10 +11,21 @@ namespace WebMVC.Controllers
{
public class ApiController : Controller
{
private readonly IRepository _repository;
public ApiController(IRepository repository)
{
_repository = repository;
}
public override void OnActionExecuted(ActionExecutedContext context)
{
// This is where I capture the error from the ApiService
// This is where I capture the error from when calling the ApiService
base.OnActionExecuted(context);
}
public async Task<IActionResult> Lookup()
{
var lookup = await _repository.Lookup();
return Ok(lookup);
}
}
}

View File

@@ -5,6 +5,7 @@ using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using RepositoryLibrary;
using WebMVC.Models;
namespace WebMVC.Controllers
@@ -12,10 +13,12 @@ namespace WebMVC.Controllers
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
private readonly IRepository _repository;
public HomeController(ILogger<HomeController> logger)
public HomeController(ILogger<HomeController> logger, IRepository repository)
{
_logger = logger;
_repository = repository;
}
public IActionResult Index()
@@ -23,8 +26,13 @@ namespace WebMVC.Controllers
return View();
}
public IActionResult Privacy()
public async Task<IActionResult> Privacy()
{
// To get this working, I have make a call here in the Privacy page.
// Making the call in the Home/Index page was always returning a 404 Not Found.
// The second project was not starting quickly enough.
var lookup = await _repository.Lookup();
return View();
}