* Added required methods to services
This commit is contained in:
@@ -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);
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user