using HotelBusinessLogic.BusinessLogic; using HotelContracts.BindingModels; using HotelContracts.BusinessLogicsContracts; using HotelContracts.SearchModels; using HotelContracts.ViewModels; using HotelDataBaseImplement.Models; using HotelDataModels.Models; using HotelOrganiserApp.Models; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Rendering; using System.Diagnostics; namespace HotelOrganiserApp.Controllers { public class HomeController : Controller { private readonly ILogger _logger; private readonly IParticipantLogic _participant; public HomeController(ILogger logger, IParticipantLogic participant) { _logger = logger; _participant = participant; } public IActionResult Index() { return View(); } [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 phone) { if (APIClient.Organiser == null) { throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); } if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(phone)) { throw new Exception("Введите логин, пароль и ФИО"); } APIClient.PostRequest("api/organiser/updatedata", new OrganiserBindingModel { Id = APIClient.Organiser.Id, OrganiserFIO = fio, OrganiserLogin = login, OrganiserPassword = password, OrganiserEmail = email, OrganiserNumber = phone }); APIClient.Organiser.OrganiserFIO = fio; APIClient.Organiser.OrganiserLogin = login; APIClient.Organiser.OrganiserPassword = password; APIClient.Organiser.OrganiserEmail = email; APIClient.Organiser.OrganiserNumber = phone; Response.Redirect("Index"); } [HttpGet] public IActionResult Register() { return View(); } [HttpPost] public void Register(string fio, string login, string email, string password, string phone) { if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio) || string.IsNullOrEmpty(phone) || string.IsNullOrEmpty(email)) { throw new Exception("Введите все данные"); } APIClient.PostRequest("api/organiser/register", new OrganiserBindingModel { OrganiserFIO = fio, OrganiserLogin = login, OrganiserPassword = password, OrganiserEmail = email, OrganiserNumber = phone }); Response.Redirect("Enter"); return; } [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"); } /*-------------------------Participant---------------------------------*/ public IActionResult Participants() { if (APIClient.Organiser == null) { return Redirect("~/Home/Enter"); } return View(APIClient.GetRequest>($"api/main/getparticipantlist?organiserId={APIClient.Organiser.Id}")); } public IActionResult CreateParticipant() { if (APIClient.Organiser == null) { return Redirect("~/Home/Enter"); } return View(); } [HttpPost] public void CreateParticipant(string participantFIO, string number) { if (APIClient.Organiser == null) { throw new Exception("Необходима авторизация"); } if (string.IsNullOrEmpty(participantFIO) || string.IsNullOrEmpty(number)) { throw new Exception("Введите данные"); } APIClient.PostRequest("api/main/createparticipant", new ParticipantBindingModel { ParticipantFIO = participantFIO, Number = number, OrganiserId = APIClient.Organiser.Id, }); Response.Redirect("Participants"); } public IActionResult UpdateParticipant() { if (APIClient.Organiser == null) { return Redirect("~/Home/Enter"); } ViewBag.Participants = APIClient.GetRequest>($"api/main/getparticipantlist?organiserId={APIClient.Organiser.Id}"); return View(); } [HttpPost] public void UpdateParticipant(int participant, string participantFIO, string number) { if (APIClient.Organiser == null) { throw new Exception("Необходима авторизация"); } if (string.IsNullOrEmpty(participantFIO) || string.IsNullOrEmpty(number)) { throw new Exception("Данные пустые"); } APIClient.PostRequest("api/main/updateparticipant", new ParticipantBindingModel { Id = participant, ParticipantFIO = participantFIO, Number = number, OrganiserId = APIClient.Organiser.Id, }); Response.Redirect("Participants"); } public IActionResult DeleteParticipant() { if (APIClient.Organiser == null) { return Redirect("~/Home/Enter"); } ViewBag.Participants = APIClient.GetRequest>($"api/main/getparticipantlist?organiserId={APIClient.Organiser.Id}"); return View(); } [HttpPost] public void DeleteParticipant(int participant) { if (APIClient.Organiser == null) { throw new Exception("Необходима авторизация"); } APIClient.PostRequest("api/main/deleteparticipant", new ParticipantBindingModel { Id = participant }); Response.Redirect("Participants"); } [HttpGet] public ParticipantViewModel? GetParticipant(int participantId) { if (APIClient.Organiser == null) { throw new Exception("Необходима авторизация"); } var result = APIClient.GetRequest($"api/main/getparticipant?participantid={participantId}"); if (result == null) { return default; } return result; } /*-------------------------------MealPlans--------------------*/ public IActionResult MealPlans() { if (APIClient.Organiser == null) { return Redirect("~/Home/Enter"); } return View(APIClient.GetRequest>($"api/main/getmealplanlist?organiserId={APIClient.Organiser.Id}")); } public IActionResult CreateMealPlan() { if (APIClient.Organiser == null) { return Redirect("~/Home/Enter"); } var list = _participant.ReadList(new ParticipantSearchModel { OrganiserId = APIClient.Organiser.Id }); var simpParticipant = list.Select(x => new { ParticipantId = x.Id, ParticipantFIO = x.ParticipantFIO }); ViewBag.Participants = new MultiSelectList(simpParticipant, "ParticipantId", "ParticipantFIO"); return View(); } [HttpPost] public void CreateMealPlan(string mealPlanName, int mealPlanPrice, int[] participants) { if (APIClient.Organiser == null) { throw new Exception("Необходима авторизация"); } if (string.IsNullOrEmpty(mealPlanName) || mealPlanPrice <= 0 || participants.Length == 0) { throw new Exception("Введите данные"); } Dictionary MealPlanParticipants = new Dictionary(); foreach (int id in participants) { MealPlanParticipants.Add(id, _participant.ReadElement(new ParticipantSearchModel { Id = id })); } APIClient.PostRequest("api/main/createmealplan", new MealPlanBindingModel { MealPlanName = mealPlanName, MealPlanPrice = mealPlanPrice, OrganiserId = APIClient.Organiser.Id, }); for (int i = 0; i < participants.Length; i++) { APIClient.PostRequest("api/main/AddParticipantToMealPlan", Tuple.Create( new MealPlanSearchModel() { MealPlanName = mealPlanName }, new ParticipantViewModel() { Id = participants[i] } )); } Response.Redirect("MealPlans"); } public IActionResult UpdateMealPlan() { if (APIClient.Organiser == null) { return Redirect("~/Home/Enter"); } ViewBag.MealPlans = APIClient.GetRequest>($"api/main/getmealplanlist?organiserId={APIClient.Organiser.Id}"); ViewBag.Participants = APIClient.GetRequest>($"api/main/getparticipantlist?organiserId={APIClient.Organiser.Id}"); return View(); } [HttpPost] public void UpdateMealPlan(int mealPlan, string mealPlanName, int mealPlanPrice, List participants) { if (APIClient.Organiser == null) { throw new Exception("Необходима авторизация"); } if (string.IsNullOrEmpty(mealPlanName) || mealPlanPrice <= 0) { throw new Exception("Введите данные"); } Dictionary participant = new Dictionary(); foreach (int din in participants) { participant.Add(din, new ParticipantSearchModel { Id = din } as IParticipantModel); } APIClient.PostRequest("api/main/updatemealplan", new MealPlanBindingModel { Id = mealPlan, MealPlanName = mealPlanName, MealPlanPrice = mealPlanPrice, OrganiserId = APIClient.Organiser.Id, MealPlanParticipants = participant, }); Response.Redirect("MealPlans"); } public IActionResult DeleteMealPlan() { if (APIClient.Organiser == null) { return Redirect("~/Home/Enter"); } ViewBag.Rooms = APIClient.GetRequest>($"api/main/getmealplanlist?organiserId={APIClient.Organiser.Id}"); return View(); } [HttpPost] public void DeleteMealPlan(int room) { if (APIClient.Organiser == null) { throw new Exception("Необходима авторизация"); } APIClient.PostRequest("api/main/deletemealplan", new MealPlanBindingModel { Id = room }); Response.Redirect("MealPlans"); } [HttpGet] public Tuple>>? GetMealPlan(int mealPlanId) { if (APIClient.Organiser == null) { throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } var result = APIClient.GetRequest>>>($"api/main/getmealplan?mealplanid={mealPlanId}"); if (result == null) { return default; } return result; } /*----------------------------Conferences--------------------*/ public IActionResult Conferences() { if (APIClient.Organiser == null) { return Redirect("~/Home/Enter"); } return View(APIClient.GetRequest>($"api/main/getconferencelist?organiserId={APIClient.Organiser.Id}")); } public IActionResult CreateConference() { if (APIClient.Organiser == null) { return Redirect("~/Home/Enter"); } var list = _participant.ReadList(new ParticipantSearchModel { OrganiserId = APIClient.Organiser.Id }); var simpParticipant = list.Select(x => new { ParticipantId = x.Id, ParticipantFIO = x.ParticipantFIO }); ViewBag.Participants = new MultiSelectList(simpParticipant, "ParticipantId", "ParticipantFIO"); return View(); } [HttpPost] public void CreateConference(string conferenceName, string subject, int[] participants, DateTime startDate) { if (APIClient.Organiser == null) { throw new Exception("Необходима авторизация"); } if (string.IsNullOrEmpty(conferenceName)) { throw new Exception("Введите данные"); } Dictionary ConferenceParticipants = new Dictionary(); foreach (int id in participants) { ConferenceParticipants.Add(id, _participant.ReadElement(new ParticipantSearchModel { Id = id })); } APIClient.PostRequest("api/main/createconference", new ConferenceBindingModel { ConferenceName = conferenceName, Subject = subject, StartDate = startDate, OrganiserId = APIClient.Organiser.Id, }); for (int i = 0; i < participants.Length; i++) { APIClient.PostRequest("api/main/AddParticipantToConference", Tuple.Create( new ConferenceSearchModel() { ConferenceName = conferenceName }, new ParticipantViewModel() { Id = participants[i] } )); } Response.Redirect("Conferences"); } public IActionResult UpdateConference() { if (APIClient.Organiser == null) { return Redirect("~/Home/Enter"); } ViewBag.Conferences = APIClient.GetRequest>($"api/main/getconferencelist?organiserid={APIClient.Organiser.Id}"); ViewBag.Participants = APIClient.GetRequest>($"api/main/getparticipantlist?organiserid={APIClient.Organiser.Id}"); return View(); } [HttpPost] public void UpdateConference(int conference, string conferenceName, string subject, DateTime startDate, List participants) { if (APIClient.Organiser == null) { throw new Exception("Необходима авторизация"); } if (string.IsNullOrEmpty(conferenceName)) { throw new Exception("Введите данные"); } Dictionary participant = new Dictionary(); foreach (int din in participants) { participant.Add(din, new ParticipantSearchModel { Id = din } as IParticipantModel); } APIClient.PostRequest("api/main/updateConference", new ConferenceBindingModel { Id = conference, ConferenceName = conferenceName, Subject = subject, StartDate = startDate, OrganiserId = APIClient.Organiser.Id, ConferenceParticipants = participant, }); Response.Redirect("Conferences"); } 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("Conferences"); } [HttpGet] public ConferenceViewModel? GetConference(int conferenceId) { if (APIClient.Organiser == null) { throw new Exception("Необходима авторизация"); } var result = APIClient.GetRequest($"api/main/getconference?conferenceid={conferenceId}"); if (result == null) { return default; } return result; } /*--------------------------AddConferenceBookingToConference------------------------------*/ [HttpGet] public IActionResult AddConferenceBookingToConference() { if (APIClient.Organiser == null) { return Redirect("~/Home/Enter"); } ViewBag.Conferences = APIClient.GetRequest>($"api/main/getconferencelist?organiserid={APIClient.Organiser.Id}"); ViewBag.ConferenceBookings = APIClient.GetRequest>($"api/main/getConferenceBookings"); return View(); } [HttpPost] public void AddConferenceBookingToConference(int conference, int conferencebooking, DateTime dateСonference) { if (APIClient.Organiser == null) { throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); } var conferenceBookingElem = APIClient.GetRequest($"api/main/getConferenceBookingById?conferenceBookingId={conferencebooking}"); APIClient.PostRequest("api/main/updateconferenceBooking", new ConferenceBookingBindingModel { Id = conferencebooking, ConferenceId = conference, PlaceСonference = conferenceBookingElem.PlaceСonference, DateСonference = conferenceBookingElem.DateСonference, AdministratorId = conferenceBookingElem.AdministratorId, }); Response.Redirect("Conferences"); } public IActionResult ListParticipantToPdfFile() { return View(); } public IActionResult ListParticipantConferenceToFile() { return View(); } [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); } } }