Controller injection resolved

This commit is contained in:
Stoyan Zlatev
2023-05-11 13:01:56 +02:00
parent 9aabd5c2bf
commit e2c464a345
12 changed files with 42 additions and 41 deletions
@@ -29,11 +29,7 @@
{
this.Pallets = pallets.ToDictionary(x => x, x => x == this.PalletNr);
if (this.PalletNr == 0)
{
this.PalletNr = this.Pallets.Keys.Last();
}
else if (!this.Pallets.ContainsKey(this.PalletNr))
if (!this.Pallets.ContainsKey(this.PalletNr))
{
this.Pallets[this.PalletNr] = true;
}
@@ -61,7 +61,7 @@
if (model != null && model.OrderNr != null)
{
batchModel = this.LoadBatchModel(model.OrderNr, model.PositionNr, model.PalletNr);
batchModel = this.LoadBatchModel(model.OrderNr, model.PositionNr, model.PalletNr > 0 ? (int?)model.PalletNr : null);
if (model.PositionNr != null && !batchModel.Positions.Any())
{
@@ -215,22 +215,22 @@
.Add(nameof(model.PositionNr), model.PositionNr),
reader: reader => (int)reader.GetValue<short>());
if (!pallets.Any())
{
return this.sqlClient.ExecuteReader(
query: $@"SELECT CAST(ISNULL(MAX([PS].[PalettenNr])
, (SELECT ISNULL(MAX([PS].[PalettenNr]), 1)
FROM [PalettenScan] AS [PS]
WHERE [PS].[AuftragNr] = @{nameof(model.OrderNr)})) AS INT)
FROM [PalettenScan] AS [PS]
WHERE [PS].[AuftragNr] = @{nameof(model.OrderNr)}
AND (@{nameof(model.PositionNr)} IS NULL
OR [PS].[PositionNr] = @{nameof(model.PositionNr)})",
parameters: parameters => parameters
.Add(nameof(model.OrderNr), model.OrderNr)
.Add(nameof(model.PositionNr), model.PositionNr),
reader: reader => reader.GetValue<int>());
}
//if (!pallets.Any())
//{
// return this.sqlClient.ExecuteReader(
// query: $@"SELECT CAST(ISNULL(MAX([PS].[PalettenNr])
// , (SELECT ISNULL(MAX([PS].[PalettenNr]), 1)
// FROM [PalettenScan] AS [PS]
// WHERE [PS].[AuftragNr] = @{nameof(model.OrderNr)})) AS INT)
// FROM [PalettenScan] AS [PS]
// WHERE [PS].[AuftragNr] = @{nameof(model.OrderNr)}
// AND (@{nameof(model.PositionNr)} IS NULL
// OR [PS].[PositionNr] = @{nameof(model.PositionNr)})",
// parameters: parameters => parameters
// .Add(nameof(model.OrderNr), model.OrderNr)
// .Add(nameof(model.PositionNr), model.PositionNr),
// reader: reader => reader.GetValue<int>());
//}
return pallets;
}
@@ -22,6 +22,11 @@
name: "MVC_Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional });
routes.MapRoute(
name: "MVC_Laa",
url: "LaaProductionWeb/{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional });
}
}
}
@@ -18,7 +18,7 @@
=> new ServiceCollection()
.ConfigureServices()
.BuildServiceProvider()
.BuildControllerFactory()
//.BuildControllerFactory()
.RegisterServiceProvider();
/// <summary>
@@ -10,8 +10,8 @@
{
private readonly IAccountService accountService;
public AdminController(IAccountService accountService)
=> this.accountService = accountService;
public AdminController()
=> this.accountService = ServiceProvider.Current.GetService<IAccountService>();
public ActionResult Index()
=> this.View();
@@ -12,8 +12,8 @@
{
private readonly IApprovalsService approvals;
public ApprovalsController(IApprovalsService approvals)
=> this.approvals = approvals;
public ApprovalsController()
=> this.approvals = ServiceProvider.Current.GetService<IApprovalsService>();
[HttpGet]
public ActionResult Add()
@@ -10,8 +10,8 @@
{
private readonly IAccountService accountService;
public HomeController(IAccountService accountService)
=> this.accountService = accountService;
public HomeController()
=> this.accountService = ServiceProvider.Current.GetService<IAccountService>();
[HttpGet]
public ActionResult Index()
@@ -13,8 +13,8 @@
private readonly IProtocolService protocolService;
public ProtocolController(IProtocolService protocolService)
=> this.protocolService = protocolService;
public ProtocolController()
=> this.protocolService = ServiceProvider.Current.GetService<IProtocolService>();
[HttpGet]
public ActionResult Index(int orderId = 0)
@@ -12,8 +12,8 @@
{
private readonly IReportService reportService;
public ReportController(IReportService reportService)
=> this.reportService = reportService;
public ReportController()
=> this.reportService = ServiceProvider.Current.GetService<IReportService>();
[HttpGet]
public ActionResult Helium()
@@ -16,10 +16,10 @@
private readonly IOrdersService ordersService;
private readonly IHttpService httpService;
public SearchController(IOrdersService ordersService, IHttpService httpService)
public SearchController()
{
this.ordersService = ordersService;
this.httpService = httpService;
this.ordersService = ServiceProvider.Current.GetService<IOrdersService>();
this.httpService = ServiceProvider.Current.GetService<IHttpService>();
}
[HttpGet]
@@ -21,10 +21,10 @@
private readonly IShipmentsService shipmentsService;
private readonly IHttpService httpService;
public ShipmentsController(IShipmentsService shipmentsService, IHttpService httpService)
public ShipmentsController()
{
this.shipmentsService = shipmentsService;
this.httpService = httpService;
this.shipmentsService = ServiceProvider.Current.GetService<IShipmentsService>();
this.httpService = ServiceProvider.Current.GetService<IHttpService>();
}
[HttpGet]
@@ -73,7 +73,7 @@
orderNrMenu.innerHTML = null;
let orderNr = orderNrInput.value;
if (orderNr && orderNr.length > 3) {
fetch(`@this.Url.Action("Orders", "Search")?search=${orderNr}`)
fetch(`@this.Url.Content("~/Search/Orders")?search=${orderNr}`)
.then(response => response.text())
.then(data => ordersAutocomplete(data))
.catch(error => console.log(error));
@@ -96,7 +96,7 @@
function getPositions(orderNr) {
if (orderNr && orderNr.length > 3) {
fetch(`@this.Url.Action("Positions", "Search")?ordernr=${orderNr}`)
fetch(`@this.Url.Content("~/Search/Positions")?ordernr=${orderNr}`)
.then(response => response.text())
.then(data => positionsHandler(data))
.catch(error => console.log(error));