55 lines
2.5 KiB
C#
55 lines
2.5 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|||
|
|
using Microsoft.AspNetCore.Http;
|
||
|
|
using Microsoft.AspNetCore.Mvc;
|
||
|
|
using Net.Business.DTO.WMS.Transferencia;
|
||
|
|
using Net.Business.Services.Log;
|
||
|
|
using Net.Data;
|
||
|
|
using Newtonsoft.Json;
|
||
|
|
using System.Text;
|
||
|
|
using System.Threading.Tasks;
|
||
|
|
|
||
|
|
namespace Net.Business.Services.Controllers
|
||
|
|
{
|
||
|
|
[Route("api/[controller]")]
|
||
|
|
[ApiController]
|
||
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||
|
|
[ApiExplorerSettings(GroupName = "ApiSAPWMS")]
|
||
|
|
[Authorize(AuthenticationSchemes = "Bearer")]
|
||
|
|
public class TransferenciaController : ControllerBase
|
||
|
|
{
|
||
|
|
private readonly IRepositoryWrapper _repository;
|
||
|
|
public TransferenciaController(IRepositoryWrapper repository)
|
||
|
|
{
|
||
|
|
this._repository = repository;
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpPost]
|
||
|
|
[ProducesResponseType(StatusCodes.Status201Created)]
|
||
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||
|
|
public async Task<IActionResult> POST([FromBody] Dto_TransferenciaRequest value)
|
||
|
|
{
|
||
|
|
if (value == null)
|
||
|
|
{
|
||
|
|
B_Log.Add("Cubico", Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(value)), Encoding.UTF8.GetBytes("Master object is null"), "Transferencia", value.NumOrden, value.DocEntry.ToString(), "0", "0");
|
||
|
|
return BadRequest("Master object is null");
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!ModelState.IsValid)
|
||
|
|
{
|
||
|
|
B_Log.Add("Cubico", Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(value)), Encoding.UTF8.GetBytes("Invalid model object"), "Transferencia", value.NumOrden, value.DocEntry.ToString(), "0", "0");
|
||
|
|
return BadRequest("Invalid model object");
|
||
|
|
}
|
||
|
|
|
||
|
|
var ObjectNew = await _repository.Transferencia.Create(value.RetornaModelo());
|
||
|
|
|
||
|
|
if (ObjectNew.StatusCode != 200)
|
||
|
|
{
|
||
|
|
B_Log.Add("Cubico", Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(value)), Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(ObjectNew)), "Transferencia", value.NumOrden, value.DocEntry.ToString(), "0", "0");
|
||
|
|
return BadRequest(ObjectNew);
|
||
|
|
}
|
||
|
|
B_Log.Add("Cubico", Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(value)), Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(ObjectNew)), "Transferencia", value.NumOrden, value.DocEntry.ToString(), ObjectNew?.DocNum.ToString(), ObjectNew?.DocEntry.ToString());
|
||
|
|
return Ok(ObjectNew);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|