diff --git a/Api/OnlineSalesAutoCrop.CoreAPI.Models/Requests/Integrations/IntegrationMaterialFreeGoodsRequest.cs b/Api/OnlineSalesAutoCrop.CoreAPI.Models/Requests/Integrations/IntegrationMaterialFreeGoodsRequest.cs index 0319130..9ee11c8 100644 --- a/Api/OnlineSalesAutoCrop.CoreAPI.Models/Requests/Integrations/IntegrationMaterialFreeGoodsRequest.cs +++ b/Api/OnlineSalesAutoCrop.CoreAPI.Models/Requests/Integrations/IntegrationMaterialFreeGoodsRequest.cs @@ -17,9 +17,8 @@ public class IntegrationMaterialFreeGoodsRequest [StringLength(13, MinimumLength = 1, ErrorMessage = "CustomerNumber must be between 1 and 13 characters.")] public string? CustomerNumber { get; set; } // nullable - [Required(ErrorMessage = "CustomerPriceGroup is required.")] [StringLength(2, MinimumLength = 1, ErrorMessage = "CustomerPriceGroup must be between 1 and 2 characters.")] - public string CustomerPriceGroup { get; set; } + public string? CustomerPriceGroup { get; set; } [Required(ErrorMessage = "MaterialCode is required.")] [StringLength(10, MinimumLength = 1, ErrorMessage = "MaterialCode must be between 1 and 10 characters.")] @@ -66,9 +65,11 @@ public class GetMaterialFreeGoodsByFilterRequest [StringLength(2, MinimumLength = 1, ErrorMessage = "DistributionChannel must be between 1 and 2 characters.")] public string DistributionChannel { get; set; } - [Required(ErrorMessage = "CustomerPriceGroup is required.")] + [StringLength(13, MinimumLength = 1, ErrorMessage = "CustomerNumber must be between 1 and 13 characters.")] + public string? CustomerNumber { get; set; } // nullable + [StringLength(2, MinimumLength = 1, ErrorMessage = "CustomerPriceGroup must be between 1 and 2 characters.")] - public string CustomerPriceGroup { get; set; } + public string? CustomerPriceGroup { get; set; } [Required(ErrorMessage = "MaterialCode is required.")] [StringLength(10, MinimumLength = 1, ErrorMessage = "MaterialCode must be between 1 and 10 characters.")] diff --git a/Api/OnlineSalesAutoCrop.CoreAPI.Models/Requests/Integrations/IntegrationMaterialPriceRequest.cs b/Api/OnlineSalesAutoCrop.CoreAPI.Models/Requests/Integrations/IntegrationMaterialPriceRequest.cs index 2970822..34bc434 100644 --- a/Api/OnlineSalesAutoCrop.CoreAPI.Models/Requests/Integrations/IntegrationMaterialPriceRequest.cs +++ b/Api/OnlineSalesAutoCrop.CoreAPI.Models/Requests/Integrations/IntegrationMaterialPriceRequest.cs @@ -13,13 +13,11 @@ public class IntegrationMaterialPriceRequest [StringLength(2, ErrorMessage = "Distribution Channel cannot exceed 2 characters.")] public string DistributionChannel { get; set; } - [Required(ErrorMessage = "Customer Number is required.")] [StringLength(13, ErrorMessage = "Customer Number cannot exceed 13 characters.")] - public string CustomerNumber { get; set; } + public string? CustomerNumber { get; set; } - [Required(ErrorMessage = "Customer Group Code is required.")] [StringLength(10, ErrorMessage = "Customer Group Code cannot exceed 10 characters.")] - public string CustomerGroupCode { get; set; } + public string? CustomerGroupCode { get; set; } [Required(ErrorMessage = "Material Code is required.")] [StringLength(10, ErrorMessage = "Material Code cannot exceed 10 characters.")] @@ -59,6 +57,10 @@ public class IntegrationMaterialPriceRequest public class GetMaterialPriceByCodeRequest { + [Required(ErrorMessage = "Sales Org is required.")] + [StringLength(4, ErrorMessage = "Sales Org cannot exceed 4 characters.")] + public string SalesOrg { get; set; } + [Required(ErrorMessage = "Material Code is required.")] [StringLength(10, ErrorMessage = "Material Code cannot exceed 10 characters.")] public string MaterialCode { get; set; } @@ -66,4 +68,10 @@ public class GetMaterialPriceByCodeRequest [Required(ErrorMessage = "Condition Type is required.")] [StringLength(4, ErrorMessage = "Condition Type cannot exceed 4 characters.")] public string ConditionType { get; set; } + + [StringLength(13, ErrorMessage = "Customer Number cannot exceed 13 characters.")] + public string? CustomerNumber { get; set; } + + [StringLength(10, ErrorMessage = "Customer Group Code cannot exceed 10 characters.")] + public string? CustomerGroupCode { get; set; } } \ No newline at end of file diff --git a/Api/OnlineSalesAutoCrop.CoreAPI.Models/Responses/Integrations/IntegrationMaterialFreeGoodsResponse.cs b/Api/OnlineSalesAutoCrop.CoreAPI.Models/Responses/Integrations/IntegrationMaterialFreeGoodsResponse.cs index f20b797..e072401 100644 --- a/Api/OnlineSalesAutoCrop.CoreAPI.Models/Responses/Integrations/IntegrationMaterialFreeGoodsResponse.cs +++ b/Api/OnlineSalesAutoCrop.CoreAPI.Models/Responses/Integrations/IntegrationMaterialFreeGoodsResponse.cs @@ -8,7 +8,7 @@ public class IntegrationMaterialFreeGoodsResponse : ResponseBase public string SalesOrg { get; set; } public string DistributionChannel { get; set; } public string? CustomerNumber { get; set; } // nullable - public string CustomerPriceGroup { get; set; } + public string? CustomerPriceGroup { get; set; } public string MaterialCode { get; set; } public decimal MinOrderQuantity { get; set; } public decimal ForQuantity { get; set; } @@ -24,6 +24,7 @@ public class MaterialFreeGoodsByReqResponse : ResponseBase { public string SalesOrg { get; set; } public string DistributionChannel { get; set; } + public string CustomerNumber { get; set; } public string CustomerPriceGroup { get; set; } public string MaterialCode { get; set; } public bool IsUpdated { get; set; } diff --git a/Api/OnlineSalesAutoCrop.CoreAPI.Models/Responses/Integrations/IntegrationMaterialPriceResponse.cs b/Api/OnlineSalesAutoCrop.CoreAPI.Models/Responses/Integrations/IntegrationMaterialPriceResponse.cs index 7263b50..c2bfc92 100644 --- a/Api/OnlineSalesAutoCrop.CoreAPI.Models/Responses/Integrations/IntegrationMaterialPriceResponse.cs +++ b/Api/OnlineSalesAutoCrop.CoreAPI.Models/Responses/Integrations/IntegrationMaterialPriceResponse.cs @@ -7,8 +7,8 @@ public class IntegrationMaterialPriceResponse : ResponseBase public int MaterialPriceId { get; set; } public string SalesOrg { get; set; } public string DistributionChannel { get; set; } - public string CustomerNumber { get; set; } - public string CustomerGroupCode { get; set; } + public string? CustomerNumber { get; set; } + public string? CustomerGroupCode { get; set; } public string MaterialCode { get; set; } public string ConditionType { get; set; } public string CalculationType { get; set; } @@ -24,5 +24,7 @@ public class MaterialIntegrationPriceReqResponse : ResponseBase { public string MaterialCode { get; set; } public string ConditionType { get; set; } + public string? CustomerNumber { get; set; } + public string? CustomerGroupCode { get; set; } public bool IsUpdated { get; set; } } \ No newline at end of file diff --git a/Api/OnlineSalesAutoCrop.CoreAPI.Services/Services/Integrations/IntegrationService.cs b/Api/OnlineSalesAutoCrop.CoreAPI.Services/Services/Integrations/IntegrationService.cs index f4671cd..cbb460f 100644 --- a/Api/OnlineSalesAutoCrop.CoreAPI.Services/Services/Integrations/IntegrationService.cs +++ b/Api/OnlineSalesAutoCrop.CoreAPI.Services/Services/Integrations/IntegrationService.cs @@ -238,7 +238,8 @@ public class IntegrationService : IIntegrationService try { IntegrationMaterialPriceResponse meterialPrice = await GetMaterialPriceByCodeAndConditionTypeAsync(tc, - new GetMaterialPriceByCodeRequest() { MaterialCode = request.MaterialCode, ConditionType = request.ConditionType }); + new GetMaterialPriceByCodeRequest() { MaterialCode = request.MaterialCode, ConditionType = request.ConditionType, + SalesOrg=request.SalesOrg, CustomerNumber = request.CustomerNumber,CustomerGroupCode = request.CustomerGroupCode }); if (meterialPrice != null && !string.IsNullOrWhiteSpace(meterialPrice.MaterialCode)) { @@ -307,7 +308,7 @@ public class IntegrationService : IIntegrationService { IntegrationMaterialFreeGoodsResponse meterialFreeGoods = await GetMaterialFreeGoodsByFilterAsync(tc, new GetMaterialFreeGoodsByFilterRequest() { SalesOrg = request.SalesOrg, DistributionChannel = request.DistributionChannel, - CustomerPriceGroup = request.CustomerPriceGroup,MaterialCode = request.MaterialCode }); + CustomerPriceGroup = request.CustomerPriceGroup,MaterialCode = request.MaterialCode, CustomerNumber = request.CustomerNumber }); if (meterialFreeGoods != null && !string.IsNullOrWhiteSpace(meterialFreeGoods.MaterialCode)) { @@ -911,20 +912,23 @@ public class IntegrationService : IIntegrationService { SqlParameter[] p = [ + SqlHelperExtension.CreateInParam("@SalesOrg", SqlDbType.NVarChar, request.SalesOrg), SqlHelperExtension.CreateInParam("@MaterialCode", SqlDbType.NVarChar, request.MaterialCode), - SqlHelperExtension.CreateInParam("@ConditionType", SqlDbType.NVarChar, request.ConditionType) + SqlHelperExtension.CreateInParam("@ConditionType", SqlDbType.NVarChar, request.ConditionType), + SqlHelperExtension.CreateInParam("@CustomerNumber", SqlDbType.NVarChar, string.IsNullOrWhiteSpace(request.CustomerNumber)? null : request.CustomerNumber ), + SqlHelperExtension.CreateInParam("@CustomerGroup", SqlDbType.NVarChar, string.IsNullOrWhiteSpace(request.CustomerGroupCode)? null : request.CustomerGroupCode ) ]; using (IDataReader dr = await tc.ExecuteReaderSpAsync("dbo.GetMaterialPriceByMaterialCodeAndConditionType", parameterValues: p)) { - while (dr.Read()) + if (dr.Read()) { response=new IntegrationMaterialPriceResponse() { MaterialPriceId = dr.GetInt32(0), SalesOrg = dr.GetString(1), DistributionChannel = dr.GetString(2), - CustomerNumber = dr.GetString(3), + CustomerNumber = dr.IsDBNull(3) ? null : dr.GetString(3), CustomerGroupCode = dr.IsDBNull(4) ? null : dr.GetString(4), MaterialCode = dr.GetString(5), ConditionType = dr.GetString(6), @@ -948,9 +952,9 @@ public class IntegrationService : IIntegrationService return response; } - private int CreateMaterialPrice(TransactionContext tc, IntegrationMaterialPriceRequest request) + private bool CreateMaterialPrice(TransactionContext tc, IntegrationMaterialPriceRequest request) { - int newMaterialPriceId = 0; + bool response = false; try { @@ -968,20 +972,19 @@ public class IntegrationService : IIntegrationService SqlHelperExtension.CreateInParam("@ValidFrom", SqlDbType.DateTime, request.ValidFrom), SqlHelperExtension.CreateInParam("@ValidTo", SqlDbType.DateTime, request.ValidTo), SqlHelperExtension.CreateInParam("@Status", SqlDbType.NVarChar, request.Status), - SqlHelperExtension.CreateInParam("@ConditionValue", SqlDbType.Decimal, request.ConditionValue), - SqlHelperExtension.CreateOutParam("@NewMaterialPriceId", SqlDbType.Int) + SqlHelperExtension.CreateInParam("@ConditionValue", SqlDbType.Decimal, request.ConditionValue) ]; _ = tc.ExecuteNonQuerySp(spName: "dbo.InsertIntegrationMaterialPrice", parameterValues: p); - newMaterialPriceId = (int)p[14].Value; + response = true; } catch (Exception) { throw; } - return newMaterialPriceId; + return response; } private bool UpdateMaterialPrice(TransactionContext tc, IntegrationMaterialPriceRequest request) @@ -994,7 +997,7 @@ public class IntegrationService : IIntegrationService [ SqlHelperExtension.CreateInParam("@SalesOrg", SqlDbType.NVarChar, request.SalesOrg), SqlHelperExtension.CreateInParam("@DistributionChannel", SqlDbType.NVarChar, request.DistributionChannel), - SqlHelperExtension.CreateInParam("@CustomerNumber", SqlDbType.NVarChar, request.CustomerNumber), + SqlHelperExtension.CreateInParam("@CustomerNumber", SqlDbType.NVarChar, string.IsNullOrWhiteSpace(request.CustomerNumber) ? null : request.CustomerNumber), SqlHelperExtension.CreateInParam("@CustomerGroupCode", SqlDbType.NVarChar, request.CustomerGroupCode), SqlHelperExtension.CreateInParam("@MaterialCode", SqlDbType.NVarChar, request.MaterialCode), SqlHelperExtension.CreateInParam("@ConditionType", SqlDbType.NVarChar, request.ConditionType), @@ -1032,10 +1035,12 @@ public class IntegrationService : IIntegrationService { SqlParameter[] p = [ - SqlHelperExtension.CreateInParam("@MaterialCode", SqlDbType.NVarChar, request.MaterialCode), + + SqlHelperExtension.CreateInParam("@SalesOrg", SqlDbType.NVarChar, request.SalesOrg), SqlHelperExtension.CreateInParam("@DistributionChannel", SqlDbType.NVarChar, request.DistributionChannel), + SqlHelperExtension.CreateInParam("@CustomerNumber", SqlDbType.NVarChar, request.CustomerNumber), SqlHelperExtension.CreateInParam("@CustomerPriceGroup", SqlDbType.NVarChar, request.CustomerPriceGroup), - SqlHelperExtension.CreateInParam("@SalesOrg", SqlDbType.NVarChar, request.SalesOrg) + SqlHelperExtension.CreateInParam("@MaterialCode", SqlDbType.NVarChar, request.MaterialCode) ]; using (IDataReader dr = await tc.ExecuteReaderSpAsync("dbo.GetAllMaterialFreeGoodsForUpdate", parameterValues: p)) @@ -1071,9 +1076,9 @@ public class IntegrationService : IIntegrationService return response; } - private int CreateMaterialFreeGoods(TransactionContext tc, IntegrationMaterialFreeGoodsRequest request) + private bool CreateMaterialFreeGoods(TransactionContext tc, IntegrationMaterialFreeGoodsRequest request) { - int newFreeGoodsId = 0; + bool response = false; try { @@ -1092,19 +1097,18 @@ public class IntegrationService : IIntegrationService SqlHelperExtension.CreateInParam("@ValidFrom", SqlDbType.Date, request.ValidFrom), SqlHelperExtension.CreateInParam("@ValidTo", SqlDbType.Date, request.ValidTo), SqlHelperExtension.CreateInParam("@Status", SqlDbType.NVarChar, (object?)request.Status ?? DBNull.Value), - SqlHelperExtension.CreateOutParam("@NewFreeGoodsId", SqlDbType.Int) // index 14 ]; _ = tc.ExecuteNonQuerySp(spName: "dbo.InsertIntegrationMaterialFreeGoods", parameterValues: p); - newFreeGoodsId = (int)p[14].Value; + response = true; } catch (Exception) { throw; } - return newFreeGoodsId; + return response; } private bool UpdateMaterialFreeGoods(TransactionContext tc, IntegrationMaterialFreeGoodsRequest request) diff --git a/Api/OnlineSalesAutoCrop.CoreAPI/Controllers/IntegretionApi/IntegrationController.cs b/Api/OnlineSalesAutoCrop.CoreAPI/Controllers/IntegretionApi/IntegrationController.cs index e818d46..b529e72 100644 --- a/Api/OnlineSalesAutoCrop.CoreAPI/Controllers/IntegretionApi/IntegrationController.cs +++ b/Api/OnlineSalesAutoCrop.CoreAPI/Controllers/IntegretionApi/IntegrationController.cs @@ -169,20 +169,23 @@ namespace OnlineSalesAutoCrop.CoreAPI.Controllers.IntegretionApi response = await _integrationService.UpsertMaterialPriceAsync(request); if (!response.IsUpdated) { - response.ReturnMessage.Add($"Material Price Created Successfully for MaterialCode :{request.MaterialCode} And ConditionType : {request.ConditionType} "); + response.ReturnMessage.Add($"Material Price Created Successfully for MaterialCode :{request.MaterialCode} And ConditionType : {request.ConditionType}" + + $"And Customer Number : {request.CustomerNumber} And Customer Group Code : {request.CustomerGroupCode} "); response.ReturnStatus = StatusCodes.Status201Created; return StatusCode(StatusCodes.Status201Created, response); } else { - response.ReturnMessage.Add($"Material Price Updated Successfully for MaterialCode :{request.MaterialCode} And ConditionType : {request.ConditionType} "); + response.ReturnMessage.Add($"Material Price Updated Successfully for MaterialCode :{request.MaterialCode} And ConditionType : {request.ConditionType}" + + $"And Customer Number : {request.CustomerNumber} And Customer Group Code : {request.CustomerGroupCode} "); response.ReturnStatus = StatusCodes.Status200OK; return StatusCode(StatusCodes.Status200OK, response); } } catch (Exception ex) { - string msg = $"Exception Occur in Material Price Operation {request?.MaterialCode} And ConditionType : {request.ConditionType}"; + string msg = $"Exception Occur in Material Price Operation MaterialCode :{request.MaterialCode} And ConditionType : {request.ConditionType}" + + $"And Customer Number : {request.CustomerNumber} And Customer Group Code : {request.CustomerGroupCode} "; _logger.LogError(exception: ex, msg); response.ReturnStatus = StatusCodes.Status500InternalServerError; response.ReturnMessage.Add(ex.InnerException != null ? ex.InnerException.Message : ex.Message); @@ -210,14 +213,16 @@ namespace OnlineSalesAutoCrop.CoreAPI.Controllers.IntegretionApi if (!response.IsUpdated) { response.ReturnMessage.Add($"Material Free Goods Created Successfully for SalesOrg :{request.SalesOrg} " + - $"And CustomerPriceGroup : {request.CustomerPriceGroup} And MaterialCode : {request.MaterialCode} And DistributorChannel : {request.DistributionChannel}"); + $"And CustomerPriceGroup : {request.CustomerPriceGroup} And MaterialCode : {request.MaterialCode} And DistributorChannel : {request.DistributionChannel}" + + $" And Customer Number :{request.CustomerNumber} And Customer Price Group : {request.CustomerPriceGroup}"); response.ReturnStatus = StatusCodes.Status201Created; return StatusCode(StatusCodes.Status201Created, response); } else { response.ReturnMessage.Add($"Material Free Goods Updated Successfully for SalesOrg :{request.SalesOrg} " + - $"And CustomerPriceGroup : {request.CustomerPriceGroup} And MaterialCode : {request.MaterialCode} And DistributorChannel : {request.DistributionChannel}"); + $"And CustomerPriceGroup : {request.CustomerPriceGroup} And MaterialCode : {request.MaterialCode} And DistributorChannel : {request.DistributionChannel}" + + $" And Customer Number :{request.CustomerNumber} And Customer Price Group : {request.CustomerPriceGroup}"); response.ReturnStatus = StatusCodes.Status200OK; return StatusCode(StatusCodes.Status200OK, response); } @@ -225,7 +230,8 @@ namespace OnlineSalesAutoCrop.CoreAPI.Controllers.IntegretionApi catch (Exception ex) { string msg = $"Exception Occur in Material Free Goods Operation SalesOrg :{request.SalesOrg} " + - $"And CustomerPriceGroup : {request.CustomerPriceGroup} And MaterialCode : {request.MaterialCode} And DistributorChannel : {request.DistributionChannel}" ; + $" And CustomerPriceGroup : {request.CustomerPriceGroup} And MaterialCode : {request.MaterialCode} And DistributorChannel : {request.DistributionChannel}" + + $" And Customer Number :{request.CustomerNumber} And Customer Price Group : {request.CustomerPriceGroup}"; _logger.LogError(exception: ex, msg); response.ReturnStatus = StatusCodes.Status500InternalServerError; response.ReturnMessage.Add(ex.InnerException != null ? ex.InnerException.Message : ex.Message);