using HotelContracts.BindingModels; using HotelContracts.SearchModels; using HotelContracts.ViewModels; using HotelOrganiserApp.Models; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; using System.Text; namespace HotelOrganiserApp.Controllers { public class HomeController : Controller { private readonly ILogger _logger; public HomeController(ILogger logger) { _logger = logger; } public IActionResult CreateMember() { if (APIClient.Organiser == null) { return Redirect("~/Home/Enter"); } return View(); } [HttpPost] public void CreateMember(string fio, string citizenship) { if (APIClient.Organiser == null) { throw new Exception("Необходима авторизация"); } if (string.IsNullOrEmpty(fio) || string.IsNullOrEmpty(citizenship)) { throw new Exception("Введите фио"); } if (string.IsNullOrEmpty(citizenship)) { throw new Exception("Введите гражданство"); } APIClient.PostRequest("api/main/createmember", new MemberBindingModel { MemberFIO = fio, Citizenship = citizenship, OrganiserId = APIClient.Organiser.Id, }); Response.Redirect("ListMembers"); } public IActionResult UpdateMember() { if (APIClient.Organiser == null) { return Redirect("~/Home/Enter"); } ViewBag.Members = APIClient.GetRequest>($"api/main/getmemberlist?organiserId={APIClient.Organiser.Id}"); return View(); } [HttpPost] public void UpdateMember(int member, string fio, string citizenship) { if (APIClient.Organiser == null) { throw new Exception("Необходима авторизация"); } if (string.IsNullOrEmpty(fio)) { throw new Exception("фио не может быть пустым"); } if (string.IsNullOrEmpty(citizenship)) { throw new Exception("Гражданство не может быть пустым"); } APIClient.PostRequest("api/main/updatemember", new MemberBindingModel { Id = member, MemberFIO = fio, Citizenship = citizenship, OrganiserId = APIClient.Organiser.Id, }); Response.Redirect("ListMembers"); } public IActionResult DeleteMember() { if (APIClient.Organiser == null) { return Redirect("~/Home/Enter"); } ViewBag.Members = APIClient.GetRequest>($"api/main/getmemberlist?organiserId={APIClient.Organiser.Id}"); return View(); } [HttpPost] public void DeleteMember(int member) { if (APIClient.Organiser == null) { throw new Exception("Необходима авторизация"); } APIClient.PostRequest("api/main/deletemember", new MemberBindingModel { Id = member }); Response.Redirect("ListMembers"); } [HttpGet] public MemberViewModel? GetMember(int memberId) { if (APIClient.Organiser == null) { throw new Exception("Необходима авторизация"); } var result = APIClient.GetRequest($"api/main/getmember?memberid={memberId}"); if (result == null) { return default; } var memberFIO = result.MemberFIO; var citizenship = result.Citizenship; return result; } public IActionResult Index() { if (APIClient.Organiser == null) { return Redirect("~/Home/Enter"); } return View(); } public IActionResult ListMembers() { if (APIClient.Organiser == null) { return Redirect("~/Home/Enter"); } return View(APIClient.GetRequest>($"api/main/getmemberlist?organiserId={APIClient.Organiser.Id}")); } public IActionResult CreateConference() { if (APIClient.Organiser == null) { return Redirect("~/Home/Enter"); } return View(); } [HttpPost] public void CreateConference(string conferenceName, DateTime startDate) { if (APIClient.Organiser == null) { throw new Exception("Необходима авторизация"); } if (string.IsNullOrEmpty(conferenceName) || string.IsNullOrEmpty(startDate.ToString())) { throw new Exception("Введите название"); } if (string.IsNullOrEmpty(startDate.ToString())) { throw new Exception("Введите дату"); } APIClient.PostRequest("api/main/createconference", new ConferenceBindingModel { ConferenceName = conferenceName, StartDate = startDate, OrganiserId = APIClient.Organiser.Id, }); Response.Redirect("ListConferences"); } public IActionResult DeleteConference() { if (APIClient.Organiser == null) { return Redirect("~/Home/Enter"); } ViewBag.Conferences = APIClient.GetRequest>($"api/main/getconferencelist?organiserId={APIClient.Organiser.Id}"); return View(); } [HttpPost] public void DeleteConference(int conference) { if (APIClient.Organiser == null) { throw new Exception("Необходима авторизация"); } APIClient.PostRequest("api/main/deleteconference", new ConferenceBindingModel { Id = conference }); Response.Redirect("ListConferences"); } public IActionResult UpdateConference() { if (APIClient.Organiser == null) { return Redirect("~/Home/Enter"); } ViewBag.Conferences = APIClient.GetRequest>($"api/main/getconferencelist?organiserId={APIClient.Organiser.Id}"); return View(); } [HttpPost] public void UpdateConference(int conference, string conferenceName, DateTime startDate) { if (APIClient.Organiser == null) { throw new Exception("Необходима авторизация"); } if (string.IsNullOrEmpty(conferenceName)) { throw new Exception("Название не может быть пустым"); } if (string.IsNullOrEmpty(startDate.ToString())) { throw new Exception("Дата не может быть пустым"); } APIClient.PostRequest("api/main/updateconference", new ConferenceBindingModel { Id = conference, ConferenceName = conferenceName, StartDate = startDate, OrganiserId = APIClient.Organiser.Id }); Response.Redirect("ListConferences"); } [HttpGet] public Tuple? GetConference(int conferenceId) { if (APIClient.Organiser == null) { throw new Exception("Необходима авторизация"); } var result = APIClient.GetRequest>>>($"api/main/getconference?conferenceId={conferenceId}"); if (result == null) { return default; } string table = ""; for (int i = 0; i < result.Item2.Count; i++) { var memberFIO = result.Item2[i].Item1; var citizenship = result.Item2[i].Item2; table += ""; table += $"{memberFIO}"; table += $"{citizenship}"; table += ""; } return Tuple.Create(result.Item1, table); } public IActionResult AddMemberToConference() { if (APIClient.Organiser == null) { return Redirect("~/Home/Enter"); } ViewBag.Conferences = APIClient.GetRequest>($"api/main/getconferencelist?organiserId={APIClient.Organiser.Id}"); ViewBag.Members = APIClient.GetRequest>($"api/main/getmemberlist?organiserId={APIClient.Organiser.Id}"); return View(); } [HttpPost] public void AddMemberToConference(int conference, int member) { if (APIClient.Organiser == null) { throw new Exception("Необходима авторизация"); } APIClient.PostRequest("api/main/AddMemberToConference", Tuple.Create( new ConferenceSearchModel() { Id = conference }, new MemberViewModel() { Id = member } )); Response.Redirect("ListConferences"); } public IActionResult ListConferences() { if (APIClient.Organiser == null) { return Redirect("~/Home/Enter"); } return View(APIClient.GetRequest>($"api/main/getconferencelist?organiserId={APIClient.Organiser.Id}")); } [HttpGet] public IActionResult Privacy() { if (APIClient.Organiser == null) { return Redirect("~/Home/Enter"); } return View(APIClient.Organiser); } [HttpPost] public void Privacy(string login, string email, string password, string fio, string telephone) { if (APIClient.Organiser == null) { throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); } if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) { throw new Exception("Введите логин, пароль и ФИО"); } APIClient.PostRequest("api/organiser/updatedata", new OrganiserBindingModel { Id = APIClient.Organiser.Id, OrganiserFIO = fio, OrganiserLogin = login, OrganiserPassword = password, OrganiserEmail= email, OrganiserNumber= telephone }); APIClient.Organiser.OrganiserFIO = fio; APIClient.Organiser.OrganiserLogin = login; APIClient.Organiser.OrganiserPassword = password; APIClient.Organiser.OrganiserEmail = email; APIClient.Organiser.OrganiserNumber = telephone; Response.Redirect("Index"); } [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); } [HttpGet] public IActionResult Enter() { return View(); } [HttpPost] public void Enter(string login, string password) { if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) { throw new Exception("Введите логин и пароль"); } APIClient.Organiser = APIClient.GetRequest($"api/organiser/login?login={login}&password={password}"); if (APIClient.Organiser == null) { throw new Exception("Неверный логин/пароль"); } Response.Redirect("Index"); } [HttpGet] public IActionResult Register() { return View(); } [HttpPost] public void Register(string login, string email, string password, string fio, string telephone) { if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) { throw new Exception("Введите логин, пароль и ФИО"); } APIClient.PostRequest("api/organiser/register", new OrganiserBindingModel { OrganiserFIO = fio, OrganiserLogin = login, OrganiserPassword = password, OrganiserEmail = email, OrganiserNumber = telephone }); Response.Redirect("Enter"); return; } } }