CourseWork_EventVisitor/EventVisitor/EventVisitorClientApp/Controllers/HomeController.cs

172 lines
4.2 KiB
C#

using EventVisitorClientApp.Models;
using EventVisitorLogic.BindingModels;
using EventVisitorLogic.Logic;
using EventVisitorLogic.ViewModels;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Diagnostics;
using System.Security.Cryptography.Xml;
namespace EventVisitorClientApp.Controllers
{
public class HomeController : Controller
{
Random rnd = new Random();
public IActionResult Index()
{
return View();
}
[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.Client = APIClient.GetRequest<OrganizerViewModel>($"api/client/login?login={login}&password={password}");
if (APIClient.Client == null)
{
throw new Exception("Íåâåðíûé ëîãèí/ïàðîëü");
}
Response.Redirect("Index");
}
[HttpGet]
public IActionResult Privacy()
{
if (APIClient.Client == null)
{
return Redirect("~Home/Enter");
}
return View(APIClient.Client);
}
[HttpPost]
public void Privacy(string login, string password, string surname, string name, string lastname, string role, string organizationName, string phone)
{
if (APIClient.Client == null)
{
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
}
if (string.IsNullOrEmpty(login))
{
throw new Exception("Ââåäèòå e-mail");
}
if (string.IsNullOrEmpty(password))
{
throw new Exception("Ââåäèòå ïàðîëü");
}
if (string.IsNullOrEmpty(name))
{
throw new Exception("Ââåäèòå èìÿ");
}
if (string.IsNullOrEmpty(surname))
{
throw new Exception("Ââåäèòå ôàìèëèþ");
}
if (string.IsNullOrEmpty(organizationName))
{
throw new Exception("Ââåäèòå íàçâàíèå îðãàíèçàöèè");
}
if (string.IsNullOrEmpty(role))
{
throw new Exception("Ââåäèòå ðîëü");
}
APIClient.PostRequest("api/client/updatedata", new OrganizerBindingModel
{
Id = APIClient.Client.Id,
Name = name,
Surname = surname,
LastName = lastname,
Role = role,
OrganizationName = organizationName,
Phone = phone,
Email = login,
Password = password
});
APIClient.Client.Name = name;
APIClient.Client.Surname = surname;
APIClient.Client.LastName = lastname;
APIClient.Client.Role = role;
APIClient.Client.OrganizationName = organizationName;
APIClient.Client.Phone = phone;
APIClient.Client.Email = login;
APIClient.Client.Password = password;
Response.Redirect("Index");
}
[HttpGet]
public IActionResult Register()
{
return View();
}
[HttpPost]
public void Register(string login, string password, string surname, string name, string lastname, string role, string organizationName, string phone, string code)
{
if (string.IsNullOrEmpty(login))
{
throw new Exception("Ââåäèòå e-mail");
}
if (string.IsNullOrEmpty(password))
{
throw new Exception("Ââåäèòå ïàðîëü");
}
if (string.IsNullOrEmpty(name))
{
throw new Exception("Ââåäèòå èìÿ");
}
if (string.IsNullOrEmpty(surname))
{
throw new Exception("Ââåäèòå ôàìèëèþ");
}
if (string.IsNullOrEmpty(organizationName))
{
throw new Exception("Ââåäèòå íàçâàíèå îðãàíèçàöèè");
}
if (string.IsNullOrEmpty(role))
{
throw new Exception("Ââåäèòå ðîëü");
}
APIClient.PostRequest("api/Organizer/Register", new OrganizerBindingModel
{
Name = name,
Surname = surname,
LastName = lastname,
Role = role,
OrganizationName = organizationName,
Phone = phone,
Email = login,
Password = password
});
Response.Redirect("Enter");
return;
}
public IActionResult MyEvents()
{
//if (APIClient.Client == null)
//{
// return Redirect("~/Home/Enter");
//}
return View(APIClient.GetRequest<List<EventViewModel>>($"api/main/getevents"));
}
public IActionResult CreateEvent()
{
//if (APIClient.Client == null)
//{
// return Redirect("~/Home/Enter");
//}
return View();
}
}
}