homework/Controllers/HomeController.cs

68 lines
1.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using TechnoWorld.Data;
using TechnoWorld.Models;
namespace TechnoWorld.Controllers;
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}
public IActionResult Index()
{
ViewData["Title"] = "Главная";
ViewData["Hits"] = ProductStore.GetHits();
return View();
}
public IActionResult About()
{
ViewData["Title"] = "О системе";
return View();
}
[HttpGet]
public IActionResult Contacts()
{
ViewData["Title"] = "Контакты";
return View();
}
[HttpPost]
public IActionResult Contacts(ContactViewModel model)
{
if (ModelState.IsValid)
{
TempData["ContactSuccess"] = "Ваше сообщение принято! Мы свяжемся с вами в ближайшее время.";
return RedirectToAction(nameof(Contacts));
}
ViewData["Title"] = "Контакты";
return View(model);
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error(int? statusCode = null)
{
var model = new ErrorViewModel
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier,
StatusCode = statusCode
};
if (statusCode == 404)
ViewData["Title"] = "Страница не найдена";
else
ViewData["Title"] = "Ошибка";
return View(model);
}
}