complete customer api for integration
This commit is contained in:
parent
99f820ff0f
commit
3bfab96c0d
|
|
@ -55,7 +55,7 @@ public class IntegrationService : IIntegrationService
|
|||
CustomerIntegrationResponse response = new();
|
||||
try
|
||||
{
|
||||
using TransactionContext tc = await TransactionContext.BeginAsync(_settings.DefaultConnection.ConnectionNode);
|
||||
using TransactionContext tc = await TransactionContext.BeginAsync(_settings.DefaultConnection.ConnectionNode,true);
|
||||
try
|
||||
{
|
||||
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)
|
||||
{
|
||||
//Update Here
|
||||
|
||||
UpdateCustomer(tc, customer.CustomerId, request);
|
||||
response.CustomerNumber = request.CustomerNumber;
|
||||
response.CompanyCode = request.CompanyCode;
|
||||
response.IsUpdated = true;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//Insert Here
|
||||
|
||||
CreateCustomer(tc, request);
|
||||
response.CustomerNumber = request.CustomerNumber;
|
||||
response.CompanyCode = request.CompanyCode;
|
||||
response.IsUpdated = false;
|
||||
|
||||
}
|
||||
|
||||
tc.End();
|
||||
|
|
@ -112,6 +115,7 @@ public class IntegrationService : IIntegrationService
|
|||
{
|
||||
response = new CustomerByCompanyCodeResponse()
|
||||
{
|
||||
CustomerId =Convert.ToInt32( dr["CustomerId"].ToString()),
|
||||
CustomerNumber = dr["CustomerNumber"].ToString(),
|
||||
CustomerName = dr["CustomerName"].ToString(),
|
||||
AccountGroup = dr["AccountGroup"].ToString(),
|
||||
|
|
@ -157,4 +161,150 @@ public class IntegrationService : IIntegrationService
|
|||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ namespace OnlineSalesAutoCrop.CoreAPI.Controllers.IntegretionApi
|
|||
/// </remarks>
|
||||
/// <param name="request"></param>
|
||||
/// <returns>if created return 201 or if updated return 204 true</returns>
|
||||
[HttpGet("Customers")]
|
||||
[HttpPost("Customers")]
|
||||
[IgnoreAntiforgeryToken]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IntegrationLoginResponse))]
|
||||
public async Task<IActionResult> UpsertCustomers(CustomerIntegrationRequest request)
|
||||
|
|
@ -57,8 +57,8 @@ namespace OnlineSalesAutoCrop.CoreAPI.Controllers.IntegretionApi
|
|||
else
|
||||
{
|
||||
response.ReturnMessage.Add($"Customer Updated Successfully for CustomerNumber :{request.CustomerNumber} & CompanyCode:{request.CompanyCode}");
|
||||
response.ReturnStatus = StatusCodes.Status204NoContent;
|
||||
return StatusCode(StatusCodes.Status204NoContent, response);
|
||||
response.ReturnStatus = StatusCodes.Status200OK;
|
||||
return StatusCode(StatusCodes.Status200OK, response);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user