2023-05-18 23:32:19 +04:00
|
|
|
|
using CaseAccountingContracts.BindingModels;
|
|
|
|
|
using CaseAccountingContracts.ViewModels;
|
2023-05-19 18:09:36 +04:00
|
|
|
|
using CaseAccountingDataModels.Models;
|
2023-05-18 23:32:19 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace CaseAccountingProviderView.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class DealController : Controller
|
|
|
|
|
{
|
|
|
|
|
public IActionResult Create()
|
|
|
|
|
{
|
|
|
|
|
if (APIUser.User == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Create([FromBody] DealBindingModel dealModel)
|
|
|
|
|
{
|
|
|
|
|
if (APIUser.User == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("403");
|
|
|
|
|
}
|
|
|
|
|
dealModel.UserId = APIUser.User.Id;
|
2023-05-19 18:09:36 +04:00
|
|
|
|
var dict = new Dictionary<int, ICaseModel>();
|
|
|
|
|
foreach (var element in dealModel.CaseViewModels)
|
|
|
|
|
{
|
|
|
|
|
var caseModel = APIUser.GetRequest<CaseViewModel>($"api/case/get?id={element.Id}");
|
|
|
|
|
dict.Add(element.Id, caseModel);
|
|
|
|
|
}
|
|
|
|
|
dealModel.Cases = dict;
|
|
|
|
|
APIUser.PostRequest("api/deal/create", dealModel);
|
2023-05-18 23:32:19 +04:00
|
|
|
|
Response.Redirect("/Home/Deals");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult Update(int id)
|
|
|
|
|
{
|
|
|
|
|
if (APIUser.User == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
ViewBag.Deal = APIUser.GetRequest<DealViewModel>($"api/deal/get?id={id}");
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Update([FromBody] DealBindingModel dealModel)
|
|
|
|
|
{
|
|
|
|
|
if (APIUser.User == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("403");
|
|
|
|
|
}
|
|
|
|
|
dealModel.UserId = APIUser.User.Id;
|
|
|
|
|
APIUser.PostRequest("api/deal/update", dealModel);
|
|
|
|
|
Response.Redirect("/Home/Deals");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult AddDeal(int id)
|
|
|
|
|
{
|
|
|
|
|
if (APIUser.User == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
ViewBag.DealId = id;
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void AddDeal([FromBody] DealBindingModel dealModel)
|
|
|
|
|
{
|
|
|
|
|
if (APIUser.User == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("403");
|
|
|
|
|
}
|
|
|
|
|
APIUser.PostRequest("api/deal/update", dealModel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult Bind(int id)
|
|
|
|
|
{
|
|
|
|
|
if (APIUser.User == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
ViewBag.Deal = APIUser.GetRequest<DealViewModel>($"api/deal/get?id={id}");
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Bind([FromBody] DealBindingModel dealModel)
|
|
|
|
|
{
|
|
|
|
|
if (APIUser.User == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("403");
|
|
|
|
|
}
|
|
|
|
|
APIUser.PostRequest("api/deal/update", dealModel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Delete(int id)
|
|
|
|
|
{
|
|
|
|
|
if (APIUser.User == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("403");
|
|
|
|
|
}
|
|
|
|
|
APIUser.PostRequest($"api/deal/delete", new DealBindingModel() { Id = id });
|
|
|
|
|
Response.Redirect("/Home/Deals");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<DealViewModel> GetAllByUser()
|
|
|
|
|
{
|
|
|
|
|
if (APIUser.User == null)
|
|
|
|
|
{
|
|
|
|
|
return new();
|
|
|
|
|
}
|
|
|
|
|
List<DealViewModel>? dealModel = APIUser.GetRequest<List<DealViewModel>>($"api/deal/getallbyuser?userId={APIUser.User.Id}");
|
|
|
|
|
return dealModel ?? new();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DealViewModel? Get(int id)
|
|
|
|
|
{
|
|
|
|
|
if (APIUser.User == null)
|
|
|
|
|
{
|
|
|
|
|
return new();
|
|
|
|
|
}
|
|
|
|
|
DealViewModel? dealModel = APIUser.GetRequest<DealViewModel>($"api/deal/get?id={id}");
|
|
|
|
|
return dealModel;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|