126 lines
3.5 KiB
C#
126 lines
3.5 KiB
C#
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
using System.Diagnostics;
|
|||
|
using UniversityContracts.BindingModels;
|
|||
|
using UniversityContracts.ViewModels;
|
|||
|
using UniversityCustomer;
|
|||
|
using UniversityModels.Enums;
|
|||
|
using UniversityCustomer.Models;
|
|||
|
|
|||
|
namespace UniversityProvider.Controllers
|
|||
|
{
|
|||
|
public class HomeController : Controller
|
|||
|
{
|
|||
|
public HomeController() { }
|
|||
|
|
|||
|
public IActionResult Index()
|
|||
|
{
|
|||
|
if (APIClient.User == null)
|
|||
|
{
|
|||
|
return Redirect("~/Home/Login");
|
|||
|
}
|
|||
|
return View();
|
|||
|
}
|
|||
|
|
|||
|
public IActionResult Login()
|
|||
|
{
|
|||
|
return View();
|
|||
|
}
|
|||
|
|
|||
|
[HttpPost]
|
|||
|
public void Login(string login, string password)
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
|
|||
|
{
|
|||
|
throw new Exception("Введите логин и пароль");
|
|||
|
}
|
|||
|
APIClient.User = APIClient.GetRequest<UserViewModel>($"api/user/login?login={login}&password={password}&role={Role.Customer}");
|
|||
|
if (APIClient.User == null)
|
|||
|
{
|
|||
|
throw new Exception("Неверный логин/пароль");
|
|||
|
}
|
|||
|
Response.Redirect("Index");
|
|||
|
}
|
|||
|
|
|||
|
public IActionResult Registration()
|
|||
|
{
|
|||
|
return View();
|
|||
|
}
|
|||
|
|
|||
|
[HttpPost]
|
|||
|
public void Registration(string login, string password)
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
|
|||
|
{
|
|||
|
throw new Exception("Введите логин и пароль");
|
|||
|
}
|
|||
|
APIClient.PostRequest("api/user/register", new UserBindingModel
|
|||
|
{
|
|||
|
Login = login,
|
|||
|
Password = password,
|
|||
|
Role = Role.Customer
|
|||
|
});
|
|||
|
Response.Redirect("Login");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
public IActionResult Streams(int page)
|
|||
|
{
|
|||
|
if (APIClient.User == null)
|
|||
|
{
|
|||
|
return Redirect("~/Home/Enter");
|
|||
|
}
|
|||
|
if (page == 0)
|
|||
|
{
|
|||
|
page = 1;
|
|||
|
}
|
|||
|
ViewBag.Streams = APIClient.GetRequest<List<StreamViewModel>>
|
|||
|
($"api/stream/getmany?userId={APIClient.User.Id}&page={page}");
|
|||
|
ViewBag.Page = page;
|
|||
|
ViewBag.NumberOfPages = APIClient.GetRequest<int>
|
|||
|
($"api/stream/getnumberofpages?userId={APIClient.User.Id}");
|
|||
|
return View();
|
|||
|
}
|
|||
|
|
|||
|
public IActionResult EducationGroups(int page)
|
|||
|
{
|
|||
|
if (APIClient.User == null)
|
|||
|
{
|
|||
|
return Redirect("~/Home/Enter");
|
|||
|
}
|
|||
|
if (page == 0)
|
|||
|
{
|
|||
|
page = 1;
|
|||
|
}
|
|||
|
ViewBag.EducationGroups = APIClient.GetRequest<List<EducationGroupViewModel>>
|
|||
|
($"api/educationgroup/getmany?userId={APIClient.User.Id}&page={page}");
|
|||
|
ViewBag.Page = page;
|
|||
|
ViewBag.NumberOfPages = APIClient.GetRequest<int>
|
|||
|
($"api/educationgroup/getnumberofpages?userId={APIClient.User.Id}");
|
|||
|
return View();
|
|||
|
}
|
|||
|
|
|||
|
public IActionResult Disciplines(int page)
|
|||
|
{
|
|||
|
if (APIClient.User == null)
|
|||
|
{
|
|||
|
return Redirect("~/Home/Enter");
|
|||
|
}
|
|||
|
if (page == 0)
|
|||
|
{
|
|||
|
page = 1;
|
|||
|
}
|
|||
|
ViewBag.Disciplines = APIClient.GetRequest<List<DisciplineViewModel>>
|
|||
|
($"api/discipline/getmany?userId={APIClient.User.Id}&page={page}");
|
|||
|
ViewBag.Page = page;
|
|||
|
ViewBag.NumberOfPages = APIClient.GetRequest<int>
|
|||
|
($"api/discipline/getnumberofpages?userId={APIClient.User.Id}");
|
|||
|
return View();
|
|||
|
}
|
|||
|
|
|||
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|||
|
public IActionResult Error()
|
|||
|
{
|
|||
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|||
|
}
|
|||
|
}
|
|||
|
}
|