179 lines
5.4 KiB
C#
179 lines
5.4 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 List<EducationStatusViewModel> Status()
|
|
{
|
|
return APIClient.GetRequest<List<EducationStatusViewModel>>
|
|
($"api/educationstatus/getall");
|
|
}
|
|
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();
|
|
}
|
|
public IActionResult StreamStudentList()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public int[]? StreamStudentList([FromBody] StreamStudentBindingModel listModel)
|
|
{
|
|
if (APIClient.User == null)
|
|
{
|
|
return Array.Empty<int>();
|
|
}
|
|
byte[]? file = APIClient.PostRequestWithResult<StreamStudentBindingModel, byte[]>
|
|
("api/reportcustomer/streamstudentlist", listModel);
|
|
return file!.Select(b => (int)b).ToArray();
|
|
}
|
|
|
|
public IActionResult GetReport()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public List<ReportStreamStudentEdStatPeriodViewModel>? GetReport([FromBody] ReportBindingModel reportModel)
|
|
{
|
|
if (APIClient.User == null)
|
|
{
|
|
return new();
|
|
}
|
|
reportModel.UserId = APIClient.User.Id;
|
|
reportModel.UserEmail = APIClient.User.Login;
|
|
List<ReportStreamStudentEdStatPeriodViewModel>? list = APIClient.PostRequestWithResult<ReportBindingModel, List<ReportStreamStudentEdStatPeriodViewModel>>
|
|
("api/reportprovider/getreportdata", reportModel);
|
|
return list;
|
|
}
|
|
|
|
[HttpPost]
|
|
public void SendByMailStatusReport([FromBody] ReportBindingModel reportModel)
|
|
{
|
|
if (APIClient.User == null)
|
|
{
|
|
return;
|
|
}
|
|
reportModel.UserId = APIClient.User.Id;
|
|
reportModel.UserEmail = APIClient.User.Login;
|
|
APIClient.PostRequest("api/reportprovider/sendbymailstatusreport", reportModel);
|
|
}
|
|
|
|
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
public IActionResult Error()
|
|
{
|
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
}
|
|
}
|
|
} |