Production Approvals,
sql client refactoring
This commit is contained in:
@@ -9,9 +9,9 @@
|
||||
|
||||
public class AccountService : IAccountService
|
||||
{
|
||||
private readonly IDbContext dbContext;
|
||||
private readonly ISqlClient dbContext;
|
||||
|
||||
public AccountService(IDbContext dbContext)
|
||||
public AccountService(ISqlClient dbContext)
|
||||
=> this.dbContext = dbContext;
|
||||
|
||||
public WindowsUser GetOrCreateWindowsUser(string primarySID, string domainName, string userName)
|
||||
@@ -81,7 +81,7 @@
|
||||
}) ?? new UserRole();
|
||||
|
||||
public IEnumerable<UserRole> GetUserRoles(int userId)
|
||||
=> this.dbContext.AsEnumerable($@"
|
||||
=> this.dbContext.ExecuteReader($@"
|
||||
SELECT [Account].[Roles].[RoleId]
|
||||
, [Account].[Roles].[RoleName]
|
||||
, [Account].[Roles].[DisplayName]
|
||||
@@ -99,7 +99,7 @@
|
||||
});
|
||||
|
||||
public List<UserPermissions> GetUsersWithPendingRoles()
|
||||
=> this.dbContext.AsEnumerable($@"
|
||||
=> this.dbContext.ExecuteReader($@"
|
||||
SELECT [Account].[Users].[UserId]
|
||||
, [Account].[Users].[FirstName] + ' ' + [Account].[Users].[LastName]
|
||||
, [Account].[Roles].[RoleId]
|
||||
@@ -140,7 +140,7 @@
|
||||
|
||||
public void RequestPermissions(PermissionsModel model)
|
||||
{
|
||||
this.dbContext.Transaction($@"
|
||||
this.dbContext.ExecuteNonQuery($@"
|
||||
INSERT INTO [Auftrag].[Account].[Users] (
|
||||
[UserId]
|
||||
, [FirstName]
|
||||
@@ -153,7 +153,7 @@
|
||||
.Add(nameof(model.FirstName), model.FirstName)
|
||||
.Add(nameof(model.LastName), model.LastName));
|
||||
|
||||
model.Role.Pending = this.dbContext.Transaction($@"
|
||||
model.Role.Pending = this.dbContext.ExecuteNonQuery($@"
|
||||
INSERT INTO [Auftrag].[Account].[UsersRoles] (
|
||||
[UserId]
|
||||
, [RoleId])
|
||||
@@ -161,7 +161,7 @@
|
||||
, @{nameof(model.Role.RoleId)})",
|
||||
parameters => parameters
|
||||
.Add(nameof(model.UserId), model.UserId)
|
||||
.Add(nameof(model.Role.RoleId), model.Role.RoleId));
|
||||
.Add(nameof(model.Role.RoleId), model.Role.RoleId)) == 1;
|
||||
}
|
||||
|
||||
public void SaveUserPermissions(IEnumerable<UserPermissions> usersPermissions)
|
||||
@@ -170,7 +170,7 @@
|
||||
{
|
||||
foreach (var role in user.Roles)
|
||||
{
|
||||
this.dbContext.Transaction(
|
||||
this.dbContext.ExecuteNonQuery(
|
||||
role.Deleted
|
||||
? $@"DELETE FROM [Account].[UsersRoles]
|
||||
WHERE [Account].[UsersRoles].[UserId] = @{nameof(user.UserId)}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
namespace LaaProductionWeb.Services
|
||||
{
|
||||
using LaaProductionWeb.Data.Interfaces;
|
||||
using LaaProductionWeb.Services.Interfaces;
|
||||
using LaaProductionWeb.Services.Models;
|
||||
|
||||
public class ApprovalsService : IApprovalsService
|
||||
{
|
||||
private readonly ISqlClient sqlClient;
|
||||
|
||||
public ApprovalsService(ISqlClient sqlClient)
|
||||
=> this.sqlClient = sqlClient;
|
||||
|
||||
public Result Add(ProductionApproval approval)
|
||||
{
|
||||
var message = string.Empty;
|
||||
var rowsAffected = this.sqlClient.ExecuteNonQuery($@"
|
||||
INSERT INTO [ProductionSkipAndLifeTimeInfo] (
|
||||
[OrderNumber]
|
||||
, [PcbId]
|
||||
, [SkipRadioParametersCheck]
|
||||
, [OverrideFwCheck]
|
||||
, [OverrideLutCheck]
|
||||
, [RequiredLifeTimeYearsAssembly]
|
||||
, [RequiredLifeTimeYearsShipping]
|
||||
, [KitronProductionDate]
|
||||
, [MaxDrainedBatteryLoadPercent]
|
||||
, [MaxStorageMonths]
|
||||
, [ApprovalDate]
|
||||
, [ApproverName]
|
||||
, [ApprovalComment])
|
||||
VALUES (@{nameof(approval.OrderNr)}
|
||||
, @{nameof(approval.PcbId)}
|
||||
, @{nameof(approval.SkipRadioCheck)}
|
||||
, @{nameof(approval.OverrideFwCheck)}
|
||||
, @{nameof(approval.OverrideLutCheck)}
|
||||
, @{nameof(approval.RequiredLifeTimeYearsAssembly)}
|
||||
, @{nameof(approval.RequiredLifeTimeYearsShipping)}
|
||||
, @{nameof(approval.KitronProductionDate)}
|
||||
, @{nameof(approval.MaxDrainedBatteryLoadPercent)}
|
||||
, @{nameof(approval.MaxStorageMonths)}
|
||||
, @{nameof(approval.ApprovalDate)}
|
||||
, @{nameof(approval.ApproverName)}
|
||||
, @{nameof(approval.ApprovalComment)})",
|
||||
parameters => parameters
|
||||
.Add(nameof(approval.OrderNr), approval.OrderNr)
|
||||
.Add(nameof(approval.PcbId), approval.PcbId)
|
||||
.Add(nameof(approval.SkipRadioCheck), approval.SkipRadioCheck)
|
||||
.Add(nameof(approval.OverrideFwCheck), approval.OverrideFwCheck)
|
||||
.Add(nameof(approval.OverrideLutCheck), approval.OverrideLutCheck)
|
||||
.Add(nameof(approval.RequiredLifeTimeYearsAssembly), approval.RequiredLifeTimeYearsAssembly)
|
||||
.Add(nameof(approval.RequiredLifeTimeYearsShipping), approval.RequiredLifeTimeYearsShipping)
|
||||
.Add(nameof(approval.KitronProductionDate), approval.KitronProductionDate)
|
||||
.Add(nameof(approval.MaxDrainedBatteryLoadPercent), approval.MaxDrainedBatteryLoadPercent)
|
||||
.Add(nameof(approval.MaxStorageMonths), approval.MaxStorageMonths)
|
||||
.Add(nameof(approval.ApprovalDate), approval.ApprovalDate)
|
||||
.Add(nameof(approval.ApproverName), approval.ApproverName)
|
||||
.Add(nameof(approval.ApprovalComment), approval.ApprovalComment),
|
||||
errorCallback: (s, args) => message = args.Message);
|
||||
|
||||
Result result = rowsAffected == 1;
|
||||
|
||||
if (result)
|
||||
{
|
||||
result.WithMessage("Die Genehmigung wurde erfolgreich hinzugefügt.");
|
||||
}
|
||||
else if (string.IsNullOrWhiteSpace(message))
|
||||
{
|
||||
result.WithMessage("Die Genehmigung wurde nicht hinzugefügt.");
|
||||
}
|
||||
else
|
||||
{
|
||||
result.WithMessage(message);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace LaaProductionWeb.Services.Interfaces
|
||||
{
|
||||
using LaaProductionWeb.Services.Models;
|
||||
|
||||
public interface IApprovalsService : ITransient
|
||||
{
|
||||
Result Add(ProductionApproval approval);
|
||||
}
|
||||
}
|
||||
@@ -58,7 +58,9 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AccountService.cs" />
|
||||
<Compile Include="ApprovalsService.cs" />
|
||||
<Compile Include="Interfaces\IAccountService.cs" />
|
||||
<Compile Include="Interfaces\IApprovalsService.cs" />
|
||||
<Compile Include="Interfaces\IOrdersService.cs" />
|
||||
<Compile Include="Interfaces\IProtocolService.cs" />
|
||||
<Compile Include="Interfaces\IReportService.cs" />
|
||||
@@ -72,6 +74,7 @@
|
||||
<Compile Include="Models\HeliumReportModelExtensions.cs" />
|
||||
<Compile Include="Models\OrderIdentity.cs" />
|
||||
<Compile Include="Models\PalletPosition.cs" />
|
||||
<Compile Include="Models\ProductionApproval.cs" />
|
||||
<Compile Include="Models\RoleModel.cs" />
|
||||
<Compile Include="Models\UserRole.cs" />
|
||||
<Compile Include="Models\UserPermissions.cs" />
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
namespace LaaProductionWeb.Services.Models
|
||||
{
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
public class ProductionApproval
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public int? OrderNr { get; set; }
|
||||
|
||||
public int? PcbId { get; set; }
|
||||
|
||||
public bool SkipRadioCheck { get; set; }
|
||||
|
||||
public int? OverrideFwCheck { get; set; }
|
||||
|
||||
public int? OverrideLutCheck { get; set; }
|
||||
|
||||
public int? RequiredLifeTimeYearsAssembly { get; set; }
|
||||
|
||||
public int? RequiredLifeTimeYearsShipping { get; set; }
|
||||
|
||||
public DateTime? KitronProductionDate { get; set; }
|
||||
|
||||
public double? MaxDrainedBatteryLoadPercent { get; set; }
|
||||
|
||||
public int? MaxStorageMonths { get; set; }
|
||||
|
||||
public DateTime ApprovalDate { get; set; }
|
||||
|
||||
public string ApproverName { get; set; }
|
||||
|
||||
[Required]
|
||||
[MinLength(10)]
|
||||
public string ApprovalComment { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
namespace LaaProductionWeb.Services.Models
|
||||
{
|
||||
public struct Result
|
||||
public class Result
|
||||
{
|
||||
private readonly bool succeeded;
|
||||
private readonly string message;
|
||||
|
||||
private string message;
|
||||
|
||||
private Result(bool succeeded = true)
|
||||
{
|
||||
@@ -17,6 +18,9 @@
|
||||
this.succeeded = string.IsNullOrWhiteSpace(message);
|
||||
}
|
||||
|
||||
public void WithMessage(string message)
|
||||
=> this.message = message;
|
||||
|
||||
public override string ToString()
|
||||
=> this.message;
|
||||
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
|
||||
public class OrdersService : IOrdersService
|
||||
{
|
||||
private readonly IDbContext dbContext;
|
||||
private readonly ISqlClient dbContext;
|
||||
|
||||
public OrdersService(IDbContext dbContext)
|
||||
public OrdersService(ISqlClient dbContext)
|
||||
=> this.dbContext = dbContext;
|
||||
|
||||
public OrdersFoundModel FindOrders(string search)
|
||||
{
|
||||
var ordersFound = this.dbContext.AsEnumerable(
|
||||
var ordersFound = this.dbContext.ExecuteReader(
|
||||
query: $@"
|
||||
SELECT DISTINCT
|
||||
[AlleAuftragPositionen].[AuftragNr] -- 0
|
||||
@@ -40,7 +40,7 @@
|
||||
|
||||
public OrderPositions FindPositions(string orderNr)
|
||||
{
|
||||
var positionsFound = this.dbContext.AsEnumerable(
|
||||
var positionsFound = this.dbContext.ExecuteReader(
|
||||
query: $@"
|
||||
SELECT DISTINCT
|
||||
[AlleAuftragPositionen].[PositionNr] -- 0
|
||||
|
||||
@@ -11,13 +11,13 @@
|
||||
|
||||
public class ProtocolService : IProtocolService
|
||||
{
|
||||
private readonly IDbContext dbContext;
|
||||
private readonly ISqlClient dbContext;
|
||||
|
||||
public ProtocolService(IDbContext dbContext)
|
||||
public ProtocolService(ISqlClient dbContext)
|
||||
=> this.dbContext = dbContext;
|
||||
|
||||
public bool DeleteFile(int fileId)
|
||||
=> this.dbContext.ScalarTransaction<int>($@"
|
||||
=> this.dbContext.ExecuteScalar<int>($@"
|
||||
DELETE FROM [File]
|
||||
WHERE [FileId] = @{nameof(fileId)};
|
||||
DELETE FROM [FilesOrders]
|
||||
@@ -85,7 +85,7 @@
|
||||
}
|
||||
|
||||
public IEnumerable<KeyValuePair<int, string>> FindOrdersById(int orderno)
|
||||
=> this.dbContext.AsEnumerable($@"
|
||||
=> this.dbContext.ExecuteReader($@"
|
||||
SELECT DISTINCT
|
||||
[APG].[AuftragNr]
|
||||
, [K].[Name]
|
||||
@@ -104,7 +104,7 @@
|
||||
value: reader.GetString(1)));
|
||||
|
||||
public IEnumerable<KeyValuePair<int, string>> FindOrdersByClient(string clientName)
|
||||
=> this.dbContext.AsEnumerable(
|
||||
=> this.dbContext.ExecuteReader(
|
||||
query: $@"
|
||||
SELECT DISTINCT
|
||||
[APG].[AuftragNr]
|
||||
@@ -124,7 +124,7 @@
|
||||
value: reader.GetString(1)));
|
||||
|
||||
public IEnumerable<TestStatus> LoadTestStatus(int orderId)
|
||||
=> this.dbContext.AsEnumerable(
|
||||
=> this.dbContext.ExecuteReader(
|
||||
query: $@"
|
||||
SELECT DISTINCT
|
||||
[APS].[PositionNr] AS [PosNr] -- 0
|
||||
@@ -165,7 +165,7 @@
|
||||
|
||||
public bool OrderCompleted(int orderId)
|
||||
{
|
||||
var sumResults = this.dbContext.AsEnumerable($@"
|
||||
var sumResults = this.dbContext.ExecuteReader($@"
|
||||
SELECT CAST(CASE WHEN ISNULL([CPT].[CordonelPressureTest_Valid], 1) = 1 THEN 0 ELSE 1 END AS INT)
|
||||
+ CAST(CASE WHEN ISNULL([DP].[Dicht], 1) = 1 THEN 0 ELSE 1 END AS INT)
|
||||
+ ISNULL(MAX([APS].[StatusFertigung]) - 30, 0)
|
||||
@@ -199,7 +199,7 @@
|
||||
var fileName = $"{clientId}_{orderId}.pdf";
|
||||
var fileContent = this.GetBuffer(fileStream);
|
||||
|
||||
return this.dbContext.ScalarTransaction<int>(
|
||||
return this.dbContext.ExecuteScalar<int>(
|
||||
query: $@"
|
||||
INSERT INTO [dbo].[File] (
|
||||
[FileName]
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
|
||||
public class ReportService : IReportService
|
||||
{
|
||||
private readonly IDbContext dbContext;
|
||||
private readonly ISqlClient dbContext;
|
||||
|
||||
public ReportService(IDbContext dbContext)
|
||||
public ReportService(ISqlClient dbContext)
|
||||
=> this.dbContext = dbContext;
|
||||
|
||||
public HeliumReportModel LoadHeliumPressureReport(HeliumReportModel model = null)
|
||||
@@ -25,7 +25,7 @@
|
||||
var where = model.Filter.Where();
|
||||
var orderBy = model.Filter.OrderBy();
|
||||
|
||||
model.Items = this.dbContext.AsEnumerable($@"
|
||||
model.Items = this.dbContext.ExecuteReader($@"
|
||||
SELECT [PT].[CordonelPressureTest_FertigungsAuftragsNr] AS [FertigungNr] -- 0 Filter
|
||||
, [POS].[AuftragNr] AS [AuftragNr] -- 1 Filter
|
||||
, [POS].[PositionNr] AS [PositionNr] -- 2 Filter
|
||||
@@ -94,7 +94,7 @@
|
||||
}
|
||||
|
||||
public IEnumerable<HeliumPressurePoint> LoadHeliumPressureResults(int testId)
|
||||
=> this.dbContext.AsEnumerable($@"
|
||||
=> this.dbContext.ExecuteReader($@"
|
||||
SELECT [CordonelPressureTestTestPoints_Id]
|
||||
, [CordonelPressureTest_TestPointNr]
|
||||
, CAST([CordonelPressureTest_TestPointResult] AS NUMERIC(9, 8))
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
|
||||
public class ShipmentsService : IShipmentsService
|
||||
{
|
||||
private readonly IDbContext dbContext;
|
||||
private readonly ISqlClient dbContext;
|
||||
|
||||
public ShipmentsService(IDbContext dbContext)
|
||||
public ShipmentsService(ISqlClient dbContext)
|
||||
=> this.dbContext = dbContext;
|
||||
|
||||
public OrderScanModel DeletePalletEntry(int id)
|
||||
@@ -52,7 +52,7 @@
|
||||
|
||||
public byte[] LoadBatchBuffer(OrderScanModel model)
|
||||
{
|
||||
var palletLoad = this.dbContext.AsEnumerable(
|
||||
var palletLoad = this.dbContext.ExecuteReader(
|
||||
query: $@"
|
||||
SELECT [PalettenNr]
|
||||
, [SerienNr]
|
||||
@@ -76,7 +76,7 @@
|
||||
}
|
||||
|
||||
public IEnumerable<SerialNr> LoadBatchItems(OrderScanModel model)
|
||||
=> this.dbContext.AsEnumerable(
|
||||
=> this.dbContext.ExecuteReader(
|
||||
query: $@"
|
||||
SELECT DISTINCT
|
||||
[PalettenScan].[ID] -- 0
|
||||
@@ -156,7 +156,7 @@
|
||||
}
|
||||
|
||||
private IEnumerable<PalletPosition> LoadBatchPositions(OrderScanModel model, string orderNr, string palNr)
|
||||
=> this.dbContext.AsEnumerable($@"
|
||||
=> this.dbContext.ExecuteReader($@"
|
||||
SELECT DISTINCT
|
||||
[Auftrag].[PositionNr]
|
||||
, COUNT(1)
|
||||
|
||||
Reference in New Issue
Block a user