88 lines
2.4 KiB
C#
88 lines
2.4 KiB
C#
|
using ComputerHardwareStoreContracts.BindingModels;
|
|||
|
using ComputerHardwareStoreContracts.SearchModels;
|
|||
|
using ComputerHardwareStoreContracts.StorageContracts;
|
|||
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
|
|||
|
namespace ComputerHardwareStoreREST.Controllers
|
|||
|
{
|
|||
|
[ApiController]
|
|||
|
[Route("[controller]")]
|
|||
|
public class BuildController : Controller
|
|||
|
{
|
|||
|
private readonly ILogger<BuildController> _logger;
|
|||
|
private readonly IBuildStorage _storage;
|
|||
|
|
|||
|
public BuildController(ILogger<BuildController> logger, IBuildStorage storage)
|
|||
|
{
|
|||
|
_logger = logger;
|
|||
|
_storage = storage;
|
|||
|
}
|
|||
|
|
|||
|
[HttpPost("get/filter")]
|
|||
|
public IActionResult GetByFilter([FromBody] BuildSearchModel model)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var result = _storage.GetFilteredList(model);
|
|||
|
return Ok(result);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
return BadRequest(ex.Message);
|
|||
|
}
|
|||
|
}
|
|||
|
[HttpPost("get")]
|
|||
|
public IActionResult GetById([FromBody] BuildSearchModel model)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var result = _storage.GetElement(model);
|
|||
|
return Ok(result);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
return BadRequest(ex.Message);
|
|||
|
}
|
|||
|
}
|
|||
|
[HttpPost("create")]
|
|||
|
public IActionResult Create([FromBody] BuildBindingModel model)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var result = _storage.Insert(model);
|
|||
|
return Ok(result);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
return BadRequest(ex.Message);
|
|||
|
}
|
|||
|
}
|
|||
|
[HttpPut("update")]
|
|||
|
public IActionResult Update([FromBody] BuildBindingModel model)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var result = _storage.Update(model);
|
|||
|
return Ok(result);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
return BadRequest(ex.Message);
|
|||
|
}
|
|||
|
}
|
|||
|
[HttpPost("delete")]
|
|||
|
public IActionResult Delete([FromBody] BuildBindingModel model)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var result = _storage.Delete(model);
|
|||
|
return Ok(result);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
return BadRequest(ex.Message);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|