using Microsoft.AspNetCore.Mvc; using UniversityContracts.BindingModels; using UniversityContracts.ViewModels; using UniversityModels.Models; namespace UniversityCustomer.Controllers { public class EducationGroupController : Controller { public IActionResult Create() { if (APIClient.User == null) { return Redirect("~/Home/Enter"); } return View(); } [HttpPost] public void Create([FromBody] EducationGroupBindingModel educationGroupModel) { if (APIClient.User == null) { throw new Exception("403"); } educationGroupModel.UserId = APIClient.User.Id; APIClient.PostRequest("api/educationgroup/create", educationGroupModel); Response.Redirect("/Home/EducationGroups"); } public IActionResult Update(int id) { if (APIClient.User == null) { return Redirect("~/Home/Enter"); } ViewBag.EducationGroup = APIClient.GetRequest($"api/educationgroup/get?id={id}"); return View(); } [HttpPost] public void Update([FromBody] EducationGroupBindingModel egsModel) { if (APIClient.User == null) { throw new Exception("403"); } egsModel.UserId = APIClient.User.Id; APIClient.PostRequest("api/educationgroup/update", egsModel); Response.Redirect("/Home/EducationGroups"); } [HttpPost] public void Delete(int id) { if (APIClient.User == null) { throw new Exception("403"); } APIClient.PostRequest($"api/educationgroup/delete", new EducationGroupBindingModel() { Id = id }); Response.Redirect("/Home/EducationGroups"); } public List GetAllByUser() { if (APIClient.User == null) { return new(); } List? egs = APIClient.GetRequest>($"api/educationgroup/getallbyuser?userId={APIClient.User.Id}"); return egs ?? new(); } public EducationGroupViewModel? Get(int id) { if (APIClient.User == null) { return new(); } EducationGroupViewModel? eg = APIClient.GetRequest($"api/educationgroup/get?id={id}"); return eg; } } }