Case_accounting/CaseAccounting/CaseAccountingCustomerView/Controllers/Lawyers.cs

115 lines
3.4 KiB
C#
Raw Normal View History

using CaseAccountingContracts.BindingModels;
using CaseAccountingContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace CaseAccountingCustomerView.Controllers
{
public class Lawyers : Controller
{
public IActionResult Create()
{
if (APIUser.User == null)
{
return Redirect("~/Home/Enter");
}
return View();
}
[HttpPost]
public void Create([FromBody] LawyerBindingModel lawyerModel)
{
if (APIUser.User == null)
{
throw new Exception("403");
}
lawyerModel.UserId = APIUser.User.Id;
APIUser.PostRequest("api/lawyer/create", lawyerModel);
Response.Redirect("/Home/Lawyers");
}
public IActionResult Update(int id)
{
if (APIUser.User == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Lawyer = APIUser.GetRequest<LawyerViewModel>($"api/lawyer/get?id={id}");
return View();
}
[HttpPost]
public void Update([FromBody] LawyerBindingModel lawyerModel)
{
if (APIUser.User == null)
{
throw new Exception("403");
}
lawyerModel.UserId = APIUser.User.Id;
APIUser.PostRequest("api/lawyer/update", lawyerModel);
Response.Redirect("/Home/Lawyers");
}
[HttpPost]
public void Delete(int id)
{
if (APIUser.User == null)
{
throw new Exception("403");
}
APIUser.PostRequest($"api/lawyer/delete", new LawyerBindingModel() { Id = id });
Response.Redirect("/Home/Lawyers");
}
public List<LawyerViewModel> GetAllByUser()
{
if (APIUser.User == null)
{
return new();
}
List<LawyerViewModel> ? lawyers = APIUser.GetRequest<List<LawyerViewModel>>($"api/lawyer/getallbyuser?userId={APIUser.User.Id}");
return lawyers ?? new();
}
/*public List<EducationGroupViewModel> GetAllCases()
{
if (APIUser.User == null)
{
return new();
}
List<EducationGroupViewModel>? group = APIUser.GetRequest<List<EducationGroupViewModel>>("api/lawyer/GetAllCases");
return group ?? new();
}*/
public LawyerViewModel? Get(int id)
{
if (APIUser.User == null)
{
return new();
}
LawyerViewModel? lawyer = APIUser.GetRequest<LawyerViewModel>($"api/lawyer/get?id={id}");
return lawyer;
}
public IActionResult Bind(int id)
{
if (APIUser.User == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Lawyer = APIUser.GetRequest<LawyerViewModel>($"api/lawyer/get?id={id}");
return View();
}
public List<LawyerViewModel> GetAllByUserAndSpecialization(int specialization)
{
if (APIUser.User == null)
{
return new();
}
List<LawyerViewModel>? lawyers = APIUser.GetRequest<List<LawyerViewModel>>($"api/lawyer/getallbyuserandspecialization?userId={APIUser.User.Id}&specialization={specialization}");
return lawyers ?? new();
}
}
}