using CaseAccountingContracts.BindingModels; using CaseAccountingContracts.ViewModels; using Microsoft.AspNetCore.Mvc; namespace CaseAccountingProviderView.Controllers { public class CaseController : Controller { public IActionResult Create() { if (APIUser.User == null) { return Redirect("~/Home/Enter"); } return View(); } [HttpPost] public void Create([FromBody] CaseBindingModel caseModel) { if (APIUser.User == null) { throw new Exception("403"); } caseModel.UserId = APIUser.User.Id; APIUser.PostRequest("api/case/create", caseModel); Response.Redirect("/Home/Cases"); } public IActionResult Update(int id) { if (APIUser.User == null) { return Redirect("~/Home/Enter"); } ViewBag.Case = APIUser.GetRequest($"api/case/get?id={id}"); return View(); } [HttpPost] public void Update([FromBody] CaseBindingModel caseModel) { if (APIUser.User == null) { throw new Exception("403"); } caseModel.UserId = APIUser.User.Id; APIUser.PostRequest("api/case/update", caseModel); Response.Redirect("/Home/Cases"); } public IActionResult AddCase(int id) { if (APIUser.User == null) { return Redirect("~/Home/Enter"); } ViewBag.CaseId = id; return View(); } [HttpPost] public void AddCase([FromBody] CaseBindingModel caseModel) { if (APIUser.User == null) { throw new Exception("403"); } APIUser.PostRequest("api/case/update", caseModel); } public IActionResult Bind(int id) { if (APIUser.User == null) { return Redirect("~/Home/Enter"); } ViewBag.Case = APIUser.GetRequest($"api/case/get?id={id}"); return View(); } [HttpPost] public void Bind([FromBody] CaseBindingModel caseModel) { if (APIUser.User == null) { throw new Exception("403"); } APIUser.PostRequest("api/case/update", caseModel); } [HttpPost] public void Delete(int id) { if (APIUser.User == null) { throw new Exception("403"); } APIUser.PostRequest($"api/case/delete", new CaseBindingModel() { Id = id }); Response.Redirect("/Home/Cases"); } public List GetAllByUser() { if (APIUser.User == null) { return new(); } List? caseModel = APIUser.GetRequest>($"api/case/getallbyuser?userId={APIUser.User.Id}"); return caseModel ?? new(); } public CaseViewModel? Get(int id) { if (APIUser.User == null) { return new(); } CaseViewModel? caseModel = APIUser.GetRequest($"api/case/get?id={id}"); return caseModel; } public List GetAllSpecializations() { if (APIUser.User == null) { return new(); } List? specializationModel = APIUser.GetRequest>($"api/case/getallspecializations"); return specializationModel ?? new(); } public List GetSpecializationCases() { if (APIUser.User == null) { return new(); } List? specializationCases = APIUser.GetRequest>($"api/case/getspecializationcases"); return specializationCases ?? new(); } } }