Compare commits

...

10 Commits

21 changed files with 1504 additions and 2151 deletions

1
.gitignore vendored
View File

@ -19,3 +19,4 @@ obj
/OnlineSalesAutoCrop/App_Data/RadUploadTemp
/OnlineSalesAutoCrop/App/ClientApp/node_modules
/App/ClientApp/node_modules
/Api/OnlineSalesAutoCrop.CoreAPI/.config/dotnet-tools.json

View File

@ -1,57 +1,42 @@
namespace OnlineSalesAutoCrop.CoreAPI.Models.Objects.Integrations;
using System.ComponentModel.DataAnnotations;
namespace OnlineSalesAutoCrop.CoreAPI.Models.Objects.Integrations;
public class CustomerIntegration
{
public int CustomerId { get; set; }
public string CustomerNumber { get; set; }
public string CustomerName { get; set; }
public string AccountGroup { get; set; }
public string AccountGroupDescription { get; set; }
public string CompanyCode { get; set; }
public string CompanyCodeDescription { get; set; }
public string SalesOrganization { get; set; }
public string SalesOrganizationDescription { get; set; }
public string DistributionChannel { get; set; }
public string DistributionChannelDescription { get; set; }
public string Division { get; set; }
public string DivisionDescription { get; set; }
public string MobileNumber { get; set; }
public string EmailAddress { get; set; }
public string BusinessTaxNumber { get; set; }
public decimal? CreditLimit { get; set; }
public string SalesOffice { get; set; }
public string SalesOfficeDescription { get; set; }
public decimal CreditLimit { get; set; }
public string SalesGroup { get; set; }
public string SalesGroupDescription { get; set; }
public string CustomerGroup { get; set; }
public string Status { get; set; }
public string CustomerGroupDescription { get; set; }
public string CustomerPriceGroup { get; set; }
public string CustomerPriceGroupDescription { get; set; }
public string StatusCode { get; set; }
public string StatusDescription { get; set; }
public string PaymentTerms { get; set; }
public string PaymentTermsDescription { get; set; }
public string SearchTerm { get; set; }
public string Region { get; set; }
public string RegionName { get; set; }
public string Area { get; set; }
public string AreaName { get; set; }
public string SalesUnit { get; set; }
public string SalesUnitName { get; set; }
public string AreaRegion { get; set; }
public string AreaRegionDescription { get; set; }
public string SalesUnitAreaAV { get; set; }
public string SalesUnitAreaAVDescription { get; set; }
public string Territory { get; set; }
public string TerritoryName { get; set; }
public string Plant { get; set; }
public string PlantName { get; set; }
}

View File

@ -0,0 +1,29 @@
namespace OnlineSalesAutoCrop.CoreAPI.Models.Objects.Integrations;
public class EmployeeIntegration
{
public string EmployeeVendorCode { get; set; }
public string EmployeeVendorName { get; set; }
public string Designation { get; set; }
public string DesignationDescription { get; set; }
public string MobileNo { get; set; }
public string Mail { get; set; }
public string CompanyCode { get; set; }
public string CompanyName { get; set; }
public string SalesOrg { get; set; }
public string SalesOrgDescription { get; set; }
public string DistChannel { get; set; }
public string DistChannelDescription { get; set; }
public string Division { get; set; }
public string DivisionDescription { get; set; }
public string RegionAreaCode { get; set; }
public string RegionAreaDescription { get; set; }
public string AreaAVSalesUnitCode { get; set; }
public string AreaAVSalesUnitDescription { get; set; }
public string Territory { get; set; }
public string TerritoryDescription { get; set; }
public string Plant { get; set; }
public string PlantDescription { get; set; }
public string Status { get; set; }
public string StatusDescription { get; set; }
}

View File

@ -0,0 +1,26 @@
using System;
using System.ComponentModel.DataAnnotations;
namespace OnlineSalesAutoCrop.CoreAPI.Models.Objects.Integrations;
public class MaterialIntegration
{
public int MeterialId { get; set; }
public string MaterialType { get; set; }
public string MaterialTypeDescription { get; set; }
public string MaterialCode { get; set; }
public string MaterialDescription { get; set; }
public string MaterialGroupCode { get; set; }
public string MaterialGroupDescription { get; set; }
public string BaseUnitOfMeasure { get; set; }
public string SalesUnitOfMeasure { get; set; }
public decimal UnitConversionWithBaseUoM { get; set; }
public string PlantCode { get; set; }
public string PlantDescription { get; set; }
public string StorageLocationCode { get; set; }
public string StorageLocationDescription { get; set; }
public string SalesOrganization { get; set; }
public string SalesOrganizationDescription { get; set; }
public DateTime CreatedDate { get; set; }
public DateTime? UpdatedDate { get; set; }
}

View File

@ -7,141 +7,150 @@ namespace OnlineSalesAutoCrop.CoreAPI.Models.Requests.Integrations;
public class CustomerIntegrationRequest
{
[Required(ErrorMessage = "Customer Number is required")]
[StringLength(10, MinimumLength = 1, ErrorMessage = "Customer Number must be between 1 and 10 characters")]
public string CustomerNumber { get; set; } = string.Empty;
[Required(ErrorMessage = "Customer number is required.")]
[StringLength(10, ErrorMessage = "Customer number cannot exceed 10 characters.")]
public string CustomerNumber { get; set; }
[Required(ErrorMessage = "Customer Name is required")]
[StringLength(35, MinimumLength = 1, ErrorMessage = "Customer Name must be between 1 and 35 characters")]
public string CustomerName { get; set; } = string.Empty;
[Required(ErrorMessage = "Customer name is required.")]
[StringLength(35, ErrorMessage = "Customer name cannot exceed 35 characters.")]
public string CustomerName { get; set; }
[Required(ErrorMessage = "Account Group is required")]
[StringLength(3, MinimumLength = 1, ErrorMessage = "Account Group must be between 1 and 3 characters")]
public string AccountGroup { get; set; } = string.Empty;
[Required(ErrorMessage = "Account group is required.")]
[StringLength(4, ErrorMessage = "Account group cannot exceed 3 characters.")]
public string AccountGroup { get; set; }
[Required(ErrorMessage = "Account Group Description is required")]
[StringLength(30, ErrorMessage = "Account Group Description cannot exceed 30 characters")]
public string AccountGroupDescription { get; set; } = string.Empty;
[Required(ErrorMessage = "Account group description is required.")]
[StringLength(30, ErrorMessage = "Account group description cannot exceed 30 characters.")]
public string AccountGroupDescription { get; set; }
[Required(ErrorMessage = "Company Code is required")]
[StringLength(4, MinimumLength = 1, ErrorMessage = "Company Code must be between 1 and 4 characters")]
public string CompanyCode { get; set; } = string.Empty;
[Required(ErrorMessage = "Company code is required.")]
[StringLength(4, ErrorMessage = "Company code cannot exceed 4 characters.")]
public string CompanyCode { get; set; }
[Required(ErrorMessage = "Company Code Description is required")]
[StringLength(25, ErrorMessage = "Company Code Description cannot exceed 25 characters")]
public string CompanyCodeDescription { get; set; } = string.Empty;
[Required(ErrorMessage = "Company code description is required.")]
[StringLength(25, ErrorMessage = "Company code description cannot exceed 25 characters.")]
public string CompanyCodeDescription { get; set; }
[Required(ErrorMessage = "Sales Organization is required")]
[StringLength(4, MinimumLength = 1, ErrorMessage = "Sales Organization must be between 1 and 4 characters")]
public string SalesOrganization { get; set; } = string.Empty;
[Required(ErrorMessage = "Sales organization is required.")]
[StringLength(4, ErrorMessage = "Sales organization cannot exceed 4 characters.")]
public string SalesOrganization { get; set; }
[Required(ErrorMessage = "Sales Organization Description is required")]
[StringLength(40, ErrorMessage = "Sales Organization Description cannot exceed 40 characters")]
public string SalesOrganizationDescription { get; set; } = string.Empty;
[Required(ErrorMessage = "Sales organization description is required.")]
[StringLength(40, ErrorMessage = "Sales organization description cannot exceed 40 characters.")]
public string SalesOrganizationDescription { get; set; }
[Required(ErrorMessage = "Distribution Channel is required")]
[StringLength(2, MinimumLength = 1, ErrorMessage = "Distribution Channel must be between 1 and 2 characters")]
public string DistributionChannel { get; set; } = string.Empty;
[Required(ErrorMessage = "Distribution channel is required.")]
[StringLength(2, ErrorMessage = "Distribution channel cannot exceed 2 characters.")]
public string DistributionChannel { get; set; }
[Required(ErrorMessage = "Distribution Channel Description is required")]
[StringLength(20, ErrorMessage = "Distribution Channel Description cannot exceed 20 characters")]
public string DistributionChannelDescription { get; set; } = string.Empty;
[Required(ErrorMessage = "Distribution channel description is required.")]
[StringLength(20, ErrorMessage = "Distribution channel description cannot exceed 20 characters.")]
public string DistributionChannelDescription { get; set; }
[Required(ErrorMessage = "Division is required")]
[StringLength(2, MinimumLength = 1, ErrorMessage = "Division must be between 1 and 2 characters")]
public string Division { get; set; } = string.Empty;
[Required(ErrorMessage = "Division is required.")]
[StringLength(2, ErrorMessage = "Division cannot exceed 2 characters.")]
public string Division { get; set; }
[Required(ErrorMessage = "Division Description is required")]
[StringLength(20, ErrorMessage = "Division Description cannot exceed 20 characters")]
public string DivisionDescription { get; set; } = string.Empty;
[Required(ErrorMessage = "Division description is required.")]
[StringLength(20, ErrorMessage = "Division description cannot exceed 20 characters.")]
public string DivisionDescription { get; set; }
[Required(ErrorMessage = "Mobile Number is required")]
[StringLength(31, ErrorMessage = "Mobile Number cannot exceed 31 characters")]
[Phone(ErrorMessage = "Invalid mobile number format")]
public string MobileNumber { get; set; } = string.Empty;
[Required(ErrorMessage = "Mobile number is required.")]
[StringLength(31, ErrorMessage = "Mobile number cannot exceed 31 characters.")]
[Phone(ErrorMessage = "Mobile number is not a valid phone number.")]
public string MobileNumber { get; set; }
[Required(ErrorMessage = "Email Address is required")]
[StringLength(241, ErrorMessage = "Email Address cannot exceed 241 characters")]
[EmailAddress(ErrorMessage = "Invalid email address format")]
public string EmailAddress { get; set; } = string.Empty;
[Required(ErrorMessage = "Email address is required.")]
[StringLength(241, ErrorMessage = "Email address cannot exceed 241 characters.")]
[EmailAddress(ErrorMessage = "Email address is not valid.")]
public string EmailAddress { get; set; }
[Required(ErrorMessage = "Business/Tax Number is required")]
[StringLength(16, ErrorMessage = "Business/Tax Number cannot exceed 16 characters")]
public string BusinessTaxNumber { get; set; } = string.Empty;
[Required(ErrorMessage = "Business/Tax number is required.")]
[StringLength(16, ErrorMessage = "Business/Tax number cannot exceed 16 characters.")]
public string BusinessTaxNumber { get; set; }
[Required(ErrorMessage = "Credit Limit is required")]
[Range(0, 9999999999999, ErrorMessage = "Credit Limit must be a valid number")]
[Required(ErrorMessage = "Credit limit is required.")]
[Range(0, 9999999999999.99, ErrorMessage = "Credit limit must be between 0 and 9,999,999,999,999.99.")]
public decimal CreditLimit { get; set; }
[Required(ErrorMessage = "Sales Office is required")]
[StringLength(4, MinimumLength = 1, ErrorMessage = "Sales Office must be between 1 and 4 characters")]
public string SalesOffice { get; set; } = string.Empty;
[Required(ErrorMessage = "Sales group is required.")]
[StringLength(3, ErrorMessage = "Sales group cannot exceed 3 characters.")]
public string SalesGroup { get; set; }
[StringLength(255, ErrorMessage = "Sales Office Description cannot exceed 255 characters")]
public string? SalesOfficeDescription { get; set; }
[Required(ErrorMessage = "Sales group description is required.")]
[StringLength(20, ErrorMessage = "Sales group description cannot exceed 20 characters.")]
public string SalesGroupDescription { get; set; }
[Required(ErrorMessage = "Sales Group is required")]
[StringLength(3, MinimumLength = 1, ErrorMessage = "Sales Group must be between 1 and 3 characters")]
public string SalesGroup { get; set; } = string.Empty;
[Required(ErrorMessage = "Customer group is required.")]
[StringLength(2, ErrorMessage = "Customer group cannot exceed 2 characters.")]
public string CustomerGroup { get; set; }
[Required(ErrorMessage = "Customer Group is required")]
[StringLength(2, MinimumLength = 1, ErrorMessage = "Customer Group must be between 1 and 2 characters")]
public string CustomerGroup { get; set; } = string.Empty;
[Required(ErrorMessage = "Customer group description is required.")]
[StringLength(20, ErrorMessage = "Customer group description cannot exceed 20 characters.")]
public string CustomerGroupDescription { get; set; }
[Required(ErrorMessage = "Status is required")]
[StringLength(1, MinimumLength = 1, ErrorMessage = "Status must be exactly 1 character")]
public string Status { get; set; } = string.Empty;
[Required(ErrorMessage = "Customer price group is required.")]
[StringLength(2, ErrorMessage = "Customer price group cannot exceed 2 characters.")]
public string CustomerPriceGroup { get; set; }
[Required(ErrorMessage = "Payment Terms are required")]
[StringLength(4, MinimumLength = 1, ErrorMessage = "Payment Terms must be between 1 and 4 characters")]
public string PaymentTerms { get; set; } = string.Empty;
[Required(ErrorMessage = "Customer price group description is required.")]
[StringLength(20, ErrorMessage = "Customer price group description cannot exceed 20 characters.")]
public string CustomerPriceGroupDescription { get; set; }
[Required(ErrorMessage = "Search Term is required")]
[StringLength(20, ErrorMessage = "Search Term cannot exceed 20 characters")]
public string SearchTerm { get; set; } = string.Empty;
[Required(ErrorMessage = "Status code is required.")]
[StringLength(1, ErrorMessage = "Status code cannot exceed 1 character.")]
public string StatusCode { get; set; }
[Required(ErrorMessage = "Region is required")]
[StringLength(3, MinimumLength = 1, ErrorMessage = "Region must be between 1 and 3 characters")]
public string Region { get; set; } = string.Empty;
[Required(ErrorMessage = "Status description is required.")]
[StringLength(30, ErrorMessage = "Status description cannot exceed 30 characters.")]
public string StatusDescription { get; set; }
[Required(ErrorMessage = "Region Name is required")]
[StringLength(40, ErrorMessage = "Region Name cannot exceed 40 characters")]
public string RegionName { get; set; } = string.Empty;
[Required(ErrorMessage = "Payment terms is required.")]
[StringLength(4, ErrorMessage = "Payment terms cannot exceed 4 characters.")]
public string PaymentTerms { get; set; }
[Required(ErrorMessage = "Area is required")]
[StringLength(10, MinimumLength = 1, ErrorMessage = "Area must be between 1 and 10 characters")]
public string Area { get; set; } = string.Empty;
[Required(ErrorMessage = "Payment terms description is required.")]
public string PaymentTermsDescription { get; set; }
[Required(ErrorMessage = "Area Name is required")]
[StringLength(40, ErrorMessage = "Area Name cannot exceed 40 characters")]
public string AreaName { get; set; } = string.Empty;
[Required(ErrorMessage = "Search term is required.")]
[StringLength(20, ErrorMessage = "Search term cannot exceed 20 characters.")]
public string SearchTerm { get; set; }
[Required(ErrorMessage = "Sales Unit is required")]
[StringLength(3, MinimumLength = 1, ErrorMessage = "Sales Unit must be between 1 and 3 characters")]
public string SalesUnit { get; set; } = string.Empty;
[Required(ErrorMessage = "Area/Region is required.")]
[StringLength(3, ErrorMessage = "Area/Region cannot exceed 3 characters.")]
public string AreaRegion { get; set; }
[Required(ErrorMessage = "Sales Unit Name is required")]
[StringLength(30, ErrorMessage = "Sales Unit Name cannot exceed 30 characters")]
public string SalesUnitName { get; set; } = string.Empty;
[Required(ErrorMessage = "Area/Region description is required.")]
[StringLength(40, ErrorMessage = "Area/Region description cannot exceed 40 characters.")]
public string AreaRegionDescription { get; set; }
[Required(ErrorMessage = "Territory is required")]
[StringLength(3, MinimumLength = 1, ErrorMessage = "Territory must be between 1 and 3 characters")]
public string Territory { get; set; } = string.Empty;
[Required(ErrorMessage = "Sales Unit/Area-AV is required.")]
[StringLength(10, ErrorMessage = "Sales Unit/Area-AV cannot exceed 10 characters.")]
public string SalesUnitAreaAV { get; set; }
[Required(ErrorMessage = "Territory Name is required")]
[StringLength(20, ErrorMessage = "Territory Name cannot exceed 20 characters")]
public string TerritoryName { get; set; } = string.Empty;
[Required(ErrorMessage = "Sales Unit/Area-AV description is required.")]
[StringLength(40, ErrorMessage = "Sales Unit/Area-AV description cannot exceed 40 characters.")]
public string SalesUnitAreaAVDescription { get; set; }
[Required(ErrorMessage = "Plant is required")]
[StringLength(4, MinimumLength = 1, ErrorMessage = "Plant must be between 1 and 4 characters")]
public string Plant { get; set; } = string.Empty;
[Required(ErrorMessage = "Territory is required.")]
[StringLength(3, ErrorMessage = "Territory cannot exceed 3 characters.")]
public string Territory { get; set; }
[Required(ErrorMessage = "Plant Name is required")]
[StringLength(30, ErrorMessage = "Plant Name cannot exceed 30 characters")]
public string PlantName { get; set; } = string.Empty;
[Required(ErrorMessage = "Territory name is required.")]
[StringLength(20, ErrorMessage = "Territory name cannot exceed 20 characters.")]
public string TerritoryName { get; set; }
[Required(ErrorMessage = "Plant is required.")]
[StringLength(4, ErrorMessage = "Plant cannot exceed 4 characters.")]
public string Plant { get; set; }
[Required(ErrorMessage = "Plant name is required.")]
[StringLength(30, ErrorMessage = "Plant name cannot exceed 30 characters.")]
public string PlantName { get; set; }
}
public class CustomerByCompanyCodeRequest
{
[Required(ErrorMessage = "Customer Number is required")]

View File

@ -0,0 +1,116 @@
using System.ComponentModel.DataAnnotations;
namespace OnlineSalesAutoCrop.CoreAPI.Models.Requests.Integrations;
public class EmployeeIntegrationRequest
{
[Required(ErrorMessage = "Employee vendor code is required.")]
[StringLength(10, ErrorMessage = "Employee vendor code cannot exceed 10 characters.")]
public string EmployeeVendorCode { get; set; }
[Required(ErrorMessage = "Employee vendor name is required.")]
[StringLength(35, ErrorMessage = "Employee vendor name cannot exceed 35 characters.")]
public string EmployeeVendorName { get; set; }
[Required(ErrorMessage = "Designation is required.")]
[StringLength(4, ErrorMessage = "Designation cannot exceed 4 characters.")]
public string Designation { get; set; }
[Required(ErrorMessage = "Designation description is required.")]
[StringLength(30, ErrorMessage = "Designation description cannot exceed 30 characters.")]
public string DesignationDescription { get; set; }
[Required(ErrorMessage = "Mobile number is required.")]
[StringLength(31, ErrorMessage = "Mobile number cannot exceed 31 characters.")]
[Phone(ErrorMessage = "Mobile number is not a valid phone number.")]
public string MobileNo { get; set; }
[Required(ErrorMessage = "Email address is required.")]
[StringLength(241, ErrorMessage = "Email address cannot exceed 241 characters.")]
[EmailAddress(ErrorMessage = "Email address is not valid.")]
public string Mail { get; set; }
[Required(ErrorMessage = "Company code is required.")]
[StringLength(4, ErrorMessage = "Company code cannot exceed 4 characters.")]
public string CompanyCode { get; set; }
[Required(ErrorMessage = "Company name is required.")]
[StringLength(25, ErrorMessage = "Company name cannot exceed 25 characters.")]
public string CompanyName { get; set; }
[Required(ErrorMessage = "Sales org is required.")]
[StringLength(4, ErrorMessage = "Sales org cannot exceed 4 characters.")]
public string SalesOrg { get; set; }
[Required(ErrorMessage = "Sales org description is required.")]
[StringLength(40, ErrorMessage = "Sales org description cannot exceed 40 characters.")]
public string SalesOrgDescription { get; set; }
[Required(ErrorMessage = "Distribution channel is required.")]
[StringLength(2, ErrorMessage = "Distribution channel cannot exceed 2 characters.")]
public string DistChannel { get; set; }
[Required(ErrorMessage = "Distribution channel description is required.")]
[StringLength(20, ErrorMessage = "Distribution channel description cannot exceed 20 characters.")]
public string DistChannelDescription { get; set; }
[Required(ErrorMessage = "Division is required.")]
[StringLength(2, ErrorMessage = "Division cannot exceed 2 characters.")]
public string Division { get; set; }
[Required(ErrorMessage = "Division description is required.")]
[StringLength(20, ErrorMessage = "Division description cannot exceed 20 characters.")]
public string DivisionDescription { get; set; }
[Required(ErrorMessage = "Region/Area code is required.")]
[StringLength(3, ErrorMessage = "Region/Area code cannot exceed 3 characters.")]
public string RegionAreaCode { get; set; }
[Required(ErrorMessage = "Region/Area description is required.")]
[StringLength(40, ErrorMessage = "Region/Area description cannot exceed 40 characters.")]
public string RegionAreaDescription { get; set; }
[Required(ErrorMessage = "Area-AV/Sales unit code is required.")]
[StringLength(10, ErrorMessage = "Area-AV/Sales unit code cannot exceed 10 characters.")]
public string AreaAVSalesUnitCode { get; set; }
[Required(ErrorMessage = "Area-AV/Sales unit description is required.")]
[StringLength(40, ErrorMessage = "Area-AV/Sales unit description cannot exceed 40 characters.")]
public string AreaAVSalesUnitDescription { get; set; }
[Required(ErrorMessage = "Territory is required.")]
[StringLength(3, ErrorMessage = "Territory cannot exceed 3 characters.")]
public string Territory { get; set; }
[Required(ErrorMessage = "Territory description is required.")]
[StringLength(20, ErrorMessage = "Territory description cannot exceed 20 characters.")]
public string TerritoryDescription { get; set; }
[Required(ErrorMessage = "Plant is required.")]
[StringLength(4, ErrorMessage = "Plant cannot exceed 4 characters.")]
public string Plant { get; set; }
[Required(ErrorMessage = "Plant description is required.")]
[StringLength(30, ErrorMessage = "Plant description cannot exceed 30 characters.")]
public string PlantDescription { get; set; }
[Required(ErrorMessage = "Status is required.")]
[StringLength(1, ErrorMessage = "Status cannot exceed 1 character.")]
public string Status { get; set; }
[Required(ErrorMessage = "Status description is required.")]
[StringLength(30, ErrorMessage = "Status description cannot exceed 30 characters.")]
public string StatusDescription { get; set; }
}
public class EmployeeIntegrationByComapanyRequest
{
[Required(ErrorMessage = "Employee vendor code is required.")]
[StringLength(10, ErrorMessage = "Employee vendor code cannot exceed 10 characters.")]
public string EmployeeVendorCode { get; set; }
[Required(ErrorMessage = "Company code is required.")]
[StringLength(4, ErrorMessage = "Company code cannot exceed 4 characters.")]
public string CompanyCode { get; set; }
}

View File

@ -14,9 +14,9 @@ public class IntegrationLoginRequest
[Required, NotNull, StringLength(maximumLength: 150, MinimumLength = 5, ErrorMessage = "Password must be between 1 and 30 characters.")]
public string Password { get; set; }
public string RefreshToken { get; set; }
}
public class IntegrationRefreshTokenRequest
{
public string RefreshToken { get; set; }
@ -35,7 +35,7 @@ public class RevokedRefreshTokenRequest
public class GenerateRefreshTokenRequest
{
public User User { get; set; }
public int UserId { get; set; }
public string IpAddress { get; set; }
public string RawRefreshToken { get; set; }
}

View File

@ -0,0 +1,73 @@
using System.ComponentModel.DataAnnotations;
namespace OnlineSalesAutoCrop.CoreAPI.Models.Requests.Integrations;
public class MaterialIntegrationRequest
{
[Required(ErrorMessage = "Material type is required.")]
[StringLength(4, ErrorMessage = "Material type cannot exceed 4 characters.")]
public string MaterialType { get; set; }
[Required(ErrorMessage = "Material type description is required.")]
[StringLength(25, ErrorMessage = "Material type description cannot exceed 25 characters.")]
public string MaterialTypeDescription { get; set; }
[Required(ErrorMessage = "Material code is required.")]
[StringLength(10, ErrorMessage = "Material code cannot exceed 10 characters.")]
public string MaterialCode { get; set; }
[Required(ErrorMessage = "Material description is required.")]
[StringLength(40, ErrorMessage = "Material description cannot exceed 40 characters.")]
public string MaterialDescription { get; set; }
[Required(ErrorMessage = "Material group code is required.")]
[StringLength(9, ErrorMessage = "Material group code cannot exceed 9 characters.")]
public string MaterialGroupCode { get; set; }
[Required(ErrorMessage = "Material group description is required.")]
[StringLength(20, ErrorMessage = "Material group description cannot exceed 20 characters.")]
public string MaterialGroupDescription { get; set; }
[Required(ErrorMessage = "Base unit of measure is required.")]
[StringLength(3, ErrorMessage = "Base unit of measure cannot exceed 3 characters.")]
public string BaseUnitOfMeasure { get; set; }
[Required(ErrorMessage = "Sales unit of measure is required.")]
[StringLength(3, ErrorMessage = "Sales unit of measure cannot exceed 3 characters.")]
public string SalesUnitOfMeasure { get; set; }
[Required(ErrorMessage = "Unit conversion with base UoM is required.")]
[Range(0.001, 999.999, ErrorMessage = "Unit conversion must be between 0.001 and 999.999.")]
public decimal UnitConversionWithBaseUoM { get; set; }
[Required(ErrorMessage = "Plant code is required.")]
[StringLength(4, ErrorMessage = "Plant code cannot exceed 4 characters.")]
public string PlantCode { get; set; }
[Required(ErrorMessage = "Plant description is required.")]
[StringLength(30, ErrorMessage = "Plant description cannot exceed 30 characters.")]
public string PlantDescription { get; set; }
[Required(ErrorMessage = "Storage location code is required.")]
[StringLength(4, ErrorMessage = "Storage location code cannot exceed 4 characters.")]
public string StorageLocationCode { get; set; }
[Required(ErrorMessage = "Storage location description is required.")]
[StringLength(16, ErrorMessage = "Storage location description cannot exceed 16 characters.")]
public string StorageLocationDescription { get; set; }
[Required(ErrorMessage = "Sales Organization code is required.")]
[StringLength(4, ErrorMessage = "Sales Organization code cannot exceed 4 characters.")]
public string SalesOrganization { get; set; }
[Required(ErrorMessage = "Sales Organization Description is required.")]
[StringLength(16, ErrorMessage = "Sales Organization Description cannot exceed 16 characters.")]
public string SalesOrganizationDescription { get; set; }
}
public class GetMaterialByCodeRequest
{
[Required(ErrorMessage = "Material code is required.")]
[StringLength(10, ErrorMessage = "Material code cannot exceed 10 characters.")]
public string MaterialCode { get; set; }
}

View File

@ -2,7 +2,9 @@
public class CustomerIntegrationResponse : ResponseBase
{
public string CustomerNumber { get; set; }
public string CompanyCode { get; set; }
public bool IsUpdated { get; set; }
}
public class CustomerByCompanyCodeResponse : ResponseBase
@ -10,53 +12,37 @@ public class CustomerByCompanyCodeResponse : ResponseBase
public int CustomerId { get; set; }
public string CustomerNumber { get; set; }
public string CustomerName { get; set; }
public string AccountGroup { get; set; }
public string AccountGroupDescription { get; set; }
public string CompanyCode { get; set; }
public string CompanyCodeDescription { get; set; }
public string SalesOrganization { get; set; }
public string SalesOrganizationDescription { get; set; }
public string DistributionChannel { get; set; }
public string DistributionChannelDescription { get; set; }
public string Division { get; set; }
public string DivisionDescription { get; set; }
public string MobileNumber { get; set; }
public string EmailAddress { get; set; }
public string BusinessTaxNumber { get; set; }
public decimal? CreditLimit { get; set; }
public string SalesOffice { get; set; }
public string SalesOfficeDescription { get; set; }
public decimal CreditLimit { get; set; }
public string SalesGroup { get; set; }
public string SalesGroupDescription { get; set; }
public string CustomerGroup { get; set; }
public string Status { get; set; }
public string CustomerGroupDescription { get; set; }
public string CustomerPriceGroup { get; set; }
public string CustomerPriceGroupDescription { get; set; }
public string StatusCode { get; set; }
public string StatusDescription { get; set; }
public string PaymentTerms { get; set; }
public string PaymentTermsDescription { get; set; }
public string SearchTerm { get; set; }
public string Region { get; set; }
public string RegionName { get; set; }
public string Area { get; set; }
public string AreaName { get; set; }
public string SalesUnit { get; set; }
public string SalesUnitName { get; set; }
public string AreaRegion { get; set; }
public string AreaRegionDescription { get; set; }
public string SalesUnitAreaAV { get; set; }
public string SalesUnitAreaAVDescription { get; set; }
public string Territory { get; set; }
public string TerritoryName { get; set; }
public string Plant { get; set; }
public string PlantName { get; set; }
}

View File

@ -0,0 +1,39 @@
namespace OnlineSalesAutoCrop.CoreAPI.Models.Responses.Integrations;
public class EmployeeIntegrationResponse : ResponseBase
{
public int EmployeeId { get; set; }
public string EmployeeVendorCode { get; set; }
public string EmployeeVendorName { get; set; }
public string Designation { get; set; }
public string DesignationDescription { get; set; }
public string MobileNo { get; set; }
public string Mail { get; set; }
public string CompanyCode { get; set; }
public string CompanyName { get; set; }
public string SalesOrg { get; set; }
public string SalesOrgDescription { get; set; }
public string DistChannel { get; set; }
public string DistChannelDescription { get; set; }
public string Division { get; set; }
public string DivisionDescription { get; set; }
public string RegionAreaCode { get; set; }
public string RegionAreaDescription { get; set; }
public string AreaAVSalesUnitCode { get; set; }
public string AreaAVSalesUnitDescription { get; set; }
public string Territory { get; set; }
public string TerritoryDescription { get; set; }
public string Plant { 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 CompanyCode { get; set; }
public bool IsUpdated { get; set; }
}

View File

@ -14,10 +14,16 @@ public class IntegrationLoginResponse : ResponseBase
public DateTime AccessTokenExpiry { get; set; }
}
public class IntegrationRrefreshTokenResponse : ResponseBase
{
public string AccessToken { get; set; } = string.Empty;
public string RefreshToken { get; set; } = string.Empty;
}
public class RefreshTokenResponse : ResponseBase
{
public string UserId { get; set; }
public int UserId { get; set; }
public string TokenHash { get; set; }
public string IpAddress { get; set; }
public DateTime ExpiredAt { get; set; }
@ -31,3 +37,12 @@ public class GenerateRefreshTokenResponse : ResponseBase
public string RefreshToken { get; set; }
public DateTime ExpireTime { get; set; }
}
public class UserByRefreshTokenResponse : ResponseBase
{
public int UserId { get; set; }
public string LoginId { get; set; }
public string EmailAddress { get; set; }
public string AuthKey { get; set; }
public bool IsActive { set; get; }
}

View File

@ -0,0 +1,29 @@
using System.ComponentModel.DataAnnotations;
namespace OnlineSalesAutoCrop.CoreAPI.Models.Responses.Integrations;
public class MaterialIntegrationResponse : ResponseBase
{
public int MeterialId { get; set; }
public string MaterialType { get; set; }
public string MaterialTypeDescription { get; set; }
public string MaterialCode { get; set; }
public string MaterialDescription { get; set; }
public string MaterialGroupCode { get; set; }
public string MaterialGroupDescription { get; set; }
public string BaseUnitOfMeasure { get; set; }
public string SalesUnitOfMeasure { get; set; }
public decimal UnitConversionWithBaseUoM { get; set; }
public string PlantCode { get; set; }
public string PlantDescription { get; set; }
public string StorageLocationCode { get; set; }
public string StorageLocationDescription { get; set; }
public string SalesOrganization { get; set; }
public string SalesOrganizationDescription { get; set; }
}
public class MaterialIntegrationReqResponse : ResponseBase
{
public string MaterialCode { get; set; }
public bool IsUpdated { get; set; }
}

View File

@ -6,9 +6,7 @@ namespace OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Auth;
public interface IRefreshTokenService
{
Task<RefreshTokenResponse?> GetByTokenHashAsync(string tokenHash);
Task<bool> AddAsync(InsertRefreshTokenRequest refreshToken);
Task<bool> RevokeAsync(RevokedRefreshTokenRequest token);
Task<bool> RevokeAllForUserAsync(int userId);
Task<GenerateRefreshTokenResponse> GenerateRefreshToken(GenerateRefreshTokenRequest request);
Task<GenerateRefreshTokenResponse> GenerateRefreshTokenByUserAsync(GenerateRefreshTokenRequest request);
Task<string> GenerateRefreshTokenAsync(string refreshToken, string ipAddress);
Task<UserByRefreshTokenResponse> GetUserByRefreshTokenAsync(string refreshToken);
}

View File

@ -7,6 +7,15 @@ namespace OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Integrations;
public interface IIntegrationService
{
Task<bool> UpsertCustomerAsync(CustomerIntegrationRequest request);
//Customer
Task<CustomerIntegrationResponse> UpsertCustomerAsync(CustomerIntegrationRequest request);
Task<CustomerByCompanyCodeResponse> GetCustomerByCompanyCodeAsync(CustomerByCompanyCodeRequest request);
//Employee
Task<EmployeeIntegrationReqResponse> UpsertEmployeeAsync(EmployeeIntegrationRequest request);
Task<EmployeeIntegrationResponse> GetEmployeeBySalesOrgAsync(EmployeeIntegrationByComapanyRequest request);
//Meterial
Task<MaterialIntegrationReqResponse > UpsertMaterialAsync(MaterialIntegrationRequest request);
Task<MaterialIntegrationResponse> GetMaterialByCodeAsync(GetMaterialByCodeRequest request);
}

View File

@ -3,7 +3,6 @@ using Ease.NetCore.DataAccess.SQL;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Options;
using OnlineSalesAutoCrop.CoreAPI.Models.Global;
using OnlineSalesAutoCrop.CoreAPI.Models.Objects.Systems;
using OnlineSalesAutoCrop.CoreAPI.Models.Requests.Integrations;
using OnlineSalesAutoCrop.CoreAPI.Models.Responses.Integrations;
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Auth;
@ -23,26 +22,118 @@ public class RefreshTokenService : IRefreshTokenService
_settings = settings.Value;
}
public async Task<bool> AddAsync(InsertRefreshTokenRequest refreshToken)
public async Task<UserByRefreshTokenResponse> GetUserByRefreshTokenAsync(string refreshToken)
{
bool returnValue = false;
UserByRefreshTokenResponse response = new();
try
{
using TransactionContext tc = await TransactionContext.BeginAsync(_settings.DefaultConnection.ConnectionNode, true);
AddAsync(tc, refreshToken);
using TransactionContext tc = await TransactionContext.BeginAsync(_settings.DefaultConnection.ConnectionNode);
try
{
response = await GetUserByRefreshTokenAsync(tc, refreshToken);
tc.End();
}
catch (Exception ie)
{
tc?.HandleError();
throw DBCustomError.GenerateCustomError(ie);
}
}
catch (Exception e)
{
throw new InvalidOperationException(e.Message, e);
}
return returnValue;
return response;
}
private bool AddAsync( TransactionContext tc, InsertRefreshTokenRequest refreshToken)
public async Task<GenerateRefreshTokenResponse> GenerateRefreshTokenByUserAsync(GenerateRefreshTokenRequest request)
{
GenerateRefreshTokenResponse refreshTokenResponse = new();
try
{
using TransactionContext tc = await TransactionContext.BeginAsync(_settings.DefaultConnection.ConnectionNode, true);
try
{
// Rotate: revoke old token, issue new one
RevokeRefreshTokenByUserIdAsync(tc, request.UserId);
refreshTokenResponse= await IssueTokensAsync(tc,request.UserId, request.IpAddress);
tc.End();
}
catch (Exception ie)
{
tc?.HandleError();
throw DBCustomError.GenerateCustomError(ie);
}
}
catch (Exception e)
{
throw new InvalidOperationException(e.Message, e);
}
return refreshTokenResponse;
}
public async Task<string> GenerateRefreshTokenAsync(string refreshToken, string ipAddress)
{
string refreshTokenResponse = string.Empty;
try
{
using TransactionContext tc = await TransactionContext.BeginAsync(_settings.DefaultConnection.ConnectionNode, true);
try
{
bool isValid = IsValidRefreshTokenAsync(tc, refreshToken);
if(string.IsNullOrEmpty(refreshToken) && !isValid)
{
throw new Exception($"Refresh token has expired or been revoked- {refreshToken}");
}
var storedToken = await GetByTokenHashAsync(tc, refreshToken);
RevokeRefreshTokenByUserIdAsync(tc, storedToken.UserId);
var result = await IssueTokensAsync(tc, storedToken.UserId, ipAddress);
refreshTokenResponse = result.RefreshToken;
tc.End();
}
catch (Exception ie)
{
tc?.HandleError();
throw DBCustomError.GenerateCustomError(ie);
}
}
catch (Exception e)
{
throw new InvalidOperationException(e.Message, e);
}
return refreshTokenResponse;
}
#region Private Methods
// ----- private helpers -----
private bool IsValidRefreshTokenAsync(TransactionContext tc, string refreshToken )
{
try
{
string sql = SQLParser.MakeSQL("Select Count(1) FROM RefreshTokens where TokenHash = %s AND RevokedAt is null", refreshToken);
var returnValue = tc.ExecuteScalar(sql);
return Convert.ToInt32(returnValue) > 0 ? true : false;
}
catch(Exception)
{
throw;
}
}
private bool AddAsync(TransactionContext tc, InsertRefreshTokenRequest refreshToken)
{
bool returnValue = false;
@ -68,33 +159,6 @@ public class RefreshTokenService : IRefreshTokenService
return returnValue;
}
public async Task<RefreshTokenResponse> GetByTokenHashAsync(string tokenHash)
{
RefreshTokenResponse response = new();
try
{
using TransactionContext tc = await TransactionContext.BeginAsync(_settings.DefaultConnection.ConnectionNode);
try
{
await GetByTokenHashAsync(tc, tokenHash);
tc.End();
}
catch (Exception ie)
{
tc?.HandleError();
throw DBCustomError.GenerateCustomError(ie);
}
}
catch (Exception e)
{
throw new InvalidOperationException(e.Message, e);
}
return response;
}
private async Task<RefreshTokenResponse> GetByTokenHashAsync(TransactionContext tc, string tokenHash)
{
RefreshTokenResponse response = new();
@ -108,7 +172,7 @@ public class RefreshTokenService : IRefreshTokenService
{
if (dr.Read())
{
response.UserId = dr.GetString(0);
response.UserId = dr.GetInt32(0);
response.TokenHash = dr.GetString(1);
response.IpAddress = dr.GetString(2);
response.ExpiredAt = dr.GetDateTime(3);
@ -125,30 +189,19 @@ public class RefreshTokenService : IRefreshTokenService
return response;
}
public async Task<bool> RevokeAllForUserAsync(int userId)
private bool RevokeRefreshTokenByUserIdAsync(TransactionContext tc, int userId)
{
bool returnValue = false;
try
{
using TransactionContext tc = await TransactionContext.BeginAsync(_settings.DefaultConnection.ConnectionNode, true);
try
{
SqlParameter[] p =
[
SqlHelperExtension.CreateInParam(pName: "@UserId", pType: SqlDbType.Int, pValue: userId)
];
_ = await tc.ExecuteNonQuerySpAsync(spName: "dbo.RevokedAllRefreshToken", parameterValues: p);
_ = tc.ExecuteNonQuerySp(spName: "dbo.RevokedAllRefreshTokenByUserId", parameterValues: p);
returnValue = true;
tc.End();
}
catch (Exception ie)
{
tc?.HandleError();
throw DBCustomError.GenerateCustomError(ie);
}
}
catch (Exception e)
{
@ -158,81 +211,26 @@ public class RefreshTokenService : IRefreshTokenService
return returnValue;
}
public async Task<bool> RevokeAsync(RevokedRefreshTokenRequest token)
private async Task<UserByRefreshTokenResponse> GetUserByRefreshTokenAsync(TransactionContext tc, string refreshToken)
{
bool returnValue = false;
try
{
using TransactionContext tc = await TransactionContext.BeginAsync(_settings.DefaultConnection.ConnectionNode, true);
try
{
returnValue = RevokeAsync(tc, token);
tc.End();
}
catch (Exception ie)
{
tc?.HandleError();
throw DBCustomError.GenerateCustomError(ie);
}
}
catch (Exception e)
{
throw new InvalidOperationException(e.Message, e);
}
return returnValue;
}
private bool RevokeAsync(TransactionContext tc, RevokedRefreshTokenRequest token)
{
bool returnValue = false;
UserByRefreshTokenResponse response = new();
try
{
SqlParameter[] p =
[
SqlHelperExtension.CreateInParam(pName: "@RefreshToken", pType: SqlDbType.NVarChar, pValue: token.RefreshToken)
SqlHelperExtension.CreateInParam(pName: "@RefreshToken", pType: SqlDbType.VarChar, pValue: refreshToken),
];
_ = tc.ExecuteNonQuerySp(spName: "dbo.RevokedAllRefreshToken", parameterValues: p);
returnValue = true;
using (IDataReader dr = await tc.ExecuteReaderSpAsync("dbo.GetUserByRefreshToken", parameterValues: p))
{
if (dr.Read())
{
response.UserId = dr.GetInt32(0);
response.LoginId = dr.GetString(1);
response.EmailAddress = dr.IsDBNull(2) ? string.Empty : dr.GetString(2);
response.AuthKey = dr.IsDBNull(3) ? string.Empty : dr.GetString(3);
response.IsActive = dr.IsDBNull(4) ? true : false;
}
catch (Exception e)
{
throw new InvalidOperationException(e.Message, e);
}
return returnValue;
}
public async Task<GenerateRefreshTokenResponse> GenerateRefreshToken(GenerateRefreshTokenRequest request)
{
GenerateRefreshTokenResponse refreshTokenResponse = new();
try
{
using TransactionContext tc = await TransactionContext.BeginAsync(_settings.DefaultConnection.ConnectionNode, true);
try
{
var tokenHash = HashToken(request.RawRefreshToken);
var storedToken = await GetByTokenHashAsync(tc, tokenHash);
if (storedToken.UserId is not null && !storedToken.IsActive)
throw new UnauthorizedAccessException("Refresh token has expired or been revoked.");
// Rotate: revoke old token, issue new one
RevokeAsync(tc,new RevokedRefreshTokenRequest() { RefreshToken = storedToken.TokenHash });
refreshTokenResponse= await IssueTokensAsync(tc,request.User, request.IpAddress);
tc.End();
}
catch (Exception ie)
{
tc?.HandleError();
throw DBCustomError.GenerateCustomError(ie);
dr.Close();
}
}
catch (Exception e)
@ -240,19 +238,17 @@ public class RefreshTokenService : IRefreshTokenService
throw new InvalidOperationException(e.Message, e);
}
return refreshTokenResponse;
return response;
}
// ----- private helpers -----
private async Task<GenerateRefreshTokenResponse> IssueTokensAsync(TransactionContext tc, User user, string ipAddress)
private async Task<GenerateRefreshTokenResponse> IssueTokensAsync(TransactionContext tc, int userId, string ipAddress)
{
string rawRefreshToken = GenerateRowToken();
string tokenHash = HashToken(rawRefreshToken);
var refreshToken = new InsertRefreshTokenRequest
{
UserId = user.UserId,
TokenHash = HashToken(rawRefreshToken),
UserId = userId,
TokenHash = tokenHash,
IpAddress = ipAddress,
CreatedAt = DateTime.UtcNow,
ExpiresAt = DateTime.UtcNow.AddDays(_settings.RefreshTokenDuration)
@ -262,7 +258,7 @@ public class RefreshTokenService : IRefreshTokenService
return new GenerateRefreshTokenResponse
{
RefreshToken = rawRefreshToken,
RefreshToken = tokenHash,
ExpireTime = DateTime.UtcNow.AddMinutes(_settings.RefreshTokenDuration)
};
}
@ -280,4 +276,6 @@ public class RefreshTokenService : IRefreshTokenService
rng.GetBytes(bytes);
return Convert.ToBase64String(bytes);
}
#endregion
}

View File

@ -8,8 +8,6 @@ using OnlineSalesAutoCrop.CoreAPI.Models.Responses.Integrations;
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Integrations;
using System;
using System.Data;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace OnlineSalesAutoCrop.CoreAPI.Services.Services.Integrations;
@ -23,6 +21,7 @@ public class IntegrationService : IIntegrationService
_settings = options.Value;
}
public async Task<CustomerByCompanyCodeResponse> GetCustomerByCompanyCodeAsync(CustomerByCompanyCodeRequest request)
{
CustomerByCompanyCodeResponse response = new();
@ -49,13 +48,12 @@ public class IntegrationService : IIntegrationService
return response;
}
public async Task<bool> UpsertCustomerAsync(CustomerIntegrationRequest request)
public async Task<CustomerIntegrationResponse> UpsertCustomerAsync(CustomerIntegrationRequest request)
{
bool response = false;
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,12 +61,19 @@ public class IntegrationService : IIntegrationService
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)
@ -86,16 +91,155 @@ public class IntegrationService : IIntegrationService
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 = false;
}
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: "@CustomerNumber", pType: SqlDbType.NVarChar,pValue: request.CustomerNumber ),
SqlHelperExtension.CreateInParam(pName: "@CompanyCode", pType: SqlDbType.NVarChar,pValue: request.CompanyCode ),
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))
@ -104,49 +248,515 @@ public class IntegrationService : IIntegrationService
{
response = new CustomerByCompanyCodeResponse()
{
CustomerNumber = dr["CustomerNumber"].ToString(),
CustomerName = dr["CustomerName"].ToString(),
AccountGroup = dr["AccountGroup"].ToString(),
AccountGroupDescription = dr["AccountGroupDescription"].ToString(),
CompanyCode = dr["CompanyCode"].ToString(),
CompanyCodeDescription = dr["CompanyCodeDescription"].ToString(),
SalesOrganization = dr["SalesOrganization"].ToString(),
SalesOrganizationDescription = dr["SalesOrganizationDescription"].ToString(),
DistributionChannel = dr["DistributionChannel"].ToString(),
DistributionChannelDescription = dr["DistributionChannelDescription"].ToString(),
Division = dr["Division"].ToString(),
DivisionDescription = dr["DivisionDescription"].ToString(),
MobileNumber = dr["MobileNumber"].ToString(),
EmailAddress = dr["EmailAddress"].ToString(),
BusinessTaxNumber = dr["BusinessTaxNumber"].ToString(),
CreditLimit = dr["CreditLimit"] == DBNull.Value ? 0 : Convert.ToDecimal(dr["CreditLimit"]),
SalesOffice = dr["SalesOffice"].ToString(),
SalesOfficeDescription = dr["SalesOfficeDescription"].ToString(),
SalesGroup = dr["SalesGroup"].ToString(),
CustomerGroup = dr["CustomerGroup"].ToString(),
Status = dr["Status"].ToString(),
PaymentTerms = dr["PaymentTerms"].ToString(),
SearchTerm = dr["SearchTerm"].ToString(),
Region = dr["Region"].ToString(),
RegionName = dr["RegionName"].ToString(),
Area = dr["Area"].ToString(),
AreaName = dr["AreaName"].ToString(),
SalesUnit = dr["SalesUnit"].ToString(),
SalesUnitName = dr["SalesUnitName"].ToString(),
Territory = dr["Territory"].ToString(),
TerritoryName = dr["TerritoryName"].ToString(),
Plant = dr["Plant"].ToString(),
PlantName = dr["PlantName"].ToString()
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)
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
}

View File

@ -3,8 +3,6 @@ using Ease.NetCore.DataAccess.SQL;
using Ease.NetCore.Utility;
using OnlineSalesAutoCrop.CoreAPI.Models;
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.Requests.Systems;
using OnlineSalesAutoCrop.CoreAPI.Models.Responses.Systems;

View File

@ -1,5 +0,0 @@
{
"version": 1,
"isRoot": true,
"tools": {}
}

View File

@ -6,7 +6,6 @@ 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;
@ -38,8 +37,8 @@ namespace OnlineSalesAutoCrop.CoreAPI.Controllers.IntegretionApi
/// <remarks>
/// </remarks>
/// <param name="request"></param>
/// <returns>if created return 201 or if updated return 204 true</returns>
[HttpGet("Customers")]
/// <returns>if created return 201 or if updated return 200 true</returns>
[HttpPost("Customers")]
[IgnoreAntiforgeryToken]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IntegrationLoginResponse))]
public async Task<IActionResult> UpsertCustomers(CustomerIntegrationRequest request)
@ -47,8 +46,8 @@ namespace OnlineSalesAutoCrop.CoreAPI.Controllers.IntegretionApi
CustomerIntegrationResponse response = new CustomerIntegrationResponse();
try
{
bool result = await _integrationService.UpsertCustomerAsync(request);
if (result)
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;
@ -57,8 +56,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)
@ -70,5 +69,85 @@ namespace OnlineSalesAutoCrop.CoreAPI.Controllers.IntegretionApi
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 200 true</returns>
[HttpPost("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.CompanyCode}");
response.ReturnStatus = StatusCodes.Status201Created;
return StatusCode(StatusCodes.Status201Created, response);
}
else
{
response.ReturnMessage.Add($"Employee Updated Successfully for EmployeeVendorName :{request.EmployeeVendorName} & SalesOrgCode:{request.CompanyCode}");
response.ReturnStatus = StatusCodes.Status200OK;
return StatusCode(StatusCodes.Status200OK, response);
}
}
catch (Exception ex)
{
string msg = $"Exception Occur in Employee Operation {request?.EmployeeVendorName}~{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);
}
}
/// <summary>
/// Insert or Update Material for SAP
/// </summary>
/// <remarks>
/// </remarks>
/// <param name="request"></param>
/// <returns>if created return 201 or if updated return 200 true</returns>
[HttpPost("Materials")]
[IgnoreAntiforgeryToken]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(MaterialIntegrationReqResponse))]
[ProducesResponseType(StatusCodes.Status201Created, Type = typeof(MaterialIntegrationReqResponse))]
public async Task<IActionResult> UpsertMeterial(MaterialIntegrationRequest request)
{
MaterialIntegrationReqResponse response = new MaterialIntegrationReqResponse();
try
{
response = await _integrationService.UpsertMaterialAsync(request);
if (!response.IsUpdated)
{
response.ReturnMessage.Add($"Material Created Successfully for MaterialCode :{request.MaterialCode} ");
response.ReturnStatus = StatusCodes.Status201Created;
return StatusCode(StatusCodes.Status201Created, response);
}
else
{
response.ReturnMessage.Add($"Material Updated Successfully for MaterialCode :{request.MaterialCode} ");
response.ReturnStatus = StatusCodes.Status200OK;
return StatusCode(StatusCodes.Status200OK, response);
}
}
catch (Exception ex)
{
string msg = $"Exception Occur in Material Operation {request?.MaterialCode}";
_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);
}
}
}
}

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<NameOfLastUsedPublishProfile>D:\Local\EaseBilling\Api\EaseO2C.CoreAPI\Properties\PublishProfiles\Windows.Publish.pubxml</NameOfLastUsedPublishProfile>
<NameOfLastUsedPublishProfile>D:\Local\OnlineSalesAutoCrop\Api\OnlineSalesAutoCrop.CoreAPI\Properties\PublishProfiles\FolderProfile.pubxml</NameOfLastUsedPublishProfile>
<ActiveDebugProfile>IIS Express</ActiveDebugProfile>
<Controller_SelectedScaffolderID>ApiControllerEmptyScaffolder</Controller_SelectedScaffolderID>
<Controller_SelectedScaffolderCategoryPath>root/Common/Api</Controller_SelectedScaffolderCategoryPath>