135 lines
3.5 KiB
C#
Raw Normal View History

2024-04-30 18:42:41 +04:00
using TravelAgencyContracts.BindingModels;
using TravelAgencyContracts.ViewModels;
using TravelAgencyWebApp.Models;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
2024-05-28 18:32:51 +04:00
using TravelAgencyContracts.BusinessLogicsContracts;
using TravelAgencyContracts.SearchModels;
2024-04-30 18:42:41 +04:00
namespace TravelAgencyWebApp.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
2024-05-28 18:32:51 +04:00
private readonly IUserLogic _userLogic;
public HomeController(ILogger<HomeController> logger, IUserLogic userLogic)
2024-04-30 18:42:41 +04:00
{
_logger = logger;
2024-05-28 18:32:51 +04:00
_userLogic = userLogic;
2024-04-30 18:42:41 +04:00
}
public IActionResult Index()
{
2024-05-28 18:32:51 +04:00
if (LoggedinUser.User == null)
{
return Redirect("~/Home/Enter");
}
return View(LoggedinUser.User);
2024-04-30 18:42:41 +04:00
}
[HttpGet]
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 });
}
[HttpGet]
2024-05-28 18:32:51 +04:00
public IActionResult ReportMenu()
2024-04-30 18:42:41 +04:00
{
return View();
}
[HttpGet]
2024-05-28 18:32:51 +04:00
public IActionResult ReportPlaceTour()
2024-04-30 18:42:41 +04:00
{
2024-05-28 18:32:51 +04:00
return View(new List<ReportPlaceTourViewModel>());
2024-04-30 18:42:41 +04:00
}
[HttpGet]
2024-05-28 18:32:51 +04:00
public IActionResult ReportTourPeriod()
2024-04-30 18:42:41 +04:00
{
2024-05-28 18:32:51 +04:00
return View(new List<ReportTourPeriodViewModel>());
2024-04-30 18:42:41 +04:00
}
2024-05-28 18:32:51 +04:00
2024-04-30 18:42:41 +04:00
[HttpGet]
2024-05-28 18:32:51 +04:00
public IActionResult Enter()
2024-04-30 18:42:41 +04:00
{
2024-05-28 18:32:51 +04:00
if (LoggedinUser.User != null)
{
throw new Exception("Вы уже авторизовались!");
}
2024-04-30 18:42:41 +04:00
return View();
}
2024-05-28 18:32:51 +04:00
[HttpPost]
public void Enter(string email, string password)
2024-04-30 18:42:41 +04:00
{
2024-05-28 18:32:51 +04:00
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
{
throw new Exception("Введены не все данные!");
}
LoggedinUser.User = _userLogic.ReadElement(new UserSearchModel
{
Email = email,
Password = password
});
if (LoggedinUser.User == null)
{
throw new Exception("Неверный логин/пароль");
}
Response.Redirect("Index");
2024-04-30 18:42:41 +04:00
}
2024-05-28 18:32:51 +04:00
2024-04-30 18:42:41 +04:00
[HttpGet]
2024-05-28 18:32:51 +04:00
public IActionResult Register()
2024-04-30 18:42:41 +04:00
{
2024-05-28 18:32:51 +04:00
if (LoggedinUser.User != null)
{
throw new Exception("Вы уже зарегистрировались!");
}
2024-04-30 18:42:41 +04:00
return View();
}
2024-05-28 18:32:51 +04:00
[HttpPost]
public void Register(string fio, string email, string password, string phone)
2024-04-30 18:42:41 +04:00
{
2024-05-28 18:32:51 +04:00
if (string.IsNullOrEmpty(fio) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
{
throw new Exception("Введены не все данные!");
}
_userLogic.Create(new UserBindingModel
{
UserFIO = fio,
Email = email,
PhoneNumber = phone,
Password = password
});
Response.Redirect("Enter");
2024-04-30 18:42:41 +04:00
}
2024-05-28 18:32:51 +04:00
public void Logout()
2024-04-30 18:42:41 +04:00
{
2024-05-28 18:32:51 +04:00
if (LoggedinUser.User == null)
{
throw new Exception("Необходимо авторизоваться!");
}
LoggedinUser.User = null;
Response.Redirect("Enter");
2024-04-30 18:42:41 +04:00
}
2024-05-28 18:32:51 +04:00
2024-04-30 18:42:41 +04:00
}
}