135 lines
3.5 KiB
C#
135 lines
3.5 KiB
C#
using TravelAgencyContracts.BindingModels;
|
|
using TravelAgencyContracts.ViewModels;
|
|
using TravelAgencyWebApp.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Diagnostics;
|
|
using TravelAgencyContracts.BusinessLogicsContracts;
|
|
using TravelAgencyContracts.SearchModels;
|
|
|
|
namespace TravelAgencyWebApp.Controllers
|
|
{
|
|
public class HomeController : Controller
|
|
{
|
|
private readonly ILogger<HomeController> _logger;
|
|
|
|
private readonly IUserLogic _userLogic;
|
|
|
|
public HomeController(ILogger<HomeController> logger, IUserLogic userLogic)
|
|
{
|
|
_logger = logger;
|
|
_userLogic = userLogic;
|
|
}
|
|
|
|
public IActionResult Index()
|
|
{
|
|
if (LoggedinUser.User == null)
|
|
{
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
|
|
return View(LoggedinUser.User);
|
|
}
|
|
|
|
[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]
|
|
public IActionResult ReportMenu()
|
|
{
|
|
return View();
|
|
}
|
|
[HttpGet]
|
|
public IActionResult ReportPlaceTour()
|
|
{
|
|
return View(new List<ReportPlaceTourViewModel>());
|
|
}
|
|
[HttpGet]
|
|
public IActionResult ReportTourPeriod()
|
|
{
|
|
return View(new List<ReportTourPeriodViewModel>());
|
|
}
|
|
|
|
[HttpGet]
|
|
public IActionResult Enter()
|
|
{
|
|
if (LoggedinUser.User != null)
|
|
{
|
|
throw new Exception("Вы уже авторизовались!");
|
|
}
|
|
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public void Enter(string email, string password)
|
|
{
|
|
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");
|
|
}
|
|
|
|
[HttpGet]
|
|
public IActionResult Register()
|
|
{
|
|
if (LoggedinUser.User != null)
|
|
{
|
|
throw new Exception("Вы уже зарегистрировались!");
|
|
}
|
|
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public void Register(string fio, string email, string password, string phone)
|
|
{
|
|
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");
|
|
}
|
|
|
|
public void Logout()
|
|
{
|
|
if (LoggedinUser.User == null)
|
|
{
|
|
throw new Exception("Необходимо авторизоваться!");
|
|
}
|
|
|
|
LoggedinUser.User = null;
|
|
Response.Redirect("Enter");
|
|
}
|
|
|
|
}
|
|
}
|