530 lines
20 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 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<HomeController> _logger;
private readonly IParticipantLogic _participant;
public HomeController(ILogger<HomeController> 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<OrganiserViewModel>($"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<List<ParticipantViewModel>>($"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<List<ParticipantViewModel>>($"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<List<ParticipantViewModel>>($"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<ParticipantViewModel>($"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<List<MealPlanViewModel>>($"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<int, IParticipantModel> MealPlanParticipants = new Dictionary<int, IParticipantModel>();
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<List<MealPlanViewModel>>($"api/main/getmealplanlist?organiserId={APIClient.Organiser.Id}");
ViewBag.Participants = APIClient.GetRequest<List<ParticipantViewModel>>($"api/main/getparticipantlist?organiserId={APIClient.Organiser.Id}");
return View();
}
[HttpPost]
public void UpdateMealPlan(int mealPlan, string mealPlanName, int mealPlanPrice, List<int> participants)
{
if (APIClient.Organiser == null)
{
throw new Exception("Необходима авторизация");
}
if (string.IsNullOrEmpty(mealPlanName) || mealPlanPrice <= 0)
{
throw new Exception("Введите данные");
}
Dictionary<int, IParticipantModel> participant = new Dictionary<int, IParticipantModel>();
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<List<RoomViewModel>>($"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<MealPlanViewModel, List<Tuple<string, double>>>? GetMealPlan(int mealPlanId)
{
if (APIClient.Organiser == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
var result = APIClient.GetRequest<Tuple<MealPlanViewModel, List<Tuple<string, double>>>>($"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<List<ConferenceViewModel>>($"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<int, IParticipantModel> ConferenceParticipants = new Dictionary<int, IParticipantModel>();
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<List<ConferenceViewModel>>($"api/main/getconferencelist?organiserid={APIClient.Organiser.Id}");
ViewBag.Participants = APIClient.GetRequest<List<ParticipantViewModel>>($"api/main/getparticipantlist?organiserid={APIClient.Organiser.Id}");
return View();
}
[HttpPost]
public void UpdateConference(int conference, string conferenceName, string subject, DateTime startDate, List<int> participants)
{
if (APIClient.Organiser == null)
{
throw new Exception("Необходима авторизация");
}
if (string.IsNullOrEmpty(conferenceName))
{
throw new Exception("Введите данные");
}
Dictionary<int, IParticipantModel> participant = new Dictionary<int, IParticipantModel>();
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<List<ConferenceViewModel>>($"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<ConferenceViewModel>($"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<List<ConferenceViewModel>>($"api/main/getconferencelist?organiserid={APIClient.Organiser.Id}");
ViewBag.ConferenceBookings = APIClient.GetRequest<List<ConferenceBookingViewModel>>($"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<ConferenceBookingViewModel>($"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 });
}
}
}