UTB.Eshop_2021/UTB.Eshop.Web/Controllers/HomeController.cs

47 lines
1.3 KiB
C#

using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using UTB.Eshop.Web.Models;
using UTB.Eshop.Web.Models.Database;
using UTB.Eshop.Web.Models.ViewModels;
namespace UTB.Eshop.Web.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
readonly EshopDbContext eshopDbContext;
public HomeController(ILogger<HomeController> logger, EshopDbContext eshopDb)
{
_logger = logger;
eshopDbContext = eshopDb;
}
public IActionResult Index()
{
_logger.LogInformation("Načtení Home Index");
IndexViewModel indexVM = new IndexViewModel();
indexVM.CarouselItems = eshopDbContext.CarouselItems.ToList();
indexVM.Products = eshopDbContext.Products.ToList();
return View(indexVM);
}
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 });
}
}
}