From 51f5c09d82b4f55b6c217db849bf7fc81437870e Mon Sep 17 00:00:00 2001 From: Piotr Kus Date: Sat, 1 Feb 2025 07:21:57 +0100 Subject: [PATCH] * Removed not needed code * Changed string parameters to GUID --- .../Controllers/EdiCustomerOrdersController.cs | 2 +- .../Services/EdiCustomerOrderService.cs | 16 ++++++---------- .../Services/ErrorLogService.cs | 14 +++++++------- .../Services/IEdiCustomerOrderService.cs | 2 +- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/FaKrosnoApi/Controllers/EdiCustomerOrdersController.cs b/FaKrosnoApi/Controllers/EdiCustomerOrdersController.cs index c599fba..bdea8b7 100644 --- a/FaKrosnoApi/Controllers/EdiCustomerOrdersController.cs +++ b/FaKrosnoApi/Controllers/EdiCustomerOrdersController.cs @@ -30,7 +30,7 @@ namespace FaKrosnoApi.Controllers } [HttpPost("send-to-syteline")] - public async Task> SendOrderToSyteline([FromQuery] string customerOrderNumber) + public async Task> SendOrderToSyteline([FromQuery] Guid customerOrderNumber) { int result = await service.SendOrderToSyteline(customerOrderNumber); return result > 0 ? Ok() : BadRequest(); diff --git a/SytelineSaAppEfDataModel/Services/EdiCustomerOrderService.cs b/SytelineSaAppEfDataModel/Services/EdiCustomerOrderService.cs index 251174b..3285649 100644 --- a/SytelineSaAppEfDataModel/Services/EdiCustomerOrderService.cs +++ b/SytelineSaAppEfDataModel/Services/EdiCustomerOrderService.cs @@ -79,9 +79,13 @@ namespace SytelineSaAppEfDataModel.Services return ediCustomerOrder; } - public async Task SendOrderToSyteline(string customerOrderNumber) + public async Task SendOrderToSyteline(Guid customerOrderNumber) { - var ediCoNum = new SqlParameter("@PEdiCoNum", SqlDbType.NVarChar, 50) { Value = customerOrderNumber }; + EdiCustomerOrder? ediCustomerOrder = await context.EdiCustomerOrders.FirstOrDefaultAsync(x => x.RowPointer == customerOrderNumber); + + if (ediCustomerOrder == null) return 0; + + var ediCoNum = new SqlParameter("@PEdiCoNum", SqlDbType.NVarChar, 50) { Value = ediCustomerOrder.CustomerOrderNumber }; var ediCoCount = new SqlParameter("@PEdiCoCount", SqlDbType.Int) { Value = 0, Direction = ParameterDirection.Output }; var postedCount = new SqlParameter("@PPostedCount", SqlDbType.Int) { Value = 0, Direction = ParameterDirection.Output }; var infoBar = new SqlParameter("@Infobar", SqlDbType.NVarChar, 2800) { Value = "", Direction = ParameterDirection.Output }; @@ -92,10 +96,6 @@ namespace SytelineSaAppEfDataModel.Services "EXEC [dbo].[FKR_EDI_EXTGEN_EdiInOrderPSp] @PEdiCoNum, @PEdiCoCount OUT, @PPostedCount OUT, @Infobar OUT, @AutoPost, @ProcessId", ediCoNum, ediCoCount, postedCount, infoBar, autoPost, processId); - //var result = await context.Database.ExecuteSqlRawAsync( - // "EXEC [dbo].[FKR_EDI_EXTGEN_EdiInOrderPSp] @PEdiCoNum, @PEdiCoCount, @PPostedCount, @Infobar, @AutoPost, @ProcessId", - // parameter1, parameter2, parameter3, parameter4, parameter5, parameter6); - string? infoBarResult = infoBar.Value?.ToString(); int ediCoCountResult = Convert.ToInt32(ediCoCount.Value); int postedCountResult = Convert.ToInt32(postedCount.Value); @@ -105,10 +105,6 @@ namespace SytelineSaAppEfDataModel.Services Console.WriteLine($"Posted Count: {postedCountResult}"); return postedCountResult; - //// Jeśli chcesz pobrać wyniki procedury składowanej: - //var results = context.SomeEntity.FromSqlRaw( - // "EXEC YourStoredProcedure @Param1, @Param2", - // parameter1, parameter2).ToList(); } } } diff --git a/SytelineSaAppEfDataModel/Services/ErrorLogService.cs b/SytelineSaAppEfDataModel/Services/ErrorLogService.cs index 3e53095..8d1f2df 100644 --- a/SytelineSaAppEfDataModel/Services/ErrorLogService.cs +++ b/SytelineSaAppEfDataModel/Services/ErrorLogService.cs @@ -1,10 +1,5 @@ using AutoMapper; using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using SytelineSaAppEfDataModel.Dtos; namespace SytelineSaAppEfDataModel.Services @@ -18,8 +13,13 @@ namespace SytelineSaAppEfDataModel.Services public async Task> GetByOrderNumber(Guid customerOrderNumber) { - return await context.ErrorLogs.Where(x => x.TrxNum == customerOrderNumber) + EdiCustomerOrderDto ediCustomerOrderDto = mapper.Map( + await context.EdiCustomerOrders.FirstOrDefaultAsync(x => x.RowPointer.Equals(customerOrderNumber))); + + if (ediCustomerOrderDto == null) return []; + + return await context.ErrorLogs.Where(x => x.TrxNum == ediCustomerOrderDto.CustomerOrderNumber) .Select(x => mapper.Map(x)).ToListAsync(); } } -} +} \ No newline at end of file diff --git a/SytelineSaAppEfDataModel/Services/IEdiCustomerOrderService.cs b/SytelineSaAppEfDataModel/Services/IEdiCustomerOrderService.cs index 0f5d2e9..acfcdff 100644 --- a/SytelineSaAppEfDataModel/Services/IEdiCustomerOrderService.cs +++ b/SytelineSaAppEfDataModel/Services/IEdiCustomerOrderService.cs @@ -12,6 +12,6 @@ namespace SytelineSaAppEfDataModel.Services Task> GetAll(); Task> GetByDate(DateTime date); Task GetByOrderNumber(Guid orderNumber); - Task SendOrderToSyteline(string customerOrderNumber); + Task SendOrderToSyteline(Guid customerOrderNumber); } }