124 lines
3.7 KiB
C#
124 lines
3.7 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using UniversityContracts.BindingModels;
|
|
using UniversityContracts.ViewModels;
|
|
|
|
namespace UniversityCustomer.Controllers
|
|
{
|
|
public class StreamController : Controller
|
|
{
|
|
public IActionResult Create()
|
|
{
|
|
if (APIClient.User == null)
|
|
{
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public void Create([FromBody] StreamBindingModel streamModel)
|
|
{
|
|
if (APIClient.User == null)
|
|
{
|
|
throw new Exception("403");
|
|
}
|
|
streamModel.UserId = APIClient.User.Id;
|
|
APIClient.PostRequest("api/stream/create", streamModel);
|
|
Response.Redirect("/Home/Streams");
|
|
}
|
|
|
|
public IActionResult Update(int id)
|
|
{
|
|
if (APIClient.User == null)
|
|
{
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
ViewBag.Stream = APIClient.GetRequest<StreamViewModel>($"api/stream/get?id={id}");
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public void Update([FromBody] StreamBindingModel streamModel)
|
|
{
|
|
if (APIClient.User == null)
|
|
{
|
|
throw new Exception("403");
|
|
}
|
|
streamModel.UserId = APIClient.User.Id;
|
|
APIClient.PostRequest("api/stream/update", streamModel);
|
|
Response.Redirect("/Home/Streams");
|
|
}
|
|
|
|
public IActionResult Bind(int id)
|
|
{
|
|
if (APIClient.User == null)
|
|
{
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
ViewBag.Stream = APIClient.GetRequest<StreamViewModel>($"api/stream/get?id={id}");
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public void Bind([FromBody] StreamBindingModel streamModel)
|
|
{
|
|
if (APIClient.User == null)
|
|
{
|
|
throw new Exception("403");
|
|
}
|
|
APIClient.PostRequest("api/stream/update", streamModel);
|
|
}
|
|
|
|
[HttpPost]
|
|
public void Delete(int id)
|
|
{
|
|
if (APIClient.User == null)
|
|
{
|
|
throw new Exception("403");
|
|
}
|
|
APIClient.PostRequest($"api/stream/delete", new StreamBindingModel() { Id = id });
|
|
Response.Redirect("/Home/Streams");
|
|
}
|
|
|
|
public List<StudentViewModel> GetAllStudents()
|
|
{
|
|
if (APIClient.User == null)
|
|
{
|
|
return new();
|
|
}
|
|
List<StudentViewModel>? students = APIClient.GetRequest<List<StudentViewModel>>($"api/student/getall");
|
|
return students ?? new();
|
|
}
|
|
|
|
public List<EducationGroupViewModel> GetGroupsByUser()
|
|
{
|
|
if (APIClient.User == null)
|
|
{
|
|
return new();
|
|
}
|
|
List<EducationGroupViewModel>? group = APIClient.GetRequest<List<EducationGroupViewModel>>($"api/educationgroup/getallbyuser?userId={APIClient.User.Id}");
|
|
return group ?? new();
|
|
}
|
|
|
|
public StreamViewModel? Get(int id)
|
|
{
|
|
if (APIClient.User == null)
|
|
{
|
|
return new();
|
|
}
|
|
StreamViewModel? document = APIClient.GetRequest<StreamViewModel>($"api/stream/get?id={id}");
|
|
return document;
|
|
}
|
|
|
|
public List<StreamViewModel>? GetAllByUser()
|
|
{
|
|
if (APIClient.User == null)
|
|
{
|
|
return new();
|
|
}
|
|
List<StreamViewModel>? streams = APIClient.GetRequest<List<StreamViewModel>>($"api/stream/getallbyuser?userId={APIClient.User.Id}");
|
|
return streams;
|
|
}
|
|
}
|
|
}
|