complete customer api for integration

This commit is contained in:
dibakor 2026-06-16 18:15:04 +06:00
parent 99f820ff0f
commit 3bfab96c0d
2 changed files with 155 additions and 5 deletions

View File

@ -55,7 +55,7 @@ public class IntegrationService : IIntegrationService
CustomerIntegrationResponse response = new(); CustomerIntegrationResponse response = new();
try try
{ {
using TransactionContext tc = await TransactionContext.BeginAsync(_settings.DefaultConnection.ConnectionNode); using TransactionContext tc = await TransactionContext.BeginAsync(_settings.DefaultConnection.ConnectionNode,true);
try try
{ {
var customer = await GetCustomerByCompanyCodeAsync(tc, new CustomerByCompanyCodeRequest() { CompanyCode = request.CompanyCode, CustomerNumber = request.CustomerNumber }); var customer = await GetCustomerByCompanyCodeAsync(tc, new CustomerByCompanyCodeRequest() { CompanyCode = request.CompanyCode, CustomerNumber = request.CustomerNumber });
@ -63,18 +63,21 @@ public class IntegrationService : IIntegrationService
if( customer != null && customer.CustomerId>0) if( customer != null && customer.CustomerId>0)
{ {
//Update Here //Update Here
UpdateCustomer(tc, customer.CustomerId, request);
response.CustomerNumber = request.CustomerNumber; response.CustomerNumber = request.CustomerNumber;
response.CompanyCode = request.CompanyCode; response.CompanyCode = request.CompanyCode;
response.IsUpdated = true; response.IsUpdated = true;
} }
else else
{ {
//Insert Here //Insert Here
CreateCustomer(tc, request);
response.CustomerNumber = request.CustomerNumber; response.CustomerNumber = request.CustomerNumber;
response.CompanyCode = request.CompanyCode; response.CompanyCode = request.CompanyCode;
response.IsUpdated = false; response.IsUpdated = false;
} }
tc.End(); tc.End();
@ -112,6 +115,7 @@ public class IntegrationService : IIntegrationService
{ {
response = new CustomerByCompanyCodeResponse() response = new CustomerByCompanyCodeResponse()
{ {
CustomerId =Convert.ToInt32( dr["CustomerId"].ToString()),
CustomerNumber = dr["CustomerNumber"].ToString(), CustomerNumber = dr["CustomerNumber"].ToString(),
CustomerName = dr["CustomerName"].ToString(), CustomerName = dr["CustomerName"].ToString(),
AccountGroup = dr["AccountGroup"].ToString(), AccountGroup = dr["AccountGroup"].ToString(),
@ -157,4 +161,150 @@ public class IntegrationService : IIntegrationService
} }
return response; return response;
} }
public bool CreateCustomer(TransactionContext tc, CustomerIntegrationRequest request)
{
bool returnValue = false;
try
{
SqlParameter[] p =
[
SqlHelperExtension.CreateInParam("@CustomerNumber", SqlDbType.VarChar, request.CustomerNumber),
SqlHelperExtension.CreateInParam("@CustomerName", SqlDbType.VarChar, request.CustomerName),
SqlHelperExtension.CreateInParam("@AccountGroup", SqlDbType.VarChar, request.AccountGroup),
SqlHelperExtension.CreateInParam("@AccountGroupDescription", SqlDbType.VarChar, request.AccountGroupDescription),
SqlHelperExtension.CreateInParam("@CompanyCode", SqlDbType.VarChar, request.CompanyCode),
SqlHelperExtension.CreateInParam("@CompanyCodeDescription", SqlDbType.VarChar, request.CompanyCodeDescription),
SqlHelperExtension.CreateInParam("@SalesOrganization", SqlDbType.VarChar, request.SalesOrganization),
SqlHelperExtension.CreateInParam("@SalesOrganizationDescription", SqlDbType.VarChar, request.SalesOrganizationDescription),
SqlHelperExtension.CreateInParam("@DistributionChannel", SqlDbType.VarChar, request.DistributionChannel),
SqlHelperExtension.CreateInParam("@DistributionChannelDescription", SqlDbType.VarChar, request.DistributionChannelDescription),
SqlHelperExtension.CreateInParam("@Division", SqlDbType.VarChar, request.Division),
SqlHelperExtension.CreateInParam("@DivisionDescription", SqlDbType.VarChar, request.DivisionDescription),
SqlHelperExtension.CreateInParam("@MobileNumber", SqlDbType.VarChar, request.MobileNumber),
SqlHelperExtension.CreateInParam("@EmailAddress", SqlDbType.VarChar, request.EmailAddress),
SqlHelperExtension.CreateInParam("@BusinessTaxNumber", SqlDbType.VarChar, request.BusinessTaxNumber),
SqlHelperExtension.CreateInParam("@CreditLimit", SqlDbType.Decimal, request.CreditLimit),
SqlHelperExtension.CreateInParam("@SalesOffice", SqlDbType.VarChar, request.SalesOffice),
SqlHelperExtension.CreateInParam("@SalesOfficeDescription", SqlDbType.VarChar, request.SalesOfficeDescription),
SqlHelperExtension.CreateInParam("@SalesGroup", SqlDbType.VarChar, request.SalesGroup),
SqlHelperExtension.CreateInParam("@CustomerGroup", SqlDbType.VarChar, request.CustomerGroup),
SqlHelperExtension.CreateInParam("@Status", SqlDbType.VarChar, request.Status),
SqlHelperExtension.CreateInParam("@PaymentTerms", SqlDbType.VarChar, request.PaymentTerms),
SqlHelperExtension.CreateInParam("@SearchTerm", SqlDbType.VarChar, request.SearchTerm),
SqlHelperExtension.CreateInParam("@Region", SqlDbType.VarChar, request.Region),
SqlHelperExtension.CreateInParam("@RegionName", SqlDbType.VarChar, request.RegionName),
SqlHelperExtension.CreateInParam("@Area", SqlDbType.VarChar, request.Area),
SqlHelperExtension.CreateInParam("@AreaName", SqlDbType.VarChar, request.AreaName),
SqlHelperExtension.CreateInParam("@SalesUnit", SqlDbType.VarChar, request.SalesUnit),
SqlHelperExtension.CreateInParam("@SalesUnitName", SqlDbType.VarChar, request.SalesUnitName),
SqlHelperExtension.CreateInParam("@Territory", SqlDbType.VarChar, request.Territory),
SqlHelperExtension.CreateInParam("@TerritoryName", SqlDbType.VarChar, request.TerritoryName),
SqlHelperExtension.CreateInParam("@Plant", SqlDbType.VarChar, request.Plant),
SqlHelperExtension.CreateInParam("@PlantName", SqlDbType.VarChar, request.PlantName)
];
_ = tc.ExecuteNonQuerySp(spName: "dbo.CreateCustomer", parameterValues: p);
returnValue = true;
}
catch (Exception e)
{
throw;
}
return returnValue;
}
public bool UpdateCustomer(TransactionContext tc,int customerId, CustomerIntegrationRequest request)
{
bool returnValue = false;
try
{
SqlParameter[] p =
[
SqlHelperExtension.CreateInParam("@CustomerId", SqlDbType.Int,customerId),
SqlHelperExtension.CreateInParam("@CustomerNumber", SqlDbType.VarChar, request.CustomerNumber),
SqlHelperExtension.CreateInParam("@CompanyCode", SqlDbType.VarChar, request.CompanyCode),
SqlHelperExtension.CreateInParam("@CustomerName", SqlDbType.VarChar, request.CustomerName),
SqlHelperExtension.CreateInParam("@AccountGroup", SqlDbType.VarChar, request.AccountGroup),
SqlHelperExtension.CreateInParam("@AccountGroupDescription", SqlDbType.VarChar, request.AccountGroupDescription),
SqlHelperExtension.CreateInParam("@CompanyCodeDescription", SqlDbType.VarChar, request.CompanyCodeDescription),
SqlHelperExtension.CreateInParam("@SalesOrganization", SqlDbType.VarChar, request.SalesOrganization),
SqlHelperExtension.CreateInParam("@SalesOrganizationDescription", SqlDbType.VarChar, request.SalesOrganizationDescription),
SqlHelperExtension.CreateInParam("@DistributionChannel", SqlDbType.VarChar, request.DistributionChannel),
SqlHelperExtension.CreateInParam("@DistributionChannelDescription", SqlDbType.VarChar, request.DistributionChannelDescription),
SqlHelperExtension.CreateInParam("@Division", SqlDbType.VarChar, request.Division),
SqlHelperExtension.CreateInParam("@DivisionDescription", SqlDbType.VarChar, request.DivisionDescription),
SqlHelperExtension.CreateInParam("@MobileNumber", SqlDbType.VarChar, request.MobileNumber),
SqlHelperExtension.CreateInParam("@EmailAddress", SqlDbType.VarChar, request.EmailAddress),
SqlHelperExtension.CreateInParam("@BusinessTaxNumber", SqlDbType.VarChar, request.BusinessTaxNumber),
SqlHelperExtension.CreateInParam("@CreditLimit", SqlDbType.Decimal, request.CreditLimit),
SqlHelperExtension.CreateInParam("@SalesOffice", SqlDbType.VarChar, request.SalesOffice),
SqlHelperExtension.CreateInParam("@SalesOfficeDescription", SqlDbType.VarChar, request.SalesOfficeDescription),
SqlHelperExtension.CreateInParam("@SalesGroup", SqlDbType.VarChar, request.SalesGroup),
SqlHelperExtension.CreateInParam("@CustomerGroup", SqlDbType.VarChar, request.CustomerGroup),
SqlHelperExtension.CreateInParam("@Status", SqlDbType.VarChar, request.Status),
SqlHelperExtension.CreateInParam("@PaymentTerms", SqlDbType.VarChar, request.PaymentTerms),
SqlHelperExtension.CreateInParam("@SearchTerm", SqlDbType.VarChar, request.SearchTerm),
SqlHelperExtension.CreateInParam("@Region", SqlDbType.VarChar, request.Region),
SqlHelperExtension.CreateInParam("@RegionName", SqlDbType.VarChar, request.RegionName),
SqlHelperExtension.CreateInParam("@Area", SqlDbType.VarChar, request.Area),
SqlHelperExtension.CreateInParam("@AreaName", SqlDbType.VarChar, request.AreaName),
SqlHelperExtension.CreateInParam("@SalesUnit", SqlDbType.VarChar, request.SalesUnit),
SqlHelperExtension.CreateInParam("@SalesUnitName", SqlDbType.VarChar, request.SalesUnitName),
SqlHelperExtension.CreateInParam("@Territory", SqlDbType.VarChar, request.Territory),
SqlHelperExtension.CreateInParam("@TerritoryName", SqlDbType.VarChar, request.TerritoryName),
SqlHelperExtension.CreateInParam("@Plant", SqlDbType.VarChar, request.Plant),
SqlHelperExtension.CreateInParam("@PlantName", SqlDbType.VarChar, request.PlantName)
];
_ = tc.ExecuteNonQuerySp(
spName: "dbo.UpdateCustomerById",
parameterValues: p
);
returnValue = true;
}
catch (Exception e)
{
throw new InvalidOperationException(e.Message, e);
}
return returnValue;
}
} }

View File

@ -39,7 +39,7 @@ namespace OnlineSalesAutoCrop.CoreAPI.Controllers.IntegretionApi
/// </remarks> /// </remarks>
/// <param name="request"></param> /// <param name="request"></param>
/// <returns>if created return 201 or if updated return 204 true</returns> /// <returns>if created return 201 or if updated return 204 true</returns>
[HttpGet("Customers")] [HttpPost("Customers")]
[IgnoreAntiforgeryToken] [IgnoreAntiforgeryToken]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IntegrationLoginResponse))] [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IntegrationLoginResponse))]
public async Task<IActionResult> UpsertCustomers(CustomerIntegrationRequest request) public async Task<IActionResult> UpsertCustomers(CustomerIntegrationRequest request)
@ -57,8 +57,8 @@ namespace OnlineSalesAutoCrop.CoreAPI.Controllers.IntegretionApi
else else
{ {
response.ReturnMessage.Add($"Customer Updated Successfully for CustomerNumber :{request.CustomerNumber} & CompanyCode:{request.CompanyCode}"); response.ReturnMessage.Add($"Customer Updated Successfully for CustomerNumber :{request.CustomerNumber} & CompanyCode:{request.CompanyCode}");
response.ReturnStatus = StatusCodes.Status204NoContent; response.ReturnStatus = StatusCodes.Status200OK;
return StatusCode(StatusCodes.Status204NoContent, response); return StatusCode(StatusCodes.Status200OK, response);
} }
} }
catch (Exception ex) catch (Exception ex)