74 lines
3.1 KiB
C#
74 lines
3.1 KiB
C#
using Asp.Versioning;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Logging;
|
|
using OnlineSalesAutoCrop.CoreAPI.Models.Requests.Integrations;
|
|
using OnlineSalesAutoCrop.CoreAPI.Models.Responses.Integrations;
|
|
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Integrations;
|
|
using OnlineSalesAutoCrop.CoreAPI.Services.Services.Integrations;
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace OnlineSalesAutoCrop.CoreAPI.Controllers.IntegretionApi
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <remarks>
|
|
///
|
|
/// </remarks>
|
|
/// <param name="logger"></param>
|
|
/// <param name="integrationService"></param>
|
|
[Authorize]
|
|
[ApiController]
|
|
[ApiVersion("1.0")]
|
|
[ValidateAntiForgeryToken]
|
|
[Route("api/v{version:apiVersion}/Integration")]
|
|
public class IntegrationController(ILogger<IntegrationAuthController> logger, IIntegrationService integrationService) : ControllerBase
|
|
{
|
|
|
|
private readonly ILogger _logger = logger;
|
|
private readonly IIntegrationService _integrationService = integrationService;
|
|
|
|
|
|
/// <summary>
|
|
/// Insert or Update Customers for SAP
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// </remarks>
|
|
/// <param name="request"></param>
|
|
/// <returns>if created return 201 or if updated return 204 true</returns>
|
|
[HttpGet("Customers")]
|
|
[IgnoreAntiforgeryToken]
|
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IntegrationLoginResponse))]
|
|
public async Task<IActionResult> UpsertCustomers(CustomerIntegrationRequest request)
|
|
{
|
|
CustomerIntegrationResponse response = new CustomerIntegrationResponse();
|
|
try
|
|
{
|
|
response = await _integrationService.UpsertCustomerAsync(request);
|
|
if (!response.IsUpdated)
|
|
{
|
|
response.ReturnMessage.Add($"Customer Created Successfully for CustomerNumber :{request.CustomerNumber} & CompanyCode:{request.CompanyCode}");
|
|
response.ReturnStatus = StatusCodes.Status201Created;
|
|
return StatusCode(StatusCodes.Status201Created, response);
|
|
}
|
|
else
|
|
{
|
|
response.ReturnMessage.Add($"Customer Updated Successfully for CustomerNumber :{request.CustomerNumber} & CompanyCode:{request.CompanyCode}");
|
|
response.ReturnStatus = StatusCodes.Status204NoContent;
|
|
return StatusCode(StatusCodes.Status204NoContent, response);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string msg = $"Exception Occur in Customer Operation {request?.CustomerName}~{request?.CompanyCode}";
|
|
_logger.LogError(exception: ex, msg);
|
|
response.ReturnStatus = StatusCodes.Status500InternalServerError;
|
|
response.ReturnMessage.Add(ex.InnerException != null ? ex.InnerException.Message : ex.Message);
|
|
return StatusCode(StatusCodes.Status500InternalServerError, response);
|
|
}
|
|
}
|
|
}
|
|
} |