* Added required methods to services

This commit is contained in:
2025-04-03 09:27:32 +02:00
parent 94c4586c35
commit d7f49829a2
7 changed files with 41 additions and 27 deletions

View File

@@ -6,6 +6,6 @@ public interface IMaterialTransactionService
{
Task<IEnumerable<MaterialTransactionDto>> GetAll();
Task<MaterialTransactionDto?> GetByWzNumber(string wzNumber);
Task<IEnumerable<MaterialTransactionDto?>> GetByWzNumbers(ISet<string> wzNumbers);
Task<IEnumerable<MaterialTransactionDto?>> GetByOrderNumber(string orderNumber);
Task<IEnumerable<MaterialTransactionDto>> GetByWzNumbers(ISet<string> wzNumbers);
Task<IEnumerable<MaterialTransactionDto>> GetByOrderNumber(string orderNumber);
}

View File

@@ -1,6 +1,7 @@
using AutoMapper;
using Microsoft.EntityFrameworkCore;
using SytelineSaAppEfDataModel.Dtos;
using SytelineSaAppEfDataModel.Entities;
namespace SytelineSaAppEfDataModel.Services;
@@ -17,17 +18,31 @@ public class MaterialTransactionService(SytelineSaAppDbContext context, IMapper
.Where(x => x.MTGroupNum == wzNumber)
.Select(x => mapper.Map<MaterialTransactionDto>(x)).FirstOrDefaultAsync();
}
public async Task<IEnumerable<MaterialTransactionDto?>> GetByWzNumbers(ISet<string> wzNumbers)
public async Task<IEnumerable<MaterialTransactionDto>> GetByWzNumbers(ISet<string> wzNumbers)
{
return await context.MaterialTransactions
.Where(x => !string.IsNullOrWhiteSpace(x.MTGroupNum) && wzNumbers.Contains(x.MTGroupNum))
.Select(x => mapper.Map<MaterialTransactionDto>(x)).ToListAsync();
if (!wzNumbers.Any())
return Enumerable.Empty<MaterialTransactionDto>();
var wzNumbersList = string.Join(",", wzNumbers.Select(w => $"'{w}'"));
var sql = $@"
SELECT z.*
FROM ZPL_InternalNum_Matltran z
WHERE z.MTGroupNum <> ''
AND z.MTGroupNum IN ({wzNumbersList})";
IList<MaterialTransaction> result = await context.MaterialTransactions
.FromSqlRaw(sql)
.AsNoTracking()
.ToListAsync();
return result.Select(mapper.Map<MaterialTransactionDto>);
}
public async Task<IEnumerable<MaterialTransactionDto?>> GetByOrderNumber(string orderNumber)
public async Task<IEnumerable<MaterialTransactionDto>> GetByOrderNumber(string orderNumber)
{
return await context.MaterialTransactions.Where(x => x.RefNum == orderNumber)
return await context.MaterialTransactions.Where(x => x.RefNum == orderNumber).OrderByDescending(x => x.TransDate)
.Select(x => mapper.Map<MaterialTransactionDto>(x)).ToListAsync();
}
}