using CaseAccountingContracts.BindingModels; using CaseAccountingContracts.ViewModels; using Microsoft.AspNetCore.Mvc; namespace CaseAccountingCustomerView.Controllers { public class Specializations : Controller { public IActionResult Create() { if (APIUser.User == null) { return Redirect("~/Home/Enter"); } return View(); } [HttpPost] public void Create([FromBody] SpecializationBindingModel specializationModel) { if (APIUser.User == null) { throw new Exception("403"); } specializationModel.UserId = APIUser.User.Id; APIUser.PostRequest("api/specialization/create", specializationModel); Response.Redirect("/Home/Specializations"); } public IActionResult Update(int id) { if (APIUser.User == null) { return Redirect("~/Home/Enter"); } ViewBag.Specialization = APIUser.GetRequest($"api/specialization/get?id={id}"); return View(); } [HttpPost] public void Update([FromBody] SpecializationBindingModel specializationModel) { if (APIUser.User == null) { throw new Exception("403"); } specializationModel.UserId = APIUser.User.Id; APIUser.PostRequest("api/specialization/update", specializationModel); Response.Redirect("/Home/Specializations"); } [HttpPost] public void Delete(int id) { if (APIUser.User == null) { throw new Exception("403"); } APIUser.PostRequest($"api/specialization/delete", new SpecializationBindingModel() { Id = id }); Response.Redirect("/Home/Specializations"); } public List GetAllByUser() { if (APIUser.User == null) { return new(); } List? specializations = APIUser.GetRequest>($"api/specialization/getallbyuser?userId={APIUser.User.Id}"); return specializations ?? new(); } public SpecializationViewModel? Get(int id) { if (APIUser.User == null) { return new(); } SpecializationViewModel? specialization = APIUser.GetRequest($"api/specialization/get?id={id}"); return specialization; } public List GetAll() { if (APIUser.User == null) { return new(); } List? specializations = APIUser.GetRequest>($"api/specialization/getall"); return specializations ?? new(); } } }