Compare commits
6 Commits
main
...
Dev_Integr
| Author | SHA1 | Date | |
|---|---|---|---|
| cc740be2d5 | |||
| 3f6204975b | |||
| 0e5a7b30ef | |||
| 7819705964 | |||
| 3bfab96c0d | |||
| 99f820ff0f |
|
|
@ -0,0 +1,41 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace OnlineSalesAutoCrop.CoreAPI.Models.Requests.Integrations;
|
||||||
|
|
||||||
|
public class EmployeeIntegrationRequest
|
||||||
|
{
|
||||||
|
public string EmployeeVendorCode { get; set; }
|
||||||
|
public string EmployeeVendorName { get; set; }
|
||||||
|
public string DesignationCode { get; set; }
|
||||||
|
public string DesignationDescription { get; set; }
|
||||||
|
public string MobileNo { get; set; }
|
||||||
|
public string Email { get; set; }
|
||||||
|
public string SalesOrgCode { get; set; }
|
||||||
|
public string SalesOrgDescription { get; set; }
|
||||||
|
public string DistChannelCode { get; set; }
|
||||||
|
public string DistChannelDescription { get; set; }
|
||||||
|
public string DivisionCode { get; set; }
|
||||||
|
public string DivisionDescription { get; set; }
|
||||||
|
public string RegionAAl { get; set; }
|
||||||
|
public string AreaCode { get; set; }
|
||||||
|
public string AreaDescription { get; set; }
|
||||||
|
public string SalesUnitACCLCode { get; set; }
|
||||||
|
public string SalesUnitACCLDescription { get; set; }
|
||||||
|
public string TerritoryCode { get; set; }
|
||||||
|
public string TerritoryDescription { get; set; }
|
||||||
|
public string SalesOfficeCode { get; set; }
|
||||||
|
public string SalesOfficeDescription { get; set; }
|
||||||
|
public string PlantCode { get; set; }
|
||||||
|
public string PlantDescription { get; set; }
|
||||||
|
public string Status { get; set; }
|
||||||
|
public string StatusDescription { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class EmployeeBySalesOrgCodeRequest
|
||||||
|
{
|
||||||
|
public string EmployeeVendorCode { get; set; } = string.Empty;
|
||||||
|
public string SalesOrgCode { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
|
@ -2,7 +2,9 @@
|
||||||
|
|
||||||
public class CustomerIntegrationResponse : ResponseBase
|
public class CustomerIntegrationResponse : ResponseBase
|
||||||
{
|
{
|
||||||
|
public string CustomerNumber { get; set; }
|
||||||
|
public string CompanyCode { get; set; }
|
||||||
|
public bool IsUpdated { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CustomerByCompanyCodeResponse : ResponseBase
|
public class CustomerByCompanyCodeResponse : ResponseBase
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
namespace OnlineSalesAutoCrop.CoreAPI.Models.Responses.Integrations;
|
||||||
|
|
||||||
|
public class EmployeeIntegrationResponse : ResponseBase
|
||||||
|
{
|
||||||
|
|
||||||
|
public int EmployeeVendorId { get; set; }
|
||||||
|
public string EmployeeVendorCode { get; set; }
|
||||||
|
public string EmployeeVendorName { get; set; }
|
||||||
|
public string DesignationCode { get; set; }
|
||||||
|
public string DesignationDescription { get; set; }
|
||||||
|
public string MobileNo { get; set; }
|
||||||
|
public string Email { get; set; }
|
||||||
|
public string SalesOrgCode { get; set; }
|
||||||
|
public string SalesOrgDescription { get; set; }
|
||||||
|
public string DistChannelCode { get; set; }
|
||||||
|
public string DistChannelDescription { get; set; }
|
||||||
|
public string DivisionCode { get; set; }
|
||||||
|
public string DivisionDescription { get; set; }
|
||||||
|
public string RegionAAl { get; set; }
|
||||||
|
public string AreaCode { get; set; }
|
||||||
|
public string AreaDescription { get; set; }
|
||||||
|
public string SalesUnitACCLCode { get; set; }
|
||||||
|
public string SalesUnitACCLDescription { get; set; }
|
||||||
|
public string TerritoryCode { get; set; }
|
||||||
|
public string TerritoryDescription { get; set; }
|
||||||
|
public string SalesOfficeCode { get; set; }
|
||||||
|
public string SalesOfficeDescription { get; set; }
|
||||||
|
public string PlantCode { get; set; }
|
||||||
|
public string PlantDescription { get; set; }
|
||||||
|
public string Status { get; set; }
|
||||||
|
public string StatusDescription { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class EmployeeIntegrationReqResponse : ResponseBase
|
||||||
|
{
|
||||||
|
public string EmployeeVendorCode { get; set; }
|
||||||
|
public string SalesOrgCode { get; set; }
|
||||||
|
public bool IsUpdated { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -7,6 +7,8 @@ namespace OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Integrations;
|
||||||
|
|
||||||
public interface IIntegrationService
|
public interface IIntegrationService
|
||||||
{
|
{
|
||||||
Task<bool> UpsertCustomerAsync(CustomerIntegrationRequest request);
|
Task<CustomerIntegrationResponse> UpsertCustomerAsync(CustomerIntegrationRequest request);
|
||||||
Task<CustomerByCompanyCodeResponse> GetCustomerByCompanyCodeAsync(CustomerByCompanyCodeRequest request);
|
Task<CustomerByCompanyCodeResponse> GetCustomerByCompanyCodeAsync(CustomerByCompanyCodeRequest request);
|
||||||
|
Task<EmployeeIntegrationReqResponse> UpsertEmployeeAsync(EmployeeIntegrationRequest request);
|
||||||
|
Task<EmployeeIntegrationResponse> GetEmployeeBySalesOrgAsync(EmployeeBySalesOrgCodeRequest request);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,6 @@ using OnlineSalesAutoCrop.CoreAPI.Models.Responses.Integrations;
|
||||||
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Integrations;
|
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Integrations;
|
||||||
using System;
|
using System;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Security.Cryptography;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace OnlineSalesAutoCrop.CoreAPI.Services.Services.Integrations;
|
namespace OnlineSalesAutoCrop.CoreAPI.Services.Services.Integrations;
|
||||||
|
|
@ -50,12 +48,12 @@ public class IntegrationService : IIntegrationService
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task<bool> UpsertCustomerAsync(CustomerIntegrationRequest request)
|
public async Task<CustomerIntegrationResponse> UpsertCustomerAsync(CustomerIntegrationRequest request)
|
||||||
{
|
{
|
||||||
bool response = false;
|
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,12 +61,19 @@ 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.IsUpdated = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//Insert Here
|
//Insert Here
|
||||||
|
|
||||||
|
CreateCustomer(tc, request);
|
||||||
|
response.IsUpdated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
response.CustomerNumber = request.CustomerNumber;
|
||||||
|
response.CompanyCode = request.CompanyCode;
|
||||||
tc.End();
|
tc.End();
|
||||||
}
|
}
|
||||||
catch (Exception ie)
|
catch (Exception ie)
|
||||||
|
|
@ -104,6 +109,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(),
|
||||||
|
|
@ -149,4 +155,301 @@ public class IntegrationService : IIntegrationService
|
||||||
}
|
}
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public async Task<EmployeeIntegrationResponse> GetEmployeeBySalesOrgAsync(EmployeeBySalesOrgCodeRequest 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);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
EmployeeIntegrationResponse employee = await GetEmployeeBySalesOrgAsync(tc, new EmployeeBySalesOrgCodeRequest() { SalesOrgCode = request.SalesOrgCode, EmployeeVendorCode = request.EmployeeVendorCode });
|
||||||
|
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: "@DesignationCode", pType: SqlDbType.NVarChar, pValue: request.DesignationCode),
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@DesignationDescription", pType: SqlDbType.NVarChar, pValue: request.DesignationDescription),
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@MobileNo", pType: SqlDbType.NVarChar, pValue: request.MobileNo),
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@Email", pType: SqlDbType.NVarChar, pValue: request.Email),
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@SalesOrgCode", pType: SqlDbType.NVarChar, pValue: request.SalesOrgCode),
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@SalesOrgDescription", pType: SqlDbType.NVarChar, pValue: request.SalesOrgDescription),
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@DistChannelCode", pType: SqlDbType.NVarChar, pValue: request.DistChannelCode),
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@DistChannelDescription", pType: SqlDbType.NVarChar, pValue: request.DistChannelDescription),
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@DivisionCode", pType: SqlDbType.NVarChar, pValue: request.DivisionCode),
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@DivisionDescription", pType: SqlDbType.NVarChar, pValue: request.DivisionDescription),
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@RegionAAl", pType: SqlDbType.NVarChar, pValue: request.RegionAAl),
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@AreaCode", pType: SqlDbType.NVarChar, pValue: request.AreaCode),
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@AreaDescription", pType: SqlDbType.NVarChar, pValue: request.AreaDescription),
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@SalesUnitACCLCode", pType: SqlDbType.NVarChar, pValue: request.SalesUnitACCLCode),
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@SalesUnitACCLDescription", pType: SqlDbType.NVarChar, pValue: request.SalesUnitACCLDescription),
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@TerritoryCode", pType: SqlDbType.NVarChar, pValue: request.TerritoryCode),
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@TerritoryDescription", pType: SqlDbType.NVarChar, pValue: request.TerritoryDescription),
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@SalesOfficeCode", pType: SqlDbType.NVarChar, pValue: request.SalesOfficeCode),
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@SalesOfficeDescription", pType: SqlDbType.NVarChar, pValue: request.SalesOfficeDescription),
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@PlantCode", pType: SqlDbType.NVarChar, pValue: request.PlantCode),
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@PlantDescription", pType: SqlDbType.NVarChar, pValue: request.PlantDescription),
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@Status", pType: SqlDbType.NVarChar, pValue: request.Status),
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@StatusDescription", pType: SqlDbType.NVarChar, pValue: request.StatusDescription),
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
if (employee != null && employee.EmployeeVendorId > 0)
|
||||||
|
{
|
||||||
|
_= tc.ExecuteNonQuerySp("dbo.UpdateEmployee", p);
|
||||||
|
response.IsUpdated = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_= tc.ExecuteNonQuerySp("dbo.InsertEmployee", p);
|
||||||
|
response.IsUpdated = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
response.EmployeeVendorCode = request.EmployeeVendorCode;
|
||||||
|
response.SalesOrgCode = request.SalesOrgCode;
|
||||||
|
tc.End();
|
||||||
|
}
|
||||||
|
catch (Exception ie)
|
||||||
|
{
|
||||||
|
tc?.HandleError();
|
||||||
|
|
||||||
|
throw DBCustomError.GenerateCustomError(ie);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<EmployeeIntegrationResponse> GetEmployeeBySalesOrgAsync(TransactionContext tc, EmployeeBySalesOrgCodeRequest request)
|
||||||
|
{
|
||||||
|
EmployeeIntegrationResponse response = new EmployeeIntegrationResponse();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SqlParameter[] p =
|
||||||
|
[
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@EmployeeVendorCode", pType: SqlDbType.NVarChar,pValue: request.EmployeeVendorCode ),
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@SalesOrgCode", pType: SqlDbType.NVarChar,pValue: request.SalesOrgCode )
|
||||||
|
];
|
||||||
|
|
||||||
|
using (IDataReader dr = await tc.ExecuteReaderSpAsync("dbo.GetEmployeeBySalesOrgCode", parameterValues: p))
|
||||||
|
{
|
||||||
|
if (dr.Read())
|
||||||
|
{
|
||||||
|
response = new EmployeeIntegrationResponse()
|
||||||
|
{
|
||||||
|
EmployeeVendorId = dr.GetInt32(0),
|
||||||
|
EmployeeVendorCode = dr.GetString(1),
|
||||||
|
EmployeeVendorName = dr.GetString(2),
|
||||||
|
DesignationCode = dr.GetString(3),
|
||||||
|
DesignationDescription = dr.GetString(4),
|
||||||
|
MobileNo = dr.GetString(5),
|
||||||
|
Email = dr.GetString(6),
|
||||||
|
SalesOrgCode = dr.GetString(7),
|
||||||
|
SalesOrgDescription = dr.GetString(8),
|
||||||
|
DistChannelCode = dr.GetString(9),
|
||||||
|
DistChannelDescription = dr.GetString(10),
|
||||||
|
DivisionCode = dr.GetString(11),
|
||||||
|
DivisionDescription = dr.GetString(12),
|
||||||
|
RegionAAl = dr.GetString(13),
|
||||||
|
AreaCode = dr.GetString(14),
|
||||||
|
AreaDescription = dr.GetString(15),
|
||||||
|
SalesUnitACCLCode = dr.GetString(16),
|
||||||
|
SalesUnitACCLDescription = dr.GetString(17),
|
||||||
|
TerritoryCode = dr.GetString(18),
|
||||||
|
TerritoryDescription = dr.GetString(19),
|
||||||
|
SalesOfficeCode = dr.GetString(20),
|
||||||
|
SalesOfficeDescription = dr.GetString(21),
|
||||||
|
PlantCode = dr.GetString(22),
|
||||||
|
PlantDescription = dr.GetString(23),
|
||||||
|
Status = dr.GetString(24),
|
||||||
|
StatusDescription = dr.GetString(25)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
dr.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw DBCustomError.GenerateCustomError(ex);
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@ using Ease.NetCore.DataAccess.SQL;
|
||||||
using Ease.NetCore.Utility;
|
using Ease.NetCore.Utility;
|
||||||
using OnlineSalesAutoCrop.CoreAPI.Models;
|
using OnlineSalesAutoCrop.CoreAPI.Models;
|
||||||
using OnlineSalesAutoCrop.CoreAPI.Models.Global;
|
using OnlineSalesAutoCrop.CoreAPI.Models.Global;
|
||||||
using OnlineSalesAutoCrop.CoreAPI.Models.Objects;
|
|
||||||
using OnlineSalesAutoCrop.CoreAPI.Models.Objects.Setups;
|
|
||||||
using OnlineSalesAutoCrop.CoreAPI.Models.Objects.Systems;
|
using OnlineSalesAutoCrop.CoreAPI.Models.Objects.Systems;
|
||||||
using OnlineSalesAutoCrop.CoreAPI.Models.Requests.Systems;
|
using OnlineSalesAutoCrop.CoreAPI.Models.Requests.Systems;
|
||||||
using OnlineSalesAutoCrop.CoreAPI.Models.Responses.Systems;
|
using OnlineSalesAutoCrop.CoreAPI.Models.Responses.Systems;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.SignalR;
|
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
|
@ -20,7 +19,6 @@ using OnlineSalesAutoCrop.CoreAPI.Models.Responses.Integrations;
|
||||||
using OnlineSalesAutoCrop.CoreAPI.Models.Responses.Systems;
|
using OnlineSalesAutoCrop.CoreAPI.Models.Responses.Systems;
|
||||||
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Auth;
|
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Auth;
|
||||||
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Systems;
|
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Systems;
|
||||||
using OnlineSalesAutoCrop.CoreAPI.SignalRHub;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.DirectoryServices;
|
using System.DirectoryServices;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ using Microsoft.Extensions.Logging;
|
||||||
using OnlineSalesAutoCrop.CoreAPI.Models.Requests.Integrations;
|
using OnlineSalesAutoCrop.CoreAPI.Models.Requests.Integrations;
|
||||||
using OnlineSalesAutoCrop.CoreAPI.Models.Responses.Integrations;
|
using OnlineSalesAutoCrop.CoreAPI.Models.Responses.Integrations;
|
||||||
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Integrations;
|
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Integrations;
|
||||||
using OnlineSalesAutoCrop.CoreAPI.Services.Services.Integrations;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
|
@ -39,7 +38,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)
|
||||||
|
|
@ -47,8 +46,8 @@ namespace OnlineSalesAutoCrop.CoreAPI.Controllers.IntegretionApi
|
||||||
CustomerIntegrationResponse response = new CustomerIntegrationResponse();
|
CustomerIntegrationResponse response = new CustomerIntegrationResponse();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
bool result = await _integrationService.UpsertCustomerAsync(request);
|
response = await _integrationService.UpsertCustomerAsync(request);
|
||||||
if (result)
|
if (!response.IsUpdated)
|
||||||
{
|
{
|
||||||
response.ReturnMessage.Add($"Customer Created Successfully for CustomerNumber :{request.CustomerNumber} & CompanyCode:{request.CompanyCode}");
|
response.ReturnMessage.Add($"Customer Created Successfully for CustomerNumber :{request.CustomerNumber} & CompanyCode:{request.CompanyCode}");
|
||||||
response.ReturnStatus = StatusCodes.Status201Created;
|
response.ReturnStatus = StatusCodes.Status201Created;
|
||||||
|
|
@ -57,8 +56,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)
|
||||||
|
|
@ -70,5 +69,44 @@ namespace OnlineSalesAutoCrop.CoreAPI.Controllers.IntegretionApi
|
||||||
return StatusCode(StatusCodes.Status500InternalServerError, response);
|
return StatusCode(StatusCodes.Status500InternalServerError, response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Insert or Update Employees for SAP
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <returns>if created return 201 or if updated return 204 true</returns>
|
||||||
|
[HttpGet("Employees")]
|
||||||
|
[IgnoreAntiforgeryToken]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(EmployeeIntegrationReqResponse))]
|
||||||
|
public async Task<IActionResult> UpsertEmployee(EmployeeIntegrationRequest request)
|
||||||
|
{
|
||||||
|
EmployeeIntegrationReqResponse response = new EmployeeIntegrationReqResponse();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
response = await _integrationService.UpsertEmployeeAsync(request);
|
||||||
|
if (!response.IsUpdated)
|
||||||
|
{
|
||||||
|
response.ReturnMessage.Add($"Employee Created Successfully for EmployeeVendorName :{request.EmployeeVendorName} & SalesOrgCode:{request.SalesOrgCode}");
|
||||||
|
response.ReturnStatus = StatusCodes.Status201Created;
|
||||||
|
return StatusCode(StatusCodes.Status201Created, response);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
response.ReturnMessage.Add($"Employee Updated Successfully for EmployeeVendorName :{request.EmployeeVendorName} & SalesOrgCode:{request.SalesOrgCode}");
|
||||||
|
response.ReturnStatus = StatusCodes.Status204NoContent;
|
||||||
|
return StatusCode(StatusCodes.Status204NoContent, response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
string msg = $"Exception Occur in Employee Operation {request?.EmployeeVendorName}~{request?.SalesOrgCode}";
|
||||||
|
_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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user