Case_accounting/CaseAccounting/CaseAccountingRestApi/Controllers/DealController.cs
2023-05-19 21:07:14 +04:00

102 lines
1.8 KiB
C#

using CaseAccountingBusinessLogic.BusinessLogics;
using CaseAccountingContracts.BindingModels;
using CaseAccountingContracts.BusinessLogicContracts;
using CaseAccountingContracts.SearchModels;
using CaseAccountingContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace CaseAccountingRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class DealController : Controller
{
private readonly IDealLogic _logic;
private readonly IContractLogic _contractLogic;
public DealController(IDealLogic logic, IContractLogic contractLogic)
{
_logic = logic;
_contractLogic = contractLogic;
}
[HttpGet]
public DealViewModel? Get(int id)
{
try
{
return _logic.ReadElement(new DealSearchModel { Id = id });
}
catch (Exception)
{
throw;
}
}
[HttpGet]
public List<DealViewModel>? GetAllByUser(int userId)
{
try
{
return _logic.ReadList(new DealSearchModel { UserId = userId });
}
catch (Exception)
{
throw;
}
}
[HttpGet]
public List<ContractViewModel>? GetAllContracts()
{
try
{
return _contractLogic.ReadList(null);
}
catch (Exception)
{
throw;
}
}
[HttpPost]
public void Create(DealBindingModel model)
{
try
{
_logic.Create(model);
}
catch (Exception)
{
throw;
}
}
[HttpPost]
public void Update(DealBindingModel model)
{
try
{
_logic.Update(model);
}
catch (Exception)
{
throw;
}
}
[HttpPost]
public void Delete(DealBindingModel model)
{
try
{
_logic.Delete(new() { Id = model.Id });
}
catch (Exception)
{
throw;
}
}
}
}