diff --git a/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/IDbContext.cs b/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/IDbContext.cs deleted file mode 100644 index 25a9521d..00000000 --- a/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/IDbContext.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace LaaProductionWeb.Data.Interfaces -{ - using System; - using System.Collections.Generic; - - public interface IDbContext - { - IEnumerable AsEnumerable(string query, Action parameters, Func reader); - - IEnumerable AsEnumerable(string query, Func reader); - - int ExecuteNonQuery(string query, Action parameters); - - T FirstOrDefault(string query, Action parameters, Func reader); - - T ScalarTransaction(string query, Action parameters); - - bool Transaction(string query, Action parameters); - } -} diff --git a/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/IParameterCollection.cs b/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/IParameterCollection.cs deleted file mode 100644 index f2276950..00000000 --- a/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/IParameterCollection.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace LaaProductionWeb.Data.Interfaces -{ - public interface IParameterCollection - { - IParameterCollection Add(string name, object value); - - IParameterCollection AddFile(string name, byte[] fileContent); - } -} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/ISqlClient.cs b/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/ISqlClient.cs new file mode 100644 index 00000000..8f66d1ec --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/ISqlClient.cs @@ -0,0 +1,21 @@ +namespace LaaProductionWeb.Data.Interfaces +{ + using System; + using System.Collections.Generic; + using System.Data.SqlClient; + + public interface ISqlClient + { + int ExecuteNonQuery(string query, Action parameters, SqlInfoMessageEventHandler errorCallback = null); + + IEnumerable ExecuteReader(string query, Func reader, SqlInfoMessageEventHandler errorCallback = null); + + IEnumerable ExecuteReader(string query, Action parameters, Func reader, SqlInfoMessageEventHandler errorCallback = null); + + T ExecuteScalar(string query, Action parameters, SqlInfoMessageEventHandler errorCallback = null); + + T FirstOrDefault(string query, Func reader, SqlInfoMessageEventHandler errorCallback = null); + + T FirstOrDefault(string query, Action parameters, Func reader, SqlInfoMessageEventHandler errorCallback = null); + } +} diff --git a/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/ISqlParameters.cs b/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/ISqlParameters.cs new file mode 100644 index 00000000..5f62cab9 --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/ISqlParameters.cs @@ -0,0 +1,9 @@ +namespace LaaProductionWeb.Data.Interfaces +{ + public interface ISqlParameters + { + ISqlParameters Add(string name, object value); + + ISqlParameters AddFile(string name, byte[] fileContent); + } +} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/ISqlReader.cs b/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/ISqlReader.cs index 6bcadfe1..038f614b 100644 --- a/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/ISqlReader.cs +++ b/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/ISqlReader.cs @@ -2,10 +2,10 @@ { public interface ISqlReader { - byte[] GetBytes(int index); + byte[] GetBytes(int index = -1); - string GetString(int index); + string GetString(int index = -1); - T GetValue(int index); + T GetValue(int index = -1); } } \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb.Data/LaaProductionWeb.Data.csproj b/LaaProductionWeb/LaaProductionWeb.Data/LaaProductionWeb.Data.csproj index 8c9e61ce..40cea338 100644 --- a/LaaProductionWeb/LaaProductionWeb.Data/LaaProductionWeb.Data.csproj +++ b/LaaProductionWeb/LaaProductionWeb.Data/LaaProductionWeb.Data.csproj @@ -56,12 +56,14 @@ - - - - + + + + + + - + diff --git a/LaaProductionWeb/LaaProductionWeb.Data/Repositories/Interfaces/IRepository[T].cs b/LaaProductionWeb/LaaProductionWeb.Data/Repositories/Interfaces/IRepository[T].cs new file mode 100644 index 00000000..7f22f717 --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb.Data/Repositories/Interfaces/IRepository[T].cs @@ -0,0 +1,17 @@ +namespace LaaProductionWeb.Data.Repositories.Interfaces +{ + using System.Collections.Generic; + + public interface IRepository + { + int Create(string query, object parameters); + + int Delete(string query, object parameters); + + IEnumerable First(string query, object parameters); + + T Read(string query, object parameters); + + int Update(string query, object parameters); + } +} diff --git a/LaaProductionWeb/LaaProductionWeb.Data/Repositories/Repository[T].cs b/LaaProductionWeb/LaaProductionWeb.Data/Repositories/Repository[T].cs new file mode 100644 index 00000000..684b90ce --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb.Data/Repositories/Repository[T].cs @@ -0,0 +1,40 @@ +namespace LaaProductionWeb.Data.Repositories +{ + using System.Collections.Generic; + + using LaaProductionWeb.Data.Interfaces; + using LaaProductionWeb.Data.Repositories.Interfaces; + + public abstract class Repository : IRepository + { + private readonly ISqlClient sqlClient; + + protected Repository(ISqlClient sqlClient) + => this.sqlClient = sqlClient; + + public int Create(string query, object parameters) + { + throw new System.NotImplementedException(); + } + + public int Delete(string query, object parameters) + { + throw new System.NotImplementedException(); + } + + public IEnumerable First(string query, object parameters) + { + throw new System.NotImplementedException(); + } + + public T Read(string query, object parameters) + { + throw new System.NotImplementedException(); + } + + public int Update(string query, object parameters) + { + throw new System.NotImplementedException(); + } + } +} diff --git a/LaaProductionWeb/LaaProductionWeb.Data/DbContext.cs b/LaaProductionWeb/LaaProductionWeb.Data/SqlClient.cs similarity index 56% rename from LaaProductionWeb/LaaProductionWeb.Data/DbContext.cs rename to LaaProductionWeb/LaaProductionWeb.Data/SqlClient.cs index 3a48cf8d..28cd5de9 100644 --- a/LaaProductionWeb/LaaProductionWeb.Data/DbContext.cs +++ b/LaaProductionWeb/LaaProductionWeb.Data/SqlClient.cs @@ -6,77 +6,121 @@ using System.Collections.Generic; using System.Data; using System.Data.SqlClient; - - public class DbContext : IDbContext + + public class SqlClient : ISqlClient { private readonly string connectionString; - public DbContext(string connectionString) + public SqlClient(string connectionString) => this.connectionString = connectionString; - public IEnumerable AsEnumerable(string query, Action parameters, Func reader) + public int ExecuteNonQuery(string query, Action parameters, SqlInfoMessageEventHandler errorCallback = null) { + var rowsAffected = 0; + using (var sqlConnection = new SqlConnection(this.connectionString)) { - sqlConnection.OpenWithErrorHandling(); + sqlConnection.OpenWithErrorHandling(errorCallback); using (var sqlCommand = sqlConnection.CreateCommand()) { - sqlCommand.CommandText = query; - parameters(sqlCommand.Parameters); - using (SqlReader sqlReader = sqlCommand.ExecuteReader(CommandBehavior.SequentialAccess)) - { - while (sqlReader.Read()) - { - yield return reader(sqlReader); - } - } + sqlCommand.CommandText = query; + rowsAffected = sqlCommand.ExecuteNonQuery(); } } + + return rowsAffected; } - public IEnumerable AsEnumerable(string query, Func reader) + public IEnumerable ExecuteReader(string query, Func output, SqlInfoMessageEventHandler errorCallback = null) { using (var sqlConnection = new SqlConnection(this.connectionString)) { - sqlConnection.OpenWithErrorHandling(); + sqlConnection.OpenWithErrorHandling(errorCallback); using (var sqlCommand = sqlConnection.CreateCommand()) { sqlCommand.CommandText = query; - using (SqlReader sqlReader = sqlCommand.ExecuteReader(CommandBehavior.SequentialAccess)) + using (SqlReader sqlReader = sqlCommand.ExecuteReader()) { while (sqlReader.Read()) { - yield return reader(sqlReader); + yield return output(sqlReader); } } } } } - public T FirstOrDefault(string query, Action parameters, Func reader) + public IEnumerable ExecuteReader(string query, Action parameters, Func output, SqlInfoMessageEventHandler errorCallback = null) + { + using (var sqlConnection = new SqlConnection(this.connectionString)) + { + sqlConnection.OpenWithErrorHandling(errorCallback); + + using (var sqlCommand = sqlConnection.CreateCommand()) + { + parameters(sqlCommand.Parameters); + + sqlCommand.CommandText = query; + + using (SqlReader sqlReader = sqlCommand.ExecuteReader()) + { + while (sqlReader.Read()) + { + yield return output(sqlReader); + } + } + } + } + } + + public T ExecuteScalar(string query, Action parameters, SqlInfoMessageEventHandler errorCallback = null) + { + var scalarResult = default(T); + + using (var sqlConnection = new SqlConnection(this.connectionString)) + { + sqlConnection.OpenWithErrorHandling(errorCallback); + + using (var sqlCommand = sqlConnection.CreateCommand()) + { + parameters(sqlCommand.Parameters); + + sqlCommand.CommandText = query; + + var scalarObject = sqlCommand.ExecuteScalar(); + + if (scalarObject is T scalarValue) + { + scalarResult = scalarValue; + } + } + } + + return scalarResult; + } + + public T FirstOrDefault(string query, Func output, SqlInfoMessageEventHandler errorCallback = null) { var firstOrDefaultResult = default(T); using (var sqlConnection = new SqlConnection(this.connectionString)) { - sqlConnection.OpenWithErrorHandling(); + sqlConnection.OpenWithErrorHandling(errorCallback); using (var sqlCommand = sqlConnection.CreateCommand()) { sqlCommand.CommandText = query; - parameters(sqlCommand.Parameters); - using (SqlReader sqlReader = sqlCommand.ExecuteReader(CommandBehavior.SequentialAccess)) { if (sqlReader.Read()) { - firstOrDefaultResult = reader(sqlReader); + firstOrDefaultResult = output(sqlReader); } } } @@ -85,86 +129,31 @@ return firstOrDefaultResult; } - public int ExecuteNonQuery(string query, Action parameters) + public T FirstOrDefault(string query, Action parameters, Func output, SqlInfoMessageEventHandler errorCallback = null) { - var rowsAffected = 0; + var firstOrDefaultResult = default(T); using (var sqlConnection = new SqlConnection(this.connectionString)) { - sqlConnection.OpenWithErrorHandling(); + sqlConnection.OpenWithErrorHandling(errorCallback); using (var sqlCommand = sqlConnection.CreateCommand()) { - sqlCommand.CommandText = query; - parameters(sqlCommand.Parameters); - rowsAffected = sqlCommand.ExecuteNonQuery(); - } - } + sqlCommand.CommandText = query; - return rowsAffected; - } - - public T ScalarTransaction(string query, Action parameters) - { - var scalarResult = default(T); - - using (var sqlConnection = new SqlConnection(this.connectionString)) - { - sqlConnection.OpenWithErrorHandling(); - - using (var sqlTransaction = sqlConnection.BeginTransaction()) - { - using (var sqlCommand = sqlConnection.CreateCommand()) + using (SqlReader sqlReader = sqlCommand.ExecuteReader(CommandBehavior.SequentialAccess)) { - sqlCommand.Transaction = sqlTransaction; - sqlCommand.CommandText = query; - - parameters(sqlCommand.Parameters); - - var scalarObject = sqlCommand.ExecuteScalar(); - - if (scalarObject is T scalarValue) + if (sqlReader.Read()) { - scalarResult = scalarValue; + firstOrDefaultResult = output(sqlReader); } } - - sqlTransaction.Commit(); } } - return scalarResult; - } - - public bool Transaction(string query, Action parameters) - { - var canCommitTransaction = true; - - using (var sqlConnection = new SqlConnection(this.connectionString)) - { - sqlConnection.OpenWithErrorHandling((sender, args) => canCommitTransaction = false); - - using (var sqlTransaction = sqlConnection.BeginTransaction()) - { - using (var sqlCommand = sqlConnection.CreateCommand()) - { - sqlCommand.Transaction = sqlTransaction; - sqlCommand.CommandText = query; - - parameters(sqlCommand.Parameters); - sqlCommand.ExecuteNonQuery(); - } - - if (canCommitTransaction) - { - sqlTransaction.Commit(); - } - } - } - - return canCommitTransaction; + return firstOrDefaultResult; } } } diff --git a/LaaProductionWeb/LaaProductionWeb.Data/DbContextExtensions.cs b/LaaProductionWeb/LaaProductionWeb.Data/SqlClientExtensions.cs similarity index 90% rename from LaaProductionWeb/LaaProductionWeb.Data/DbContextExtensions.cs rename to LaaProductionWeb/LaaProductionWeb.Data/SqlClientExtensions.cs index d5d0387e..5905afd4 100644 --- a/LaaProductionWeb/LaaProductionWeb.Data/DbContextExtensions.cs +++ b/LaaProductionWeb/LaaProductionWeb.Data/SqlClientExtensions.cs @@ -7,11 +7,11 @@ using System.Data.SqlClient; using System.Diagnostics; - public static class DbContextExtensions + public static class SqlClientExtensions { public static IServiceCollection AddDbContext(this IServiceCollection services, string connectionString) { - services.AddTransient(_ => new DbContext(connectionString)); + services.AddTransient(_ => new SqlClient(connectionString)); return services; } diff --git a/LaaProductionWeb/LaaProductionWeb.Data/ParameterCollection.cs b/LaaProductionWeb/LaaProductionWeb.Data/SqlParameters.cs similarity index 63% rename from LaaProductionWeb/LaaProductionWeb.Data/ParameterCollection.cs rename to LaaProductionWeb/LaaProductionWeb.Data/SqlParameters.cs index 36b2e65d..a7dc8b7f 100644 --- a/LaaProductionWeb/LaaProductionWeb.Data/ParameterCollection.cs +++ b/LaaProductionWeb/LaaProductionWeb.Data/SqlParameters.cs @@ -6,21 +6,21 @@ using System.Data; using System.Data.SqlClient; - public class ParameterCollection : IParameterCollection + public class SqlParameters : ISqlParameters { private readonly SqlParameterCollection parameters; - private ParameterCollection(SqlParameterCollection parameters) + private SqlParameters(SqlParameterCollection parameters) => this.parameters = parameters; - public IParameterCollection Add(string name, object value) + public ISqlParameters Add(string name, object value) { this.parameters.Add(new SqlParameter(name, value ?? DBNull.Value)); return this; } - public IParameterCollection AddFile(string name, byte[] fileContent) + public ISqlParameters AddFile(string name, byte[] fileContent) { var sqlParameter = new SqlParameter(name, SqlDbType.VarBinary); @@ -38,7 +38,7 @@ return this; } - public static implicit operator ParameterCollection(SqlParameterCollection sqlParameterCollection) - => new ParameterCollection(sqlParameterCollection); + public static implicit operator SqlParameters(SqlParameterCollection sqlParameterCollection) + => new SqlParameters(sqlParameterCollection); } } diff --git a/LaaProductionWeb/LaaProductionWeb.Data/SqlReader.cs b/LaaProductionWeb/LaaProductionWeb.Data/SqlReader.cs index 898e0fc5..3c136845 100644 --- a/LaaProductionWeb/LaaProductionWeb.Data/SqlReader.cs +++ b/LaaProductionWeb/LaaProductionWeb.Data/SqlReader.cs @@ -9,6 +9,8 @@ { private readonly SqlDataReader sqlDataReader; + private int column; + private SqlReader(SqlDataReader sqlDataReader) => this.sqlDataReader = sqlDataReader; @@ -18,9 +20,10 @@ this.sqlDataReader.Dispose(); } - public byte[] GetBytes(int index) + public byte[] GetBytes(int index = -1) { var bytes = default(byte[]); + index = Math.Max(index, this.column++); if (!this.sqlDataReader.IsDBNull(index)) { @@ -30,8 +33,10 @@ return bytes ?? Array.Empty(); } - public string GetString(int index) + public string GetString(int index = -1) { + index = Math.Max(index, this.column++); + if (!this.sqlDataReader.IsDBNull(index)) { return $"{this.sqlDataReader.GetValue(index)}"; @@ -40,8 +45,10 @@ return default(string); } - public T GetValue(int index) + public T GetValue(int index = -1) { + index = Math.Max(index, this.column++); + if (!this.sqlDataReader.IsDBNull(index)) { if (this.sqlDataReader.GetValue(index) is T value) @@ -54,7 +61,11 @@ } internal bool Read() - => this.sqlDataReader.Read(); + { + this.column = 0; + + return this.sqlDataReader.Read(); + } public static implicit operator SqlReader(SqlDataReader sqlDataReader) => new SqlReader(sqlDataReader); diff --git a/LaaProductionWeb/LaaProductionWeb.Services/AccountService.cs b/LaaProductionWeb/LaaProductionWeb.Services/AccountService.cs index 6cfc6327..75f8f836 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/AccountService.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/AccountService.cs @@ -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 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 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 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)} diff --git a/LaaProductionWeb/LaaProductionWeb.Services/ApprovalsService.cs b/LaaProductionWeb/LaaProductionWeb.Services/ApprovalsService.cs new file mode 100644 index 00000000..40c2e8ed --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb.Services/ApprovalsService.cs @@ -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; + } + } +} diff --git a/LaaProductionWeb/LaaProductionWeb.Services/Interfaces/IApprovalsService.cs b/LaaProductionWeb/LaaProductionWeb.Services/Interfaces/IApprovalsService.cs new file mode 100644 index 00000000..ca668bc6 --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb.Services/Interfaces/IApprovalsService.cs @@ -0,0 +1,9 @@ +namespace LaaProductionWeb.Services.Interfaces +{ + using LaaProductionWeb.Services.Models; + + public interface IApprovalsService : ITransient + { + Result Add(ProductionApproval approval); + } +} diff --git a/LaaProductionWeb/LaaProductionWeb.Services/LaaProductionWeb.Services.csproj b/LaaProductionWeb/LaaProductionWeb.Services/LaaProductionWeb.Services.csproj index 6f9ca82b..003e5179 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/LaaProductionWeb.Services.csproj +++ b/LaaProductionWeb/LaaProductionWeb.Services/LaaProductionWeb.Services.csproj @@ -58,7 +58,9 @@ + + @@ -72,6 +74,7 @@ + diff --git a/LaaProductionWeb/LaaProductionWeb.Services/Models/ProductionApproval.cs b/LaaProductionWeb/LaaProductionWeb.Services/Models/ProductionApproval.cs new file mode 100644 index 00000000..9bc6b16b --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb.Services/Models/ProductionApproval.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; } + } +} diff --git a/LaaProductionWeb/LaaProductionWeb.Services/Models/Result.cs b/LaaProductionWeb/LaaProductionWeb.Services/Models/Result.cs index 713c9fd7..89e041af 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/Models/Result.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/Models/Result.cs @@ -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; diff --git a/LaaProductionWeb/LaaProductionWeb.Services/OrdersService.cs b/LaaProductionWeb/LaaProductionWeb.Services/OrdersService.cs index d90625cb..4d43b7bd 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/OrdersService.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/OrdersService.cs @@ -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 diff --git a/LaaProductionWeb/LaaProductionWeb.Services/ProtocolService.cs b/LaaProductionWeb/LaaProductionWeb.Services/ProtocolService.cs index 3515b060..2c0ed159 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/ProtocolService.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/ProtocolService.cs @@ -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($@" + => this.dbContext.ExecuteScalar($@" DELETE FROM [File] WHERE [FileId] = @{nameof(fileId)}; DELETE FROM [FilesOrders] @@ -85,7 +85,7 @@ } public IEnumerable> 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> FindOrdersByClient(string clientName) - => this.dbContext.AsEnumerable( + => this.dbContext.ExecuteReader( query: $@" SELECT DISTINCT [APG].[AuftragNr] @@ -124,7 +124,7 @@ value: reader.GetString(1))); public IEnumerable 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( + return this.dbContext.ExecuteScalar( query: $@" INSERT INTO [dbo].[File] ( [FileName] diff --git a/LaaProductionWeb/LaaProductionWeb.Services/ReportService.cs b/LaaProductionWeb/LaaProductionWeb.Services/ReportService.cs index ac2bf336..dfc00e23 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/ReportService.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/ReportService.cs @@ -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 LoadHeliumPressureResults(int testId) - => this.dbContext.AsEnumerable($@" + => this.dbContext.ExecuteReader($@" SELECT [CordonelPressureTestTestPoints_Id] , [CordonelPressureTest_TestPointNr] , CAST([CordonelPressureTest_TestPointResult] AS NUMERIC(9, 8)) diff --git a/LaaProductionWeb/LaaProductionWeb.Services/ShipmentsService.cs b/LaaProductionWeb/LaaProductionWeb.Services/ShipmentsService.cs index e446f055..4827f620 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/ShipmentsService.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/ShipmentsService.cs @@ -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 LoadBatchItems(OrderScanModel model) - => this.dbContext.AsEnumerable( + => this.dbContext.ExecuteReader( query: $@" SELECT DISTINCT [PalettenScan].[ID] -- 0 @@ -156,7 +156,7 @@ } private IEnumerable LoadBatchPositions(OrderScanModel model, string orderNr, string palNr) - => this.dbContext.AsEnumerable($@" + => this.dbContext.ExecuteReader($@" SELECT DISTINCT [Auftrag].[PositionNr] , COUNT(1) diff --git a/LaaProductionWeb/LaaProductionWeb/Controllers/ApprovalsController.cs b/LaaProductionWeb/LaaProductionWeb/Controllers/ApprovalsController.cs new file mode 100644 index 00000000..69d8c44d --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb/Controllers/ApprovalsController.cs @@ -0,0 +1,48 @@ +namespace LaaProductionWeb.Controllers +{ + using LaaProductionWeb.Services.Interfaces; + using LaaProductionWeb.Services.Models; + + using System; + using System.Web.Mvc; + + [Authorize] + public class ApprovalsController : Controller + { + private readonly IApprovalsService approvals; + + public ApprovalsController(IApprovalsService approvals) + => this.approvals = approvals; + + [HttpGet] + public ActionResult Add() + => this.View(new ProductionApproval + { + ApproverName = this.User.Identity.Name, + ApprovalDate = DateTime.Now + }); + + [HttpPost] + public ActionResult Add(ProductionApproval approval) + { + if (this.ModelState.IsValid) + { + approval.ApprovalDate = DateTime.Now; + approval.ApproverName = this.User.Identity.Name; + + var addResult = this.approvals.Add(approval); + + if (addResult) + { + this.TempData["Success"] = (string)addResult; + + return this.RedirectToAction(nameof(this.Add)); + } + + this.TempData["Error"] = (string)addResult; + } + + return this.View(approval); + } + } +} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/LaaProductionWeb.csproj b/LaaProductionWeb/LaaProductionWeb/LaaProductionWeb.csproj index 2e3c0a8a..0ed1cba5 100644 --- a/LaaProductionWeb/LaaProductionWeb/LaaProductionWeb.csproj +++ b/LaaProductionWeb/LaaProductionWeb/LaaProductionWeb.csproj @@ -143,6 +143,7 @@ + @@ -183,6 +184,7 @@ + diff --git a/LaaProductionWeb/LaaProductionWeb/Views/Approvals/Add.cshtml b/LaaProductionWeb/LaaProductionWeb/Views/Approvals/Add.cshtml new file mode 100644 index 00000000..ec6cc15d --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb/Views/Approvals/Add.cshtml @@ -0,0 +1,134 @@ +@model LaaProductionWeb.Services.Models.ProductionApproval + +
+
+
+
+

Neue Genehmigung erstellen

+
+
+
+
+
+
+ @this.Html.TextBoxFor(x => x.OrderNr, new { @class = "form-control", placeholder = "Creator" }) + @this.Html.LabelFor(x => x.OrderNr, labelText: "FertigungsNr") +
+
+
+
+ @this.Html.TextBoxFor(x => x.PcbId, new { @class = "form-control", placeholder = "Creator" }) + @this.Html.LabelFor(x => x.PcbId, labelText: "PcbId") +
+
+
+
+
+
+ @this.Html.TextBoxFor(x => x.OverrideFwCheck, new { @class = "form-control", placeholder = "Creator" }) + @this.Html.LabelFor(x => x.OverrideFwCheck, labelText: "OverrideFwCheck") +
+
+
+
+ @this.Html.TextBoxFor(x => x.OverrideLutCheck, new { @class = "form-control", placeholder = "Creator" }) + @this.Html.LabelFor(x => x.OverrideLutCheck, labelText: "OverrideLutCheck") +
+
+
+
+
+
+ @this.Html.TextBoxFor(x => x.RequiredLifeTimeYearsAssembly, new { @class = "form-control", placeholder = "Creator" }) + @this.Html.LabelFor(x => x.RequiredLifeTimeYearsAssembly, labelText: "RequiredLifeTimeYearsAssembly") +
+
+
+
+ @this.Html.TextBoxFor(x => x.RequiredLifeTimeYearsShipping, new { @class = "form-control", placeholder = "Creator" }) + @this.Html.LabelFor(x => x.RequiredLifeTimeYearsShipping, labelText: "RequiredLifeTimeYearsShipping") +
+
+
+
+
+
+ @this.Html.CheckBoxFor(x => x.SkipRadioCheck, new { @class = "form-check-input", type = "checkbox", role = "switch", @checked = (this.Model.SkipRadioCheck ? "checked" : null) }) + @this.Html.LabelFor(x => x.SkipRadioCheck, labelText: "Überprüfung der Funkparameter überspringen", htmlAttributes: new { @class = "form-check-label" }) +
+
+
+
+ @this.Html.TextBoxFor(x => x.KitronProductionDate, new { @class = "form-control", placeholder = "Creator", type = "date" }) + @this.Html.LabelFor(x => x.KitronProductionDate, labelText: "KitronProductionDate") +
+
+
+
+
+
+ @this.Html.TextBoxFor(x => x.MaxDrainedBatteryLoadPercent, new { @class = "form-control", placeholder = "Creator" }) + @this.Html.LabelFor(x => x.RequiredLifeTimeYearsShipping, labelText: "MaxDrainedBatteryLoadPercent") +
+
+
+
+ @this.Html.TextBoxFor(x => x.MaxStorageMonths, new { @class = "form-control", placeholder = "Creator" }) + @this.Html.LabelFor(x => x.RequiredLifeTimeYearsShipping, labelText: "MaxStorageMonths") +
+
+
+
+
+
+ @this.Html.TextBoxFor(x => x.ApproverName, new { @class = "form-control bg-light border-light", placeholder = "Creator", @readonly = "readonly" }) + @this.Html.LabelFor(x => x.ApproverName, labelText: "Name des Genehmigers") +
+
+
+
+ @this.Html.TextBoxFor(x => x.ApprovalDate, new { @class = "form-control bg-light border-light", placeholder = "Creator", @readonly = "readonly" }) + @this.Html.LabelFor(x => x.ApprovalDate, labelText: "Datum der Genehmigung") +
+
+
+
+
+
+ @this.Html.TextAreaFor(x => x.ApprovalComment, new { @class = "form-control", placeholder = "Creator", style = "height: 210px" }) + @this.Html.LabelFor(x => x.ApprovalComment, labelText: "Genehmigungskommentar") + @this.Html.ValidationMessageFor(x => x.ApprovalComment, string.Empty, new { @class = "small text-danger" }) +
+
+
+
+
+ + @if (this.TempData.TryGetValue("Success", out object message)) + { + + } + else if (this.TempData.TryGetValue("Error", out object error)) + { + + } +
+
+
+
+ + diff --git a/LaaProductionWeb/LaaProductionWeb/Views/Shared/_Layout.cshtml b/LaaProductionWeb/LaaProductionWeb/Views/Shared/_Layout.cshtml index a4474bc5..f8f963eb 100644 --- a/LaaProductionWeb/LaaProductionWeb/Views/Shared/_Layout.cshtml +++ b/LaaProductionWeb/LaaProductionWeb/Views/Shared/_Layout.cshtml @@ -38,6 +38,9 @@ +