PIbd-21_Pyatakov_KM_Markov_.../UniversityCustomer/Controllers/HomeController.cs

179 lines
5.4 KiB
C#
Raw Normal View History

2023-05-19 21:25:56 +04:00
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();
}
2023-06-22 00:20:17 +04:00
public List<EducationStatusViewModel> Status()
{
return APIClient.GetRequest<List<EducationStatusViewModel>>
($"api/educationstatus/getall");
}
public IActionResult EducationGroups(int page)
2023-05-19 21:25:56 +04:00
{
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();
}
2023-05-20 09:55:46 +04:00
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[]>
2023-06-21 21:38:05 +04:00
("api/reportcustomer/streamstudentlist", listModel);
2023-05-20 09:55:46 +04:00
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);
}
2023-05-19 21:25:56 +04:00
2023-05-20 09:55:46 +04:00
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
2023-05-19 21:25:56 +04:00
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}