56 lines
1.4 KiB
C#
56 lines
1.4 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System.Diagnostics;
|
|
using WebVentaCoche.DataBase;
|
|
using WebVentaCoche.Models;
|
|
|
|
namespace WebVentaCoche.Controllers
|
|
{
|
|
public class HomeController : Controller
|
|
{
|
|
private readonly ILogger<HomeController> _logger;
|
|
private readonly ApplicationDbContext _context;
|
|
|
|
|
|
public HomeController(ILogger<HomeController> logger, ApplicationDbContext context)
|
|
{
|
|
_logger = logger;
|
|
_context = context;
|
|
}
|
|
|
|
public IActionResult Index()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
public IActionResult Privacy()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
public IActionResult Error()
|
|
{
|
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
}
|
|
|
|
public async Task<IActionResult> ProductsHome()
|
|
{
|
|
var products = await _context.Products.ToListAsync();
|
|
return View(products);
|
|
}
|
|
|
|
public async Task<IActionResult> ProductsDetailsHome(int id)
|
|
{
|
|
var product = await _context.Products.FindAsync(id);
|
|
if (product == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
return View(product);
|
|
}
|
|
|
|
}
|
|
}
|