763 lines
37 KiB
C#
763 lines
37 KiB
C#
using Ease.NetCore.DataAccess;
|
|
using Ease.NetCore.DataAccess.SQL;
|
|
using Microsoft.Data.SqlClient;
|
|
using Microsoft.Extensions.Options;
|
|
using OnlineSalesAutoCrop.CoreAPI.Models.Global;
|
|
using OnlineSalesAutoCrop.CoreAPI.Models.Requests.Integrations;
|
|
using OnlineSalesAutoCrop.CoreAPI.Models.Responses.Integrations;
|
|
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Integrations;
|
|
using System;
|
|
using System.Data;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace OnlineSalesAutoCrop.CoreAPI.Services.Services.Integrations;
|
|
|
|
public class IntegrationService : IIntegrationService
|
|
{
|
|
private readonly AppSettings _settings;
|
|
|
|
public IntegrationService(IOptions<AppSettings> options)
|
|
{
|
|
_settings = options.Value;
|
|
}
|
|
|
|
|
|
public async Task<CustomerByCompanyCodeResponse> GetCustomerByCompanyCodeAsync(CustomerByCompanyCodeRequest request)
|
|
{
|
|
CustomerByCompanyCodeResponse response = new();
|
|
try
|
|
{
|
|
using TransactionContext tc = await TransactionContext.BeginAsync(_settings.DefaultConnection.ConnectionNode);
|
|
try
|
|
{
|
|
await GetCustomerByCompanyCodeAsync(tc, request);
|
|
tc.End();
|
|
}
|
|
catch (Exception ie)
|
|
{
|
|
tc?.HandleError();
|
|
|
|
throw DBCustomError.GenerateCustomError(ie);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
return response;
|
|
}
|
|
|
|
public async Task<CustomerIntegrationResponse> UpsertCustomerAsync(CustomerIntegrationRequest request)
|
|
{
|
|
CustomerIntegrationResponse response = new();
|
|
try
|
|
{
|
|
using TransactionContext tc = await TransactionContext.BeginAsync(_settings.DefaultConnection.ConnectionNode,true);
|
|
try
|
|
{
|
|
var customer = await GetCustomerByCompanyCodeAsync(tc, new CustomerByCompanyCodeRequest() { CompanyCode = request.CompanyCode, CustomerNumber = request.CustomerNumber });
|
|
|
|
if( customer != null && customer.CustomerId>0)
|
|
{
|
|
//Update Here
|
|
UpdateCustomer(tc, request);
|
|
response.IsUpdated = true;
|
|
}
|
|
else
|
|
{
|
|
//Insert Here
|
|
|
|
CreateCustomer(tc, request);
|
|
response.IsUpdated = false;
|
|
}
|
|
|
|
response.CustomerNumber = request.CustomerNumber;
|
|
response.CompanyCode = request.CompanyCode;
|
|
tc.End();
|
|
}
|
|
catch (Exception ie)
|
|
{
|
|
tc?.HandleError();
|
|
|
|
throw DBCustomError.GenerateCustomError(ie);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
return response;
|
|
}
|
|
|
|
|
|
public async Task<EmployeeIntegrationResponse> GetEmployeeBySalesOrgAsync(EmployeeIntegrationByComapanyRequest request)
|
|
{
|
|
EmployeeIntegrationResponse response = new();
|
|
try
|
|
{
|
|
using TransactionContext tc = await TransactionContext.BeginAsync(_settings.DefaultConnection.ConnectionNode);
|
|
try
|
|
{
|
|
await GetEmployeeBySalesOrgAsync(tc, request);
|
|
tc.End();
|
|
}
|
|
catch (Exception ie)
|
|
{
|
|
tc?.HandleError();
|
|
|
|
throw DBCustomError.GenerateCustomError(ie);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
return response;
|
|
}
|
|
|
|
public async Task<EmployeeIntegrationReqResponse> UpsertEmployeeAsync(EmployeeIntegrationRequest request)
|
|
{
|
|
EmployeeIntegrationReqResponse response = new EmployeeIntegrationReqResponse();
|
|
try
|
|
{
|
|
using TransactionContext tc = await TransactionContext.BeginAsync(_settings.DefaultConnection.ConnectionNode, true);
|
|
try
|
|
{
|
|
EmployeeIntegrationResponse employee = await GetEmployeeBySalesOrgAsync(tc,
|
|
new EmployeeIntegrationByComapanyRequest() { EmployeeVendorCode = request.EmployeeVendorCode, CompanyCode = request.CompanyCode });
|
|
|
|
|
|
if (employee != null && employee.EmployeeId > 0)
|
|
{
|
|
UpdateEmployee(tc, request);
|
|
response.IsUpdated = true;
|
|
}
|
|
else
|
|
{
|
|
InsertEmployee(tc, request);
|
|
response.IsUpdated = true;
|
|
}
|
|
|
|
response.EmployeeVendorCode = request.EmployeeVendorCode;
|
|
response.CompanyCode = request.CompanyCode;
|
|
tc.End();
|
|
}
|
|
catch (Exception ie)
|
|
{
|
|
tc?.HandleError();
|
|
|
|
throw DBCustomError.GenerateCustomError(ie);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
return response;
|
|
}
|
|
|
|
|
|
public async Task<MaterialIntegrationReqResponse> UpsertMaterialAsync(MaterialIntegrationRequest request)
|
|
{
|
|
MaterialIntegrationReqResponse response = new MaterialIntegrationReqResponse();
|
|
try
|
|
{
|
|
using TransactionContext tc = await TransactionContext.BeginAsync(_settings.DefaultConnection.ConnectionNode, true);
|
|
try
|
|
{
|
|
MaterialIntegrationResponse meterial = await GetMaterialByCodeAsync(tc,
|
|
new GetMaterialByCodeRequest() { MaterialCode = request.MaterialCode });
|
|
|
|
if (meterial != null && meterial.MeterialId > 0)
|
|
{
|
|
UpdateMaterial(tc, request);
|
|
response.IsUpdated = true;
|
|
}
|
|
else
|
|
{
|
|
CreateMaterial(tc, request);
|
|
response.IsUpdated = false;
|
|
}
|
|
|
|
response.MaterialCode = request.MaterialCode;
|
|
tc.End();
|
|
}
|
|
catch (Exception ie)
|
|
{
|
|
tc?.HandleError();
|
|
|
|
throw DBCustomError.GenerateCustomError(ie);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
return response;
|
|
}
|
|
|
|
public async Task<MaterialIntegrationResponse> GetMaterialByCodeAsync(GetMaterialByCodeRequest request)
|
|
{
|
|
MaterialIntegrationResponse response = new();
|
|
try
|
|
{
|
|
using TransactionContext tc = await TransactionContext.BeginAsync(_settings.DefaultConnection.ConnectionNode);
|
|
try
|
|
{
|
|
response= await GetMaterialByCodeAsync(tc, request);
|
|
tc.End();
|
|
}
|
|
catch (Exception ie)
|
|
{
|
|
tc?.HandleError();
|
|
|
|
throw DBCustomError.GenerateCustomError(ie);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
return response;
|
|
}
|
|
|
|
|
|
#region Customer Private Functions
|
|
|
|
private async Task<CustomerByCompanyCodeResponse> GetCustomerByCompanyCodeAsync(TransactionContext tc, CustomerByCompanyCodeRequest request)
|
|
{
|
|
CustomerByCompanyCodeResponse response = new CustomerByCompanyCodeResponse();
|
|
|
|
try
|
|
{
|
|
SqlParameter[] p =
|
|
[
|
|
SqlHelperExtension.CreateInParam(pName: "@CompanyCode", pType: SqlDbType.NVarChar, pValue: request.CompanyCode),
|
|
SqlHelperExtension.CreateInParam(pName: "@CustomerNumber", pType: SqlDbType.NVarChar, pValue: request.CustomerNumber)
|
|
];
|
|
|
|
using (IDataReader dr = await tc.ExecuteReaderSpAsync("dbo.GetCustomerByCompanyCode", parameterValues: p))
|
|
{
|
|
if (dr.Read())
|
|
{
|
|
response = new CustomerByCompanyCodeResponse()
|
|
{
|
|
CustomerId = dr.GetInt32(0),
|
|
CustomerNumber = dr.GetString(1),
|
|
CustomerName = dr.GetString(2),
|
|
AccountGroup = dr.GetString(3),
|
|
AccountGroupDescription = dr.GetString(4),
|
|
CompanyCode = dr.GetString(5),
|
|
CompanyCodeDescription = dr.GetString(6),
|
|
SalesOrganization = dr.GetString(7),
|
|
SalesOrganizationDescription = dr.GetString(8),
|
|
DistributionChannel = dr.GetString(9),
|
|
DistributionChannelDescription = dr.GetString(10),
|
|
Division = dr.GetString(11),
|
|
DivisionDescription = dr.GetString(12),
|
|
MobileNumber = dr.GetString(13),
|
|
EmailAddress = dr.GetString(14),
|
|
BusinessTaxNumber = dr.GetString(15),
|
|
CreditLimit = dr.GetDecimal(16),
|
|
SalesGroup = dr.GetString(17),
|
|
SalesGroupDescription = dr.GetString(18),
|
|
CustomerGroup = dr.GetString(19),
|
|
CustomerGroupDescription = dr.GetString(20),
|
|
CustomerPriceGroup = dr.GetString(21),
|
|
CustomerPriceGroupDescription = dr.GetString(22),
|
|
StatusCode = dr.GetString(23),
|
|
StatusDescription = dr.GetString(24),
|
|
PaymentTerms = dr.GetString(25),
|
|
PaymentTermsDescription = dr.GetString(26),
|
|
SearchTerm = dr.GetString(27),
|
|
AreaRegion = dr.GetString(28),
|
|
AreaRegionDescription = dr.GetString(29),
|
|
SalesUnitAreaAV = dr.GetString(30),
|
|
SalesUnitAreaAVDescription = dr.GetString(31),
|
|
Territory = dr.GetString(32),
|
|
TerritoryName = dr.GetString(33),
|
|
Plant = dr.GetString(34),
|
|
PlantName = dr.GetString(35)
|
|
};
|
|
}
|
|
dr.Close();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw DBCustomError.GenerateCustomError(ex);
|
|
}
|
|
|
|
return response;
|
|
}
|
|
|
|
private bool CreateCustomer(TransactionContext tc, CustomerIntegrationRequest request)
|
|
{
|
|
bool returnValue = false;
|
|
|
|
try
|
|
{
|
|
SqlParameter[] p =
|
|
[
|
|
SqlHelperExtension.CreateInParam("@CustomerNumber", SqlDbType.NVarChar, request.CustomerNumber),
|
|
SqlHelperExtension.CreateInParam("@CustomerName", SqlDbType.NVarChar, request.CustomerName),
|
|
|
|
SqlHelperExtension.CreateInParam("@AccountGroup", SqlDbType.NVarChar, request.AccountGroup),
|
|
SqlHelperExtension.CreateInParam("@AccountGroupDescription", SqlDbType.NVarChar, request.AccountGroupDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@CompanyCode", SqlDbType.NVarChar, request.CompanyCode),
|
|
SqlHelperExtension.CreateInParam("@CompanyCodeDescription", SqlDbType.NVarChar, request.CompanyCodeDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@SalesOrganization", SqlDbType.NVarChar, request.SalesOrganization),
|
|
SqlHelperExtension.CreateInParam("@SalesOrganizationDescription", SqlDbType.NVarChar, request.SalesOrganizationDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@DistributionChannel", SqlDbType.NVarChar, request.DistributionChannel),
|
|
SqlHelperExtension.CreateInParam("@DistributionChannelDescription", SqlDbType.NVarChar, request.DistributionChannelDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@Division", SqlDbType.NVarChar, request.Division),
|
|
SqlHelperExtension.CreateInParam("@DivisionDescription", SqlDbType.NVarChar, request.DivisionDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@MobileNumber", SqlDbType.NVarChar, request.MobileNumber),
|
|
SqlHelperExtension.CreateInParam("@EmailAddress", SqlDbType.NVarChar, request.EmailAddress),
|
|
|
|
SqlHelperExtension.CreateInParam("@BusinessTaxNumber", SqlDbType.NVarChar, request.BusinessTaxNumber),
|
|
SqlHelperExtension.CreateInParam("@CreditLimit", SqlDbType.Decimal, request.CreditLimit),
|
|
|
|
SqlHelperExtension.CreateInParam("@SalesGroup", SqlDbType.NVarChar, request.SalesGroup),
|
|
SqlHelperExtension.CreateInParam("@SalesGroupDescription", SqlDbType.NVarChar, request.SalesGroupDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@CustomerGroup", SqlDbType.NVarChar, request.CustomerGroup),
|
|
SqlHelperExtension.CreateInParam("@CustomerGroupDescription", SqlDbType.NVarChar, request.CustomerGroupDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@CustomerPriceGroup", SqlDbType.NVarChar, request.CustomerPriceGroup),
|
|
SqlHelperExtension.CreateInParam("@CustomerPriceGroupDescription", SqlDbType.NVarChar, request.CustomerPriceGroupDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@StatusCode", SqlDbType.NChar, request.StatusCode),
|
|
SqlHelperExtension.CreateInParam("@StatusDescription", SqlDbType.NVarChar, request.StatusDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@PaymentTerms", SqlDbType.NVarChar, request.PaymentTerms),
|
|
SqlHelperExtension.CreateInParam("@PaymentTermsDescription", SqlDbType.NVarChar, request.PaymentTermsDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@SearchTerm", SqlDbType.NVarChar, request.SearchTerm),
|
|
|
|
SqlHelperExtension.CreateInParam("@AreaRegion", SqlDbType.NVarChar, request.AreaRegion),
|
|
SqlHelperExtension.CreateInParam("@AreaRegionDescription", SqlDbType.NVarChar, request.AreaRegionDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@SalesUnitAreaAV", SqlDbType.NVarChar, request.SalesUnitAreaAV),
|
|
SqlHelperExtension.CreateInParam("@SalesUnitAreaAVDescription", SqlDbType.NVarChar, request.SalesUnitAreaAVDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@Territory", SqlDbType.NVarChar, request.Territory),
|
|
SqlHelperExtension.CreateInParam("@TerritoryName", SqlDbType.NVarChar, request.TerritoryName),
|
|
|
|
SqlHelperExtension.CreateInParam("@Plant", SqlDbType.NVarChar, request.Plant),
|
|
SqlHelperExtension.CreateInParam("@PlantName", SqlDbType.NVarChar, request.PlantName)
|
|
];
|
|
|
|
_ = tc.ExecuteNonQuerySp(spName: "dbo.CreateCustomer", parameterValues: p);
|
|
|
|
returnValue = true;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
return returnValue;
|
|
}
|
|
|
|
private bool UpdateCustomer(TransactionContext tc, CustomerIntegrationRequest request)
|
|
{
|
|
bool returnValue = false;
|
|
|
|
try
|
|
{
|
|
SqlParameter[] p =
|
|
[
|
|
SqlHelperExtension.CreateInParam("@CustomerNumber", SqlDbType.NVarChar, request.CustomerNumber),
|
|
SqlHelperExtension.CreateInParam("@CustomerName", SqlDbType.NVarChar, request.CustomerName),
|
|
|
|
SqlHelperExtension.CreateInParam("@AccountGroup", SqlDbType.NVarChar, request.AccountGroup),
|
|
SqlHelperExtension.CreateInParam("@AccountGroupDescription", SqlDbType.NVarChar, request.AccountGroupDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@CompanyCode", SqlDbType.NVarChar, request.CompanyCode),
|
|
SqlHelperExtension.CreateInParam("@CompanyCodeDescription", SqlDbType.NVarChar, request.CompanyCodeDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@SalesOrganization", SqlDbType.NVarChar, request.SalesOrganization),
|
|
SqlHelperExtension.CreateInParam("@SalesOrganizationDescription", SqlDbType.NVarChar, request.SalesOrganizationDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@DistributionChannel", SqlDbType.NVarChar, request.DistributionChannel),
|
|
SqlHelperExtension.CreateInParam("@DistributionChannelDescription", SqlDbType.NVarChar, request.DistributionChannelDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@Division", SqlDbType.NVarChar, request.Division),
|
|
SqlHelperExtension.CreateInParam("@DivisionDescription", SqlDbType.NVarChar, request.DivisionDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@MobileNumber", SqlDbType.NVarChar, request.MobileNumber),
|
|
SqlHelperExtension.CreateInParam("@EmailAddress", SqlDbType.NVarChar, request.EmailAddress),
|
|
|
|
SqlHelperExtension.CreateInParam("@BusinessTaxNumber", SqlDbType.NVarChar, request.BusinessTaxNumber),
|
|
SqlHelperExtension.CreateInParam("@CreditLimit", SqlDbType.Decimal, request.CreditLimit),
|
|
|
|
SqlHelperExtension.CreateInParam("@SalesGroup", SqlDbType.NVarChar, request.SalesGroup),
|
|
SqlHelperExtension.CreateInParam("@SalesGroupDescription", SqlDbType.NVarChar, request.SalesGroupDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@CustomerGroup", SqlDbType.NVarChar, request.CustomerGroup),
|
|
SqlHelperExtension.CreateInParam("@CustomerGroupDescription", SqlDbType.NVarChar, request.CustomerGroupDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@CustomerPriceGroup", SqlDbType.NVarChar, request.CustomerPriceGroup),
|
|
SqlHelperExtension.CreateInParam("@CustomerPriceGroupDescription", SqlDbType.NVarChar, request.CustomerPriceGroupDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@StatusCode", SqlDbType.NChar, request.StatusCode),
|
|
SqlHelperExtension.CreateInParam("@StatusDescription", SqlDbType.NVarChar, request.StatusDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@PaymentTerms", SqlDbType.NVarChar, request.PaymentTerms),
|
|
SqlHelperExtension.CreateInParam("@PaymentTermsDescription", SqlDbType.NVarChar, request.PaymentTermsDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@SearchTerm", SqlDbType.NVarChar, request.SearchTerm),
|
|
|
|
SqlHelperExtension.CreateInParam("@AreaRegion", SqlDbType.NVarChar, request.AreaRegion),
|
|
SqlHelperExtension.CreateInParam("@AreaRegionDescription", SqlDbType.NVarChar, request.AreaRegionDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@SalesUnitAreaAV", SqlDbType.NVarChar, request.SalesUnitAreaAV),
|
|
SqlHelperExtension.CreateInParam("@SalesUnitAreaAVDescription", SqlDbType.NVarChar, request.SalesUnitAreaAVDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@Territory", SqlDbType.NVarChar, request.Territory),
|
|
SqlHelperExtension.CreateInParam("@TerritoryName", SqlDbType.NVarChar, request.TerritoryName),
|
|
|
|
SqlHelperExtension.CreateInParam("@Plant", SqlDbType.NVarChar, request.Plant),
|
|
SqlHelperExtension.CreateInParam("@PlantName", SqlDbType.NVarChar, request.PlantName)
|
|
];
|
|
|
|
_ = tc.ExecuteNonQuerySp(spName: "dbo.UpdateCustomer", parameterValues: p);
|
|
|
|
returnValue = true;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
return returnValue;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Employee Private Functions
|
|
|
|
private async Task<EmployeeIntegrationResponse> GetEmployeeBySalesOrgAsync(TransactionContext tc, EmployeeIntegrationByComapanyRequest request)
|
|
{
|
|
EmployeeIntegrationResponse response = new EmployeeIntegrationResponse();
|
|
|
|
try
|
|
{
|
|
SqlParameter[] p =
|
|
[
|
|
SqlHelperExtension.CreateInParam(pName: "@EmployeeVendorCode", pType: SqlDbType.NVarChar, pValue: request.EmployeeVendorCode),
|
|
SqlHelperExtension.CreateInParam(pName: "@CompanyCode", pType: SqlDbType.NVarChar, pValue: request.CompanyCode)
|
|
];
|
|
|
|
using (IDataReader dr = await tc.ExecuteReaderSpAsync("dbo.GetEmployeeByVendorCode", parameterValues: p))
|
|
{
|
|
if (dr.Read())
|
|
{
|
|
response = new EmployeeIntegrationResponse()
|
|
{
|
|
EmployeeId = dr.GetInt32(0),
|
|
EmployeeVendorCode = dr.GetString(1),
|
|
EmployeeVendorName = dr.GetString(2),
|
|
Designation = dr.GetString(3),
|
|
DesignationDescription = dr.GetString(4),
|
|
MobileNo = dr.GetString(5),
|
|
Mail = dr.GetString(6),
|
|
CompanyCode = dr.GetString(7),
|
|
CompanyName = dr.GetString(8),
|
|
SalesOrg = dr.GetString(9),
|
|
SalesOrgDescription = dr.GetString(10),
|
|
DistChannel = dr.GetString(11),
|
|
DistChannelDescription = dr.GetString(12),
|
|
Division = dr.GetString(13),
|
|
DivisionDescription = dr.GetString(14),
|
|
RegionAreaCode = dr.GetString(15),
|
|
RegionAreaDescription = dr.GetString(16),
|
|
AreaAVSalesUnitCode = dr.GetString(17),
|
|
AreaAVSalesUnitDescription = dr.GetString(18),
|
|
Territory = dr.GetString(19),
|
|
TerritoryDescription = dr.GetString(20),
|
|
Plant = dr.GetString(21),
|
|
PlantDescription = dr.GetString(22),
|
|
Status = dr.GetString(23),
|
|
StatusDescription = dr.GetString(24)
|
|
};
|
|
}
|
|
dr.Close();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw DBCustomError.GenerateCustomError(ex);
|
|
}
|
|
|
|
return response;
|
|
}
|
|
|
|
private bool InsertEmployee(TransactionContext tc, EmployeeIntegrationRequest request)
|
|
{
|
|
bool returnValue = false;
|
|
|
|
try
|
|
{
|
|
SqlParameter[] p =
|
|
[
|
|
SqlHelperExtension.CreateInParam(pName: "@EmployeeVendorCode", pType: SqlDbType.NVarChar, pValue: request.EmployeeVendorCode),
|
|
SqlHelperExtension.CreateInParam(pName: "@EmployeeVendorName", pType: SqlDbType.NVarChar, pValue: request.EmployeeVendorName),
|
|
|
|
SqlHelperExtension.CreateInParam(pName: "@Designation", pType: SqlDbType.NVarChar, pValue: request.Designation),
|
|
SqlHelperExtension.CreateInParam(pName: "@DesignationDescription", pType: SqlDbType.NVarChar, pValue: request.DesignationDescription),
|
|
|
|
SqlHelperExtension.CreateInParam(pName: "@MobileNo", pType: SqlDbType.NVarChar, pValue: request.MobileNo),
|
|
SqlHelperExtension.CreateInParam(pName: "@Mail", pType: SqlDbType.NVarChar, pValue: request.Mail),
|
|
|
|
SqlHelperExtension.CreateInParam(pName: "@CompanyCode", pType: SqlDbType.NVarChar, pValue: request.CompanyCode),
|
|
SqlHelperExtension.CreateInParam(pName: "@CompanyName", pType: SqlDbType.NVarChar, pValue: request.CompanyName),
|
|
|
|
SqlHelperExtension.CreateInParam(pName: "@SalesOrg", pType: SqlDbType.NVarChar, pValue: request.SalesOrg),
|
|
SqlHelperExtension.CreateInParam(pName: "@SalesOrgDescription", pType: SqlDbType.NVarChar, pValue: request.SalesOrgDescription),
|
|
|
|
SqlHelperExtension.CreateInParam(pName: "@DistChannel", pType: SqlDbType.NVarChar, pValue: request.DistChannel),
|
|
SqlHelperExtension.CreateInParam(pName: "@DistChannelDescription", pType: SqlDbType.NVarChar, pValue: request.DistChannelDescription),
|
|
|
|
SqlHelperExtension.CreateInParam(pName: "@Division", pType: SqlDbType.NVarChar, pValue: request.Division),
|
|
SqlHelperExtension.CreateInParam(pName: "@DivisionDescription", pType: SqlDbType.NVarChar, pValue: request.DivisionDescription),
|
|
|
|
SqlHelperExtension.CreateInParam(pName: "@RegionAreaCode", pType: SqlDbType.NVarChar, pValue: request.RegionAreaCode),
|
|
SqlHelperExtension.CreateInParam(pName: "@RegionAreaDescription", pType: SqlDbType.NVarChar, pValue: request.RegionAreaDescription),
|
|
|
|
SqlHelperExtension.CreateInParam(pName: "@AreaAVSalesUnitCode", pType: SqlDbType.NVarChar, pValue: request.AreaAVSalesUnitCode),
|
|
SqlHelperExtension.CreateInParam(pName: "@AreaAVSalesUnitDescription", pType: SqlDbType.NVarChar, pValue: request.AreaAVSalesUnitDescription),
|
|
|
|
SqlHelperExtension.CreateInParam(pName: "@Territory", pType: SqlDbType.NVarChar, pValue: request.Territory),
|
|
SqlHelperExtension.CreateInParam(pName: "@TerritoryDescription", pType: SqlDbType.NVarChar, pValue: request.TerritoryDescription),
|
|
|
|
SqlHelperExtension.CreateInParam(pName: "@Plant", pType: SqlDbType.NVarChar, pValue: request.Plant),
|
|
SqlHelperExtension.CreateInParam(pName: "@PlantDescription", pType: SqlDbType.NVarChar, pValue: request.PlantDescription),
|
|
|
|
SqlHelperExtension.CreateInParam(pName: "@Status", pType: SqlDbType.NChar, pValue: request.Status),
|
|
SqlHelperExtension.CreateInParam(pName: "@StatusDescription", pType: SqlDbType.NVarChar, pValue: request.StatusDescription)
|
|
];
|
|
|
|
_ = tc.ExecuteNonQuerySp(spName: "dbo.InsertEmployee", parameterValues: p);
|
|
|
|
returnValue = true;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
return returnValue;
|
|
}
|
|
|
|
private bool UpdateEmployee(TransactionContext tc, EmployeeIntegrationRequest request)
|
|
{
|
|
bool returnValue = false;
|
|
|
|
try
|
|
{
|
|
SqlParameter[] p =
|
|
[
|
|
SqlHelperExtension.CreateInParam(pName: "@EmployeeVendorCode", pType: SqlDbType.NVarChar, pValue: request.EmployeeVendorCode),
|
|
SqlHelperExtension.CreateInParam(pName: "@CompanyCode", pType: SqlDbType.NVarChar, pValue: request.CompanyCode),
|
|
|
|
SqlHelperExtension.CreateInParam(pName: "@EmployeeVendorName", pType: SqlDbType.NVarChar, pValue: request.EmployeeVendorName),
|
|
|
|
SqlHelperExtension.CreateInParam(pName: "@Designation", pType: SqlDbType.NVarChar, pValue: request.Designation),
|
|
SqlHelperExtension.CreateInParam(pName: "@DesignationDescription", pType: SqlDbType.NVarChar, pValue: request.DesignationDescription),
|
|
|
|
SqlHelperExtension.CreateInParam(pName: "@MobileNo", pType: SqlDbType.NVarChar, pValue: request.MobileNo),
|
|
SqlHelperExtension.CreateInParam(pName: "@Mail", pType: SqlDbType.NVarChar, pValue: request.Mail),
|
|
|
|
SqlHelperExtension.CreateInParam(pName: "@CompanyName", pType: SqlDbType.NVarChar, pValue: request.CompanyName),
|
|
|
|
SqlHelperExtension.CreateInParam(pName: "@SalesOrg", pType: SqlDbType.NVarChar, pValue: request.SalesOrg),
|
|
SqlHelperExtension.CreateInParam(pName: "@SalesOrgDescription", pType: SqlDbType.NVarChar, pValue: request.SalesOrgDescription),
|
|
|
|
SqlHelperExtension.CreateInParam(pName: "@DistChannel", pType: SqlDbType.NVarChar, pValue: request.DistChannel),
|
|
SqlHelperExtension.CreateInParam(pName: "@DistChannelDescription", pType: SqlDbType.NVarChar, pValue: request.DistChannelDescription),
|
|
|
|
SqlHelperExtension.CreateInParam(pName: "@Division", pType: SqlDbType.NVarChar, pValue: request.Division),
|
|
SqlHelperExtension.CreateInParam(pName: "@DivisionDescription", pType: SqlDbType.NVarChar, pValue: request.DivisionDescription),
|
|
|
|
SqlHelperExtension.CreateInParam(pName: "@RegionAreaCode", pType: SqlDbType.NVarChar, pValue: request.RegionAreaCode),
|
|
SqlHelperExtension.CreateInParam(pName: "@RegionAreaDescription", pType: SqlDbType.NVarChar, pValue: request.RegionAreaDescription),
|
|
|
|
SqlHelperExtension.CreateInParam(pName: "@AreaAVSalesUnitCode", pType: SqlDbType.NVarChar, pValue: request.AreaAVSalesUnitCode),
|
|
SqlHelperExtension.CreateInParam(pName: "@AreaAVSalesUnitDescription", pType: SqlDbType.NVarChar, pValue: request.AreaAVSalesUnitDescription),
|
|
|
|
SqlHelperExtension.CreateInParam(pName: "@Territory", pType: SqlDbType.NVarChar, pValue: request.Territory),
|
|
SqlHelperExtension.CreateInParam(pName: "@TerritoryDescription", pType: SqlDbType.NVarChar, pValue: request.TerritoryDescription),
|
|
|
|
SqlHelperExtension.CreateInParam(pName: "@Plant", pType: SqlDbType.NVarChar, pValue: request.Plant),
|
|
SqlHelperExtension.CreateInParam(pName: "@PlantDescription", pType: SqlDbType.NVarChar, pValue: request.PlantDescription),
|
|
|
|
SqlHelperExtension.CreateInParam(pName: "@Status", pType: SqlDbType.NChar, pValue: request.Status),
|
|
SqlHelperExtension.CreateInParam(pName: "@StatusDescription", pType: SqlDbType.NVarChar, pValue: request.StatusDescription)
|
|
];
|
|
|
|
_ = tc.ExecuteNonQuerySp(spName: "dbo.UpdateEmployee", parameterValues: p);
|
|
|
|
returnValue = true;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
return returnValue;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Meterial Private Functions
|
|
|
|
private async Task<MaterialIntegrationResponse> GetMaterialByCodeAsync(TransactionContext tc, GetMaterialByCodeRequest request)
|
|
{
|
|
MaterialIntegrationResponse response = new MaterialIntegrationResponse();
|
|
|
|
try
|
|
{
|
|
SqlParameter[] p =
|
|
[
|
|
SqlHelperExtension.CreateInParam(pName: "@MaterialCode", pType: SqlDbType.NVarChar, pValue: request.MaterialCode)
|
|
];
|
|
|
|
using (IDataReader dr = await tc.ExecuteReaderSpAsync("dbo.GetMaterialByMaterialCode", parameterValues: p))
|
|
{
|
|
if (dr.Read())
|
|
{
|
|
response = new MaterialIntegrationResponse()
|
|
{
|
|
MeterialId = dr.GetInt32(0),
|
|
MaterialType = dr.GetString(1),
|
|
MaterialTypeDescription = dr.GetString(2),
|
|
MaterialCode = dr.GetString(3),
|
|
MaterialDescription = dr.GetString(4),
|
|
MaterialGroupCode = dr.GetString(5),
|
|
MaterialGroupDescription = dr.GetString(6),
|
|
BaseUnitOfMeasure = dr.GetString(7),
|
|
SalesUnitOfMeasure = dr.GetString(8),
|
|
UnitConversionWithBaseUoM = dr.GetDecimal(9),
|
|
PlantCode = dr.GetString(10),
|
|
PlantDescription = dr.GetString(11),
|
|
StorageLocationCode = dr.GetString(12),
|
|
StorageLocationDescription = dr.GetString(13),
|
|
SalesOrganization = dr.GetString(14),
|
|
SalesOrganizationDescription = dr.GetString(15),
|
|
};
|
|
}
|
|
dr.Close();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw DBCustomError.GenerateCustomError(ex);
|
|
}
|
|
|
|
return response;
|
|
}
|
|
|
|
private bool CreateMaterial(TransactionContext tc, MaterialIntegrationRequest request)
|
|
{
|
|
bool returnValue = false;
|
|
|
|
try
|
|
{
|
|
SqlParameter[] p =
|
|
[
|
|
SqlHelperExtension.CreateInParam("@MaterialType", SqlDbType.NVarChar, request.MaterialType),
|
|
SqlHelperExtension.CreateInParam("@MaterialTypeDescription", SqlDbType.NVarChar, request.MaterialTypeDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@MaterialCode", SqlDbType.NVarChar, request.MaterialCode),
|
|
SqlHelperExtension.CreateInParam("@MaterialDescription", SqlDbType.NVarChar, request.MaterialDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@MaterialGroupCode", SqlDbType.NVarChar, request.MaterialGroupCode),
|
|
SqlHelperExtension.CreateInParam("@MaterialGroupDescription", SqlDbType.NVarChar, request.MaterialGroupDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@BaseUnitOfMeasure", SqlDbType.NVarChar, request.BaseUnitOfMeasure),
|
|
SqlHelperExtension.CreateInParam("@SalesUnitOfMeasure", SqlDbType.NVarChar, request.SalesUnitOfMeasure),
|
|
|
|
SqlHelperExtension.CreateInParam("@UnitConversionWithBaseUoM", SqlDbType.Decimal, request.UnitConversionWithBaseUoM),
|
|
|
|
SqlHelperExtension.CreateInParam("@PlantCode", SqlDbType.NVarChar, request.PlantCode),
|
|
SqlHelperExtension.CreateInParam("@PlantDescription", SqlDbType.NVarChar, request.PlantDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@StorageLocationCode", SqlDbType.NVarChar, request.StorageLocationCode),
|
|
SqlHelperExtension.CreateInParam("@StorageLocationDescription", SqlDbType.NVarChar, request.StorageLocationDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@SalesOrganization", SqlDbType.NVarChar, request.SalesOrganization),
|
|
SqlHelperExtension.CreateInParam("@SalesOrganizationDescription", SqlDbType.NVarChar, request.SalesOrganizationDescription)
|
|
];
|
|
|
|
_ = tc.ExecuteNonQuerySp(spName: "dbo.CreateMaterial", parameterValues: p);
|
|
|
|
returnValue = true;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
return returnValue;
|
|
}
|
|
|
|
private bool UpdateMaterial(TransactionContext tc, MaterialIntegrationRequest request)
|
|
{
|
|
bool returnValue = false;
|
|
|
|
try
|
|
{
|
|
SqlParameter[] p =
|
|
[
|
|
SqlHelperExtension.CreateInParam("@MaterialType", SqlDbType.NVarChar, request.MaterialType),
|
|
SqlHelperExtension.CreateInParam("@MaterialTypeDescription", SqlDbType.NVarChar, request.MaterialTypeDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@MaterialCode", SqlDbType.NVarChar, request.MaterialCode),
|
|
SqlHelperExtension.CreateInParam("@MaterialDescription", SqlDbType.NVarChar, request.MaterialDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@MaterialGroupCode", SqlDbType.NVarChar, request.MaterialGroupCode),
|
|
SqlHelperExtension.CreateInParam("@MaterialGroupDescription", SqlDbType.NVarChar, request.MaterialGroupDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@BaseUnitOfMeasure", SqlDbType.NVarChar, request.BaseUnitOfMeasure),
|
|
SqlHelperExtension.CreateInParam("@SalesUnitOfMeasure", SqlDbType.NVarChar, request.SalesUnitOfMeasure),
|
|
|
|
SqlHelperExtension.CreateInParam("@UnitConversionWithBaseUoM", SqlDbType.Decimal, request.UnitConversionWithBaseUoM),
|
|
|
|
SqlHelperExtension.CreateInParam("@PlantCode", SqlDbType.NVarChar, request.PlantCode),
|
|
SqlHelperExtension.CreateInParam("@PlantDescription", SqlDbType.NVarChar, request.PlantDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@StorageLocationCode", SqlDbType.NVarChar, request.StorageLocationCode),
|
|
SqlHelperExtension.CreateInParam("@StorageLocationDescription", SqlDbType.NVarChar, request.StorageLocationDescription),
|
|
|
|
SqlHelperExtension.CreateInParam("@SalesOrganization", SqlDbType.NVarChar, request.SalesOrganization),
|
|
SqlHelperExtension.CreateInParam("@SalesOrganizationDescription", SqlDbType.NVarChar, request.SalesOrganizationDescription)
|
|
];
|
|
|
|
_ = tc.ExecuteNonQuerySp(spName: "dbo.UpdateMaterial", parameterValues: p);
|
|
|
|
returnValue = true;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
return returnValue;
|
|
}
|
|
|
|
#endregion
|
|
}
|