Existing code
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
namespace LaaProductionWeb.Services
|
||||
{
|
||||
using LaaProductionWeb.Data.Interfaces;
|
||||
using LaaProductionWeb.Services.Interfaces;
|
||||
using LaaProductionWeb.Services.Models;
|
||||
|
||||
public class OrdersService : IOrdersService
|
||||
{
|
||||
private readonly IDbContext dbContext;
|
||||
|
||||
public OrdersService(IDbContext dbContext)
|
||||
=> this.dbContext = dbContext;
|
||||
|
||||
public OrdersFoundModel FindOrders(string search)
|
||||
{
|
||||
var ordersFound = this.dbContext.AsEnumerable(
|
||||
query: $@"
|
||||
SELECT DISTINCT
|
||||
[AlleAuftragPositionen].[AuftragNr] -- 0
|
||||
, [AlleAuftragPositionen].[FertigungsauftragNr] -- 1
|
||||
, [Kunde].[Name] -- 2
|
||||
FROM [AlleAuftragPositionen]
|
||||
LEFT JOIN [Kunde] ON [Kunde].[KundenNr] = [AlleAuftragPositionen].[KundenNr]
|
||||
WHERE [AlleAuftragPositionen].[Versand_Ist_datum] IS NOT NULL
|
||||
AND [AlleAuftragPositionen].[AuftragNr] LIKE @{nameof(search)}
|
||||
ORDER BY [AlleAuftragPositionen].[AuftragNr]
|
||||
, [AlleAuftragPositionen].[FertigungsauftragNr]
|
||||
, [Kunde].[Name]",
|
||||
parameters: parameters => parameters
|
||||
.Add(nameof(search), $"%{search}%"),
|
||||
reader: reader => new OrderInfoModel
|
||||
{
|
||||
OrderNr = reader.GetValue<int>(0),
|
||||
ProductionOrderNr = reader.GetValue<int>(1),
|
||||
ClientName = reader.GetValue<string>(2),
|
||||
});
|
||||
|
||||
return new OrdersFoundModel(ordersFound);
|
||||
}
|
||||
|
||||
public OrderPositions FindPositions(string orderNr)
|
||||
{
|
||||
var positionsFound = this.dbContext.AsEnumerable(
|
||||
query: $@"
|
||||
SELECT DISTINCT
|
||||
[AlleAuftragPositionen].[PositionNr] -- 0
|
||||
FROM [AlleAuftragPositionen]
|
||||
WHERE [AlleAuftragPositionen].[AuftragNr] = @{nameof(orderNr)}
|
||||
OR [AlleAuftragPositionen].[FertigungsauftragNr] = @{nameof(orderNr)}
|
||||
ORDER BY [AlleAuftragPositionen].[PositionNr]",
|
||||
parameters: parameters => parameters.Add(nameof(orderNr), orderNr),
|
||||
reader: reader => (int)reader.GetValue<short>(0));
|
||||
|
||||
return new OrderPositions(positionsFound);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user