diff --git a/LaaProductionWeb/FluentSQL/FluentSQL.cs b/LaaProductionWeb/FluentSQL/FluentSQL.cs deleted file mode 100644 index 419d208e..00000000 --- a/LaaProductionWeb/FluentSQL/FluentSQL.cs +++ /dev/null @@ -1,116 +0,0 @@ -namespace LaaProductionWeb.Data -{ - using LaaProductionWeb.Data.Interfaces; - - using System; - using System.Collections.Generic; - using System.Data; - using System.Data.SqlClient; - using System.Linq; - - public class FluentSQL : IFluentSQL - { - private readonly string connectionString; - - public FluentSQL(string connectionString) - { - connectionString.ThrowIfNullOrWhiteSpace(nameof(connectionString)); - - var connectionStringBuilder = new SqlConnectionStringBuilder(connectionString); - - this.connectionString = connectionStringBuilder.ToString(); - } - - public FluentSQLCommand CreateCommand(string commandText) - => new FluentSQLCommand(this, commandText); - - internal int ExecuteNonQuery(FluentSQLCommand command) - { - command.ThrowIfNull(nameof(command)); - - var rowsAffected = 0; - - using (var sqlConnection = new SqlConnection(this.connectionString)) - { - sqlConnection.OpenWithErrorHandling(); - - using (var sqlCommand = sqlConnection.CreateCommand()) - { - sqlCommand.CommandText = command.CommandText; - - sqlCommand.Parameters.AddRange(command.Parameters); - - rowsAffected = sqlCommand.ExecuteNonQuery(); - - sqlCommand.Parameters.Clear(); - } - } - - return rowsAffected; - } - - internal IEnumerable ExecuteReader(FluentSQLCommand command, Func expression) - { - command.ThrowIfNull(nameof(command)); - expression.ThrowIfNull(nameof(expression)); - - using (var sqlConnection = new SqlConnection(this.connectionString)) - { - sqlConnection.OpenWithErrorHandling(); - - using (var sqlCommand = sqlConnection.CreateCommand()) - { - sqlCommand.CommandText = command.CommandText; - - sqlCommand.Parameters.AddRange(command.Parameters); - - using (FluentSQLReader sqlReader = sqlCommand.ExecuteReader(CommandBehavior.SequentialAccess)) - { - sqlCommand.Parameters.Clear(); - - while (sqlReader.Read()) - { - yield return expression(sqlReader); - } - } - } - } - } - - internal T ExecuteScalar(FluentSQLCommand command, Func expression) - { - command.ThrowIfNull(nameof(command)); - expression.ThrowIfNull(nameof(expression)); - - var scalarResult = default(T); - - using (var sqlConnection = new SqlConnection(this.connectionString)) - { - sqlConnection.OpenWithErrorHandling(); - - using (var sqlCommand = sqlConnection.CreateCommand()) - { - sqlCommand.CommandText = command.CommandText; - - sqlCommand.Parameters.AddRange(command.Parameters); - - var scalarObject = sqlCommand.ExecuteScalar(); - - sqlCommand.Parameters.Clear(); - - if (scalarObject is T scalarValue) - { - scalarResult = scalarValue; - } - } - } - - return scalarResult; - } - - internal T FirstOrDefault(FluentSQLCommand command, Func expression) - => this - .ExecuteReader(command, expression) - .FirstOrDefault(); - } -} diff --git a/LaaProductionWeb/FluentSQL/FluentSQL.csproj b/LaaProductionWeb/FluentSQL/FluentSQL.csproj deleted file mode 100644 index 24dae94f..00000000 --- a/LaaProductionWeb/FluentSQL/FluentSQL.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - netstandard2.0 - - - - - - - diff --git a/LaaProductionWeb/FluentSQL/FluentSQLCommand.cs b/LaaProductionWeb/FluentSQL/FluentSQLCommand.cs deleted file mode 100644 index 39c93cdc..00000000 --- a/LaaProductionWeb/FluentSQL/FluentSQLCommand.cs +++ /dev/null @@ -1,65 +0,0 @@ -namespace LaaProductionWeb.Data -{ - using LaaProductionWeb.Data.Interfaces; - - using System; - using System.Collections.Generic; - using System.Data.SqlClient; - using System.Linq; - - public class FluentSQLCommand : IFluentSQLCommand - { - private readonly FluentSQL fluentSql; - private readonly IDictionary parameters; - - public FluentSQLCommand(FluentSQL fluentSql, string commandText) - { - this.fluentSql = fluentSql.EnsureNotNull(nameof(fluentSql)); - this.CommandText = commandText.EnsureNotNullOrWhiteSpace(nameof(commandText)); - this.parameters = new Dictionary(); - } - - internal string CommandText { get; } - - internal SqlParameter[] Parameters - => this.parameters.Values.ToArray(); - - public int ExecuteNonQuery() - => this.fluentSql.ExecuteNonQuery(this); - - public IEnumerable ExecuteReader(Func expression) - => this.fluentSql.ExecuteReader(this, expression); - - public T ExecuteScalar(Func expression) - => this.fluentSql.ExecuteScalar(this, expression); - - public T FirstOrDefault(Func expression) - => this.fluentSql.FirstOrDefault(this, expression); - - public IFluentSQLCommand SetParameter(string name, object value) - { - name.ThrowIfNullOrWhiteSpace(nameof(name)); - - if (value is null) - { - value = DBNull.Value; - } - - var parameter = new SqlParameter(name, value); - - this.parameters[name] = parameter; - - return this; - } - - public IFluentSQLCommand SetParameters(IEnumerable> parameters) - { - foreach (var kvp in parameters) - { - this.SetParameter(kvp.Key, kvp.Value); - } - - return this; - } - } -} diff --git a/LaaProductionWeb/FluentSQL/FluentSQLExtensions.cs b/LaaProductionWeb/FluentSQL/FluentSQLExtensions.cs deleted file mode 100644 index ad5457c1..00000000 --- a/LaaProductionWeb/FluentSQL/FluentSQLExtensions.cs +++ /dev/null @@ -1,54 +0,0 @@ -namespace LaaProductionWeb.Data -{ - using System; - using System.Data.SqlClient; - using System.Runtime.CompilerServices; - - internal static class FluentSQLExtensions - { - public static T EnsureNotNull(this T value, [CallerMemberName] string memberName = "") - { - value.ThrowIfNull(memberName); - - return value; - } - - public static string EnsureNotNullOrWhiteSpace(this string value, [CallerMemberName] string memberName = "") - { - value.ThrowIfNullOrWhiteSpace(memberName); - - return value; - } - - public static void ThrowIfNull(this T value, [CallerMemberName] string memberName = "") - { - if (value == null) - { - throw new ArgumentException($"{memberName} should not be null.", memberName); - } - } - - public static void ThrowIfNullOrWhiteSpace(this string value, [CallerMemberName] string memberName = "") - { - if (string.IsNullOrWhiteSpace(value)) - { - throw new ArgumentException($"{memberName} should not be null or white space.", memberName); - } - } - - internal static void OpenWithErrorHandling(this SqlConnection sqlConnection) - { - sqlConnection.ThrowIfNull(nameof(sqlConnection)); - - sqlConnection.FireInfoMessageEventOnUserErrors = true; - sqlConnection.InfoMessage += SqlConnectionInfoMessage; - - sqlConnection.Open(); - } - - internal static void SqlConnectionInfoMessage(object sender, SqlInfoMessageEventArgs e) - { - // TODO: Log error message to the caller or elsewhere. - } - } -} diff --git a/LaaProductionWeb/FluentSQL/FluentSQLReader.cs b/LaaProductionWeb/FluentSQL/FluentSQLReader.cs deleted file mode 100644 index 02b565b1..00000000 --- a/LaaProductionWeb/FluentSQL/FluentSQLReader.cs +++ /dev/null @@ -1,151 +0,0 @@ -namespace LaaProductionWeb.Data -{ - using LaaProductionWeb.Data.Interfaces; - - using System; - using System.Data.SqlClient; - - public class FluentSQLReader : IFluentSQLReader, IDisposable - { - private readonly SqlDataReader sqlDataReader; - - private int index; - - private FluentSQLReader(SqlDataReader sqlDataReader) - => this.sqlDataReader = sqlDataReader.EnsureNotNull(nameof(sqlDataReader)); - - public void Dispose() - { - this.sqlDataReader.Close(); - this.sqlDataReader.Dispose(); - } - - public bool GetBool() - { - this.index++; - - if (!this.sqlDataReader.IsDBNull(this.index)) - { - return this.sqlDataReader.GetBoolean(this.index); - } - - return default(bool); - } - - public byte[] GetBytes() - { - this.index++; - - var bytes = default(byte[]); - - if (!this.sqlDataReader.IsDBNull(this.index)) - { - bytes = this.sqlDataReader.GetFieldValue(0); - } - - return bytes ?? Array.Empty(); - } - - public DateTime GetDate() - { - this.index++; - - if (!this.sqlDataReader.IsDBNull(this.index)) - { - return this.sqlDataReader.GetDateTime(this.index); - } - - return default(DateTime); - } - - public int GetInt() - { - this.index++; - - if (!this.sqlDataReader.IsDBNull(this.index)) - { - return this.sqlDataReader.GetInt32(this.index); - } - - return default(int); - } - - public long GetLong() - { - this.index++; - - if (!this.sqlDataReader.IsDBNull(this.index)) - { - return this.sqlDataReader.GetInt64(this.index); - } - - return default(long); - } - - public short GetSmallint() - { - this.index++; - - if (!this.sqlDataReader.IsDBNull(this.index)) - { - return this.sqlDataReader.GetInt16(this.index); - } - - return default(short); - } - - public string GetString() - { - this.index++; - - if (!this.sqlDataReader.IsDBNull(this.index)) - { - return $"{this.sqlDataReader.GetValue(this.index)}"; - } - - return default(string); - } - - public T GetValue() - { - this.index++; - - if (!this.sqlDataReader.IsDBNull(this.index)) - { - if (this.sqlDataReader.GetValue(this.index) is T value) - { - return value; - } - } - - return default(T); - } - - public object GetValue(string column) - { - column.EnsureNotNullOrWhiteSpace(nameof(column)); - - var colIndex = this.sqlDataReader.GetOrdinal(column); - - if (colIndex >= 0 && colIndex < this.sqlDataReader.FieldCount) - { - if (!this.sqlDataReader.IsDBNull(this.index)) - { - return this.sqlDataReader.GetValue(this.index); - } - } - - return default(object); - } - - internal bool Read() - { - this.index = -1; - - return this.sqlDataReader.Read(); - } - - public static implicit operator FluentSQLReader(SqlDataReader sqlDataReader) - => new FluentSQLReader(sqlDataReader); - } -} \ No newline at end of file diff --git a/LaaProductionWeb/FluentSQL/Interfaces/IFluentSQL.cs b/LaaProductionWeb/FluentSQL/Interfaces/IFluentSQL.cs deleted file mode 100644 index 4b2de335..00000000 --- a/LaaProductionWeb/FluentSQL/Interfaces/IFluentSQL.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace LaaProductionWeb.Data.Interfaces -{ - public interface IFluentSQL - { - FluentSQLCommand CreateCommand(string commandText); - } -} diff --git a/LaaProductionWeb/FluentSQL/Interfaces/IFluentSQLCommand.cs b/LaaProductionWeb/FluentSQL/Interfaces/IFluentSQLCommand.cs deleted file mode 100644 index f44451fb..00000000 --- a/LaaProductionWeb/FluentSQL/Interfaces/IFluentSQLCommand.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace LaaProductionWeb.Data.Interfaces -{ - using System; - using System.Collections.Generic; - - public interface IFluentSQLCommand - { - int ExecuteNonQuery(); - - IEnumerable ExecuteReader(Func expression); - - T ExecuteScalar(Func expression); - - T FirstOrDefault(Func expression); - - IFluentSQLCommand SetParameter(string name, object value); - - IFluentSQLCommand SetParameters(IEnumerable> parameters); - } -} diff --git a/LaaProductionWeb/FluentSQL/Interfaces/IFluentSQLReader.cs b/LaaProductionWeb/FluentSQL/Interfaces/IFluentSQLReader.cs deleted file mode 100644 index be11cea0..00000000 --- a/LaaProductionWeb/FluentSQL/Interfaces/IFluentSQLReader.cs +++ /dev/null @@ -1,25 +0,0 @@ -namespace LaaProductionWeb.Data.Interfaces -{ - using System; - - public interface IFluentSQLReader - { - bool GetBool(); - - byte[] GetBytes(); - - DateTime GetDate(); - - int GetInt(); - - long GetLong(); - - short GetSmallint(); - - string GetString(); - - T GetValue(); - - object GetValue(string column); - } -} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb.Data/FluentSQL.cs b/LaaProductionWeb/LaaProductionWeb.Data/FluentSQL.cs deleted file mode 100644 index 419d208e..00000000 --- a/LaaProductionWeb/LaaProductionWeb.Data/FluentSQL.cs +++ /dev/null @@ -1,116 +0,0 @@ -namespace LaaProductionWeb.Data -{ - using LaaProductionWeb.Data.Interfaces; - - using System; - using System.Collections.Generic; - using System.Data; - using System.Data.SqlClient; - using System.Linq; - - public class FluentSQL : IFluentSQL - { - private readonly string connectionString; - - public FluentSQL(string connectionString) - { - connectionString.ThrowIfNullOrWhiteSpace(nameof(connectionString)); - - var connectionStringBuilder = new SqlConnectionStringBuilder(connectionString); - - this.connectionString = connectionStringBuilder.ToString(); - } - - public FluentSQLCommand CreateCommand(string commandText) - => new FluentSQLCommand(this, commandText); - - internal int ExecuteNonQuery(FluentSQLCommand command) - { - command.ThrowIfNull(nameof(command)); - - var rowsAffected = 0; - - using (var sqlConnection = new SqlConnection(this.connectionString)) - { - sqlConnection.OpenWithErrorHandling(); - - using (var sqlCommand = sqlConnection.CreateCommand()) - { - sqlCommand.CommandText = command.CommandText; - - sqlCommand.Parameters.AddRange(command.Parameters); - - rowsAffected = sqlCommand.ExecuteNonQuery(); - - sqlCommand.Parameters.Clear(); - } - } - - return rowsAffected; - } - - internal IEnumerable ExecuteReader(FluentSQLCommand command, Func expression) - { - command.ThrowIfNull(nameof(command)); - expression.ThrowIfNull(nameof(expression)); - - using (var sqlConnection = new SqlConnection(this.connectionString)) - { - sqlConnection.OpenWithErrorHandling(); - - using (var sqlCommand = sqlConnection.CreateCommand()) - { - sqlCommand.CommandText = command.CommandText; - - sqlCommand.Parameters.AddRange(command.Parameters); - - using (FluentSQLReader sqlReader = sqlCommand.ExecuteReader(CommandBehavior.SequentialAccess)) - { - sqlCommand.Parameters.Clear(); - - while (sqlReader.Read()) - { - yield return expression(sqlReader); - } - } - } - } - } - - internal T ExecuteScalar(FluentSQLCommand command, Func expression) - { - command.ThrowIfNull(nameof(command)); - expression.ThrowIfNull(nameof(expression)); - - var scalarResult = default(T); - - using (var sqlConnection = new SqlConnection(this.connectionString)) - { - sqlConnection.OpenWithErrorHandling(); - - using (var sqlCommand = sqlConnection.CreateCommand()) - { - sqlCommand.CommandText = command.CommandText; - - sqlCommand.Parameters.AddRange(command.Parameters); - - var scalarObject = sqlCommand.ExecuteScalar(); - - sqlCommand.Parameters.Clear(); - - if (scalarObject is T scalarValue) - { - scalarResult = scalarValue; - } - } - } - - return scalarResult; - } - - internal T FirstOrDefault(FluentSQLCommand command, Func expression) - => this - .ExecuteReader(command, expression) - .FirstOrDefault(); - } -} diff --git a/LaaProductionWeb/LaaProductionWeb.Data/FluentSQLCommand.cs b/LaaProductionWeb/LaaProductionWeb.Data/FluentSQLCommand.cs deleted file mode 100644 index 39c93cdc..00000000 --- a/LaaProductionWeb/LaaProductionWeb.Data/FluentSQLCommand.cs +++ /dev/null @@ -1,65 +0,0 @@ -namespace LaaProductionWeb.Data -{ - using LaaProductionWeb.Data.Interfaces; - - using System; - using System.Collections.Generic; - using System.Data.SqlClient; - using System.Linq; - - public class FluentSQLCommand : IFluentSQLCommand - { - private readonly FluentSQL fluentSql; - private readonly IDictionary parameters; - - public FluentSQLCommand(FluentSQL fluentSql, string commandText) - { - this.fluentSql = fluentSql.EnsureNotNull(nameof(fluentSql)); - this.CommandText = commandText.EnsureNotNullOrWhiteSpace(nameof(commandText)); - this.parameters = new Dictionary(); - } - - internal string CommandText { get; } - - internal SqlParameter[] Parameters - => this.parameters.Values.ToArray(); - - public int ExecuteNonQuery() - => this.fluentSql.ExecuteNonQuery(this); - - public IEnumerable ExecuteReader(Func expression) - => this.fluentSql.ExecuteReader(this, expression); - - public T ExecuteScalar(Func expression) - => this.fluentSql.ExecuteScalar(this, expression); - - public T FirstOrDefault(Func expression) - => this.fluentSql.FirstOrDefault(this, expression); - - public IFluentSQLCommand SetParameter(string name, object value) - { - name.ThrowIfNullOrWhiteSpace(nameof(name)); - - if (value is null) - { - value = DBNull.Value; - } - - var parameter = new SqlParameter(name, value); - - this.parameters[name] = parameter; - - return this; - } - - public IFluentSQLCommand SetParameters(IEnumerable> parameters) - { - foreach (var kvp in parameters) - { - this.SetParameter(kvp.Key, kvp.Value); - } - - return this; - } - } -} diff --git a/LaaProductionWeb/LaaProductionWeb.Data/FluentSQLExtensions.cs b/LaaProductionWeb/LaaProductionWeb.Data/FluentSQLExtensions.cs deleted file mode 100644 index ad5457c1..00000000 --- a/LaaProductionWeb/LaaProductionWeb.Data/FluentSQLExtensions.cs +++ /dev/null @@ -1,54 +0,0 @@ -namespace LaaProductionWeb.Data -{ - using System; - using System.Data.SqlClient; - using System.Runtime.CompilerServices; - - internal static class FluentSQLExtensions - { - public static T EnsureNotNull(this T value, [CallerMemberName] string memberName = "") - { - value.ThrowIfNull(memberName); - - return value; - } - - public static string EnsureNotNullOrWhiteSpace(this string value, [CallerMemberName] string memberName = "") - { - value.ThrowIfNullOrWhiteSpace(memberName); - - return value; - } - - public static void ThrowIfNull(this T value, [CallerMemberName] string memberName = "") - { - if (value == null) - { - throw new ArgumentException($"{memberName} should not be null.", memberName); - } - } - - public static void ThrowIfNullOrWhiteSpace(this string value, [CallerMemberName] string memberName = "") - { - if (string.IsNullOrWhiteSpace(value)) - { - throw new ArgumentException($"{memberName} should not be null or white space.", memberName); - } - } - - internal static void OpenWithErrorHandling(this SqlConnection sqlConnection) - { - sqlConnection.ThrowIfNull(nameof(sqlConnection)); - - sqlConnection.FireInfoMessageEventOnUserErrors = true; - sqlConnection.InfoMessage += SqlConnectionInfoMessage; - - sqlConnection.Open(); - } - - internal static void SqlConnectionInfoMessage(object sender, SqlInfoMessageEventArgs e) - { - // TODO: Log error message to the caller or elsewhere. - } - } -} diff --git a/LaaProductionWeb/LaaProductionWeb.Data/FluentSQLReader.cs b/LaaProductionWeb/LaaProductionWeb.Data/FluentSQLReader.cs deleted file mode 100644 index 02b565b1..00000000 --- a/LaaProductionWeb/LaaProductionWeb.Data/FluentSQLReader.cs +++ /dev/null @@ -1,151 +0,0 @@ -namespace LaaProductionWeb.Data -{ - using LaaProductionWeb.Data.Interfaces; - - using System; - using System.Data.SqlClient; - - public class FluentSQLReader : IFluentSQLReader, IDisposable - { - private readonly SqlDataReader sqlDataReader; - - private int index; - - private FluentSQLReader(SqlDataReader sqlDataReader) - => this.sqlDataReader = sqlDataReader.EnsureNotNull(nameof(sqlDataReader)); - - public void Dispose() - { - this.sqlDataReader.Close(); - this.sqlDataReader.Dispose(); - } - - public bool GetBool() - { - this.index++; - - if (!this.sqlDataReader.IsDBNull(this.index)) - { - return this.sqlDataReader.GetBoolean(this.index); - } - - return default(bool); - } - - public byte[] GetBytes() - { - this.index++; - - var bytes = default(byte[]); - - if (!this.sqlDataReader.IsDBNull(this.index)) - { - bytes = this.sqlDataReader.GetFieldValue(0); - } - - return bytes ?? Array.Empty(); - } - - public DateTime GetDate() - { - this.index++; - - if (!this.sqlDataReader.IsDBNull(this.index)) - { - return this.sqlDataReader.GetDateTime(this.index); - } - - return default(DateTime); - } - - public int GetInt() - { - this.index++; - - if (!this.sqlDataReader.IsDBNull(this.index)) - { - return this.sqlDataReader.GetInt32(this.index); - } - - return default(int); - } - - public long GetLong() - { - this.index++; - - if (!this.sqlDataReader.IsDBNull(this.index)) - { - return this.sqlDataReader.GetInt64(this.index); - } - - return default(long); - } - - public short GetSmallint() - { - this.index++; - - if (!this.sqlDataReader.IsDBNull(this.index)) - { - return this.sqlDataReader.GetInt16(this.index); - } - - return default(short); - } - - public string GetString() - { - this.index++; - - if (!this.sqlDataReader.IsDBNull(this.index)) - { - return $"{this.sqlDataReader.GetValue(this.index)}"; - } - - return default(string); - } - - public T GetValue() - { - this.index++; - - if (!this.sqlDataReader.IsDBNull(this.index)) - { - if (this.sqlDataReader.GetValue(this.index) is T value) - { - return value; - } - } - - return default(T); - } - - public object GetValue(string column) - { - column.EnsureNotNullOrWhiteSpace(nameof(column)); - - var colIndex = this.sqlDataReader.GetOrdinal(column); - - if (colIndex >= 0 && colIndex < this.sqlDataReader.FieldCount) - { - if (!this.sqlDataReader.IsDBNull(this.index)) - { - return this.sqlDataReader.GetValue(this.index); - } - } - - return default(object); - } - - internal bool Read() - { - this.index = -1; - - return this.sqlDataReader.Read(); - } - - public static implicit operator FluentSQLReader(SqlDataReader sqlDataReader) - => new FluentSQLReader(sqlDataReader); - } -} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/IFluentSQL.cs b/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/IFluentSQL.cs deleted file mode 100644 index 4b2de335..00000000 --- a/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/IFluentSQL.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace LaaProductionWeb.Data.Interfaces -{ - public interface IFluentSQL - { - FluentSQLCommand CreateCommand(string commandText); - } -} diff --git a/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/IFluentSQLCommand.cs b/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/IFluentSQLCommand.cs deleted file mode 100644 index f44451fb..00000000 --- a/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/IFluentSQLCommand.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace LaaProductionWeb.Data.Interfaces -{ - using System; - using System.Collections.Generic; - - public interface IFluentSQLCommand - { - int ExecuteNonQuery(); - - IEnumerable ExecuteReader(Func expression); - - T ExecuteScalar(Func expression); - - T FirstOrDefault(Func expression); - - IFluentSQLCommand SetParameter(string name, object value); - - IFluentSQLCommand SetParameters(IEnumerable> parameters); - } -} diff --git a/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/IFluentSQLReader.cs b/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/IFluentSQLReader.cs deleted file mode 100644 index be11cea0..00000000 --- a/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/IFluentSQLReader.cs +++ /dev/null @@ -1,25 +0,0 @@ -namespace LaaProductionWeb.Data.Interfaces -{ - using System; - - public interface IFluentSQLReader - { - bool GetBool(); - - byte[] GetBytes(); - - DateTime GetDate(); - - int GetInt(); - - long GetLong(); - - short GetSmallint(); - - string GetString(); - - T GetValue(); - - object GetValue(string column); - } -} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb.Data/LaaProductionWeb.Data.csproj b/LaaProductionWeb/LaaProductionWeb.Data/LaaProductionWeb.Data.csproj deleted file mode 100644 index e5ab81b7..00000000 --- a/LaaProductionWeb/LaaProductionWeb.Data/LaaProductionWeb.Data.csproj +++ /dev/null @@ -1,54 +0,0 @@ - - - - - Debug - AnyCPU - {4B5BF112-D3BE-4E84-9A8E-74A0E314BBA7} - Library - Properties - LaaProductionWeb.Data - LaaProductionWeb.Data - v4.8.1 - 512 - true - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb.Data/Properties/AssemblyInfo.cs b/LaaProductionWeb/LaaProductionWeb.Data/Properties/AssemblyInfo.cs deleted file mode 100644 index ec1c0e02..00000000 --- a/LaaProductionWeb/LaaProductionWeb.Data/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("LaaProductionWeb.Data")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("LaaProductionWeb.Data")] -[assembly: AssemblyCopyright("Copyright © 2023")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("4b5bf112-d3be-4e84-9a8e-74a0e314bba7")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/LaaProductionWeb/LaaProductionWeb.Data/app.config b/LaaProductionWeb/LaaProductionWeb.Data/app.config deleted file mode 100644 index bd072565..00000000 --- a/LaaProductionWeb/LaaProductionWeb.Data/app.config +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff --git a/LaaProductionWeb/LaaProductionWeb.Services/AccountService.cs b/LaaProductionWeb/LaaProductionWeb.Services/AccountService.cs index 5f72c369..a5e882e7 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/AccountService.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/AccountService.cs @@ -12,9 +12,9 @@ public class AccountService : IAccountService { - private readonly IFluentSQL sqlClient; + private readonly IFluentSQLConnection sqlClient; - public AccountService(IFluentSQL sqlClient) + public AccountService(IFluentSQLConnection sqlClient) => this.sqlClient = sqlClient; public Employee FindEmployee(short userId) diff --git a/LaaProductionWeb/LaaProductionWeb.Services/ApprovalsService.cs b/LaaProductionWeb/LaaProductionWeb.Services/ApprovalsService.cs index 50698906..9d057f8f 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/ApprovalsService.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/ApprovalsService.cs @@ -7,9 +7,9 @@ public class ApprovalsService : IApprovalsService { - private readonly IFluentSQL fluentSQL; + private readonly IFluentSQLConnection fluentSQL; - public ApprovalsService(IFluentSQL fluentSQL) + public ApprovalsService(IFluentSQLConnection fluentSQL) => this.fluentSQL = fluentSQL; public Result Add(ProductionApproval approval) diff --git a/LaaProductionWeb/LaaProductionWeb.Services/Interfaces/ISearchService.cs b/LaaProductionWeb/LaaProductionWeb.Services/Interfaces/ISearchService.cs new file mode 100644 index 00000000..5f36499a --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb.Services/Interfaces/ISearchService.cs @@ -0,0 +1,13 @@ +namespace LaaProductionWeb.Services.Interfaces +{ + using LaaProductionWeb.Services.Models; + + using System.Collections.Generic; + + public interface ISearchService + { + IEnumerable Find(WildcardInputModel model); + + IEnumerable Options(); + } +} diff --git a/LaaProductionWeb/LaaProductionWeb.Services/LaaProductionWeb.Services.csproj b/LaaProductionWeb/LaaProductionWeb.Services/LaaProductionWeb.Services.csproj index 8780c34d..adac8ba8 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/LaaProductionWeb.Services.csproj +++ b/LaaProductionWeb/LaaProductionWeb.Services/LaaProductionWeb.Services.csproj @@ -13,6 +13,8 @@ 512 true + + true @@ -32,8 +34,8 @@ 4 - - ..\packages\FluentSQL.1.0.0\lib\netstandard2.0\FluentSQL.dll + + ..\packages\FluentSQLClient.1.0.0\lib\netstandard2.0\FluentSQLClient.dll False @@ -42,17 +44,11 @@ - ..\packages\System.Data.SqlClient.4.8.5\lib\net461\System.Data.SqlClient.dll - - ..\packages\System.Net.Http.4.3.4\lib\net46\System.Net.Http.dll - True - True - - + @@ -67,6 +63,7 @@ + @@ -101,6 +98,8 @@ + + @@ -115,6 +114,7 @@ + diff --git a/LaaProductionWeb/LaaProductionWeb.Services/LoggerService.cs b/LaaProductionWeb/LaaProductionWeb.Services/LoggerService.cs index e70c2409..082b2785 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/LoggerService.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/LoggerService.cs @@ -8,9 +8,9 @@ public class LoggerService : ILoggerService { - private readonly IFluentSQL fluentSQL; + private readonly IFluentSQLConnection fluentSQL; - public LoggerService(IFluentSQL fluentSQL) + public LoggerService(IFluentSQLConnection fluentSQL) => this.fluentSQL = fluentSQL; public class Actions diff --git a/LaaProductionWeb/LaaProductionWeb.Services/Models/Search/WildcardInputModel.cs b/LaaProductionWeb/LaaProductionWeb.Services/Models/Search/WildcardInputModel.cs new file mode 100644 index 00000000..2f5e8ba6 --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb.Services/Models/Search/WildcardInputModel.cs @@ -0,0 +1,38 @@ +namespace LaaProductionWeb.Services.Models +{ + using System; + using System.Collections.Generic; + using System.ComponentModel.DataAnnotations; + using System.Linq; + + public class WildcardInputModel + { + private string token; + private IEnumerable fields = Array.Empty(); + + [Required] + [StringLength(50, MinimumLength = 1)] + [RegularExpression("^[0-9 a-z-A-Z]+$")] + public string Token + { + get => this.token; + set => this.token = value?.Replace(" ", "")?.Trim(); + } + + public string Fields + { + get => string.Join(",", this.fields); + set => this.fields = $"{value}".Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + } + + internal IEnumerable GetRequiredFields(IEnumerable allFields) + { + if (this.fields.Any()) + { + return allFields.Where(x => this.fields.Contains(x, StringComparer.OrdinalIgnoreCase)); + } + + return allFields; + } + } +} diff --git a/LaaProductionWeb/LaaProductionWeb.Services/Models/Search/WildcardResult.cs b/LaaProductionWeb/LaaProductionWeb.Services/Models/Search/WildcardResult.cs new file mode 100644 index 00000000..2d5029f4 --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb.Services/Models/Search/WildcardResult.cs @@ -0,0 +1,8 @@ +namespace LaaProductionWeb.Services.Models +{ + using System.Collections.Generic; + + public class WildcardResult : Dictionary + { + } +} diff --git a/LaaProductionWeb/LaaProductionWeb.Services/OrdersService.cs b/LaaProductionWeb/LaaProductionWeb.Services/OrdersService.cs index 1d9cbda1..beb09e9a 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/OrdersService.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/OrdersService.cs @@ -7,9 +7,9 @@ public class OrdersService : IOrdersService { - private readonly IFluentSQL sqlClient; + private readonly IFluentSQLConnection sqlClient; - public OrdersService(IFluentSQL sqlClient) + public OrdersService(IFluentSQLConnection sqlClient) => this.sqlClient = sqlClient; public OrdersFoundModel FindOrders(string search) diff --git a/LaaProductionWeb/LaaProductionWeb.Services/ProtocolService.cs b/LaaProductionWeb/LaaProductionWeb.Services/ProtocolService.cs index 327c408c..f8488ec9 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/ProtocolService.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/ProtocolService.cs @@ -13,9 +13,9 @@ public class ProtocolService : IProtocolService { - private readonly IFluentSQL fluentSQL; + private readonly IFluentSQLConnection fluentSQL; - public ProtocolService(IFluentSQL fluentSQL) + public ProtocolService(IFluentSQLConnection fluentSQL) => this.fluentSQL = fluentSQL; public bool DeleteFile(int fileId) diff --git a/LaaProductionWeb/LaaProductionWeb.Services/ReportService.cs b/LaaProductionWeb/LaaProductionWeb.Services/ReportService.cs index a4199d97..21dce32c 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/ReportService.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/ReportService.cs @@ -12,9 +12,9 @@ public partial class ReportService : IReportService { - private readonly IFluentSQL fluentSQL; + private readonly IFluentSQLConnection fluentSQL; - public ReportService(IFluentSQL fluentSQL) + public ReportService(IFluentSQLConnection fluentSQL) => this.fluentSQL = fluentSQL; public CordonelPressureSensorModel LoadCordonelPressureSensorReport(CordonelPressureSensorModel model = null) diff --git a/LaaProductionWeb/LaaProductionWeb.Services/SearchService.cs b/LaaProductionWeb/LaaProductionWeb.Services/SearchService.cs new file mode 100644 index 00000000..9f11d844 --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb.Services/SearchService.cs @@ -0,0 +1,131 @@ +namespace LaaProductionWeb.Services +{ + using FluentSQLClient.Interfaces; + + using LaaProductionWeb.Services.Models; + using LaaProductionWeb.Services.Interfaces; + + using System.Collections.Generic; + + public class SearchService : ISearchService + { + private readonly IFluentSQLConnection fluentSQLClient; + + public SearchService(IFluentSQLConnection fluentSQLClient) + => this.fluentSQLClient = fluentSQLClient; + + public IEnumerable Find(WildcardInputModel model) + { + var requiredFields = model.GetRequiredFields(this.Options()); + var ordersFound = fluentSQLClient + .CreateCommand($@" + DECLARE @serienNr TABLE([Nr] VARCHAR(50)); + ----------------------------------------------------------------------------- + -- 1. LOOK FOR SERIAL NUMBER ------------------------------------------------ + ----------------------------------------------------------------------------- + INSERT INTO @serienNr + SELECT [APS].[SerienNr] + FROM [AuftragPositionSerienNr] AS [APS] + WHERE [APS].[SerienNr] LIKE @{nameof(model.Token)} + OR [APS].[KundeneigeneSerienNr] LIKE @{nameof(model.Token)} + OR REPLACE([APS].[KundeneigeneSerienNr], ' ', '') LIKE @{nameof(model.Token)}; + ----------------------------------------------------------------------------- + -- 2. LOOK FOR PCB NUMBER --------------------------------------------------- + ----------------------------------------------------------------------------- + INSERT INTO @serienNr + SELECT [PCBS].[MapPcbIdToSerialNumber_SerialNumber] + FROM [MapPcbIdToSerialNumber] AS [PCBS] + WHERE [PCBS].[MapPcbIdToSerialNumber_PcbId] LIKE @{nameof(model.Token)}; + ----------------------------------------------------------------------------- + -- 3. LOOK FOR FUNK ADDRESS E-REGISTER -------------------------------------- + ----------------------------------------------------------------------------- + INSERT INTO @serienNr + SELECT [ER].[Seriennummer] + FROM [eRegister] AS [ER] + WHERE [ER].[Adresse] LIKE @{nameof(model.Token)}; + ----------------------------------------------------------------------------- + -- 4. LOOK FOR FUNK ADDRESS GENESIS ----------------------------------------- + ----------------------------------------------------------------------------- + INSERT INTO @serienNr + SELECT [GM].[Seriennummer] + FROM [Genesis_Meter] AS [GM] + WHERE [GM].[Adresse] LIKE @{nameof(model.Token)}; + ----------------------------------------------------------------------------- + -- 5. TAKE ORDERS INFO ------------------------------------------------------ + ----------------------------------------------------------------------------- + SELECT DISTINCT + [KN].[KundenNr] AS [CustomerNo] + , [KN].[Name] AS [Customer] + , [AP].[FertigungsauftragNr] AS [ProductionOrderNo] + , [APS].[AuftragNr] AS [CustomerOrderNo] + , [APS].[PositionNr] AS [PosNo] + , [APS].[SerienNr] AS [SerialNo] + , [APS].[KundeneigeneSerienNr] AS [CustomerSerialNo] + , [IDN].[KurzBez] AS [KurzBez] + , [IDN].[Typ] AS [Typ] + , [IDN].[Nennweite] AS [Nennweite] + , [IDN].[Baulaenge] AS [Baulaenge] + , [AP].[Menge] AS [Quantity] + , [APS].[FabNr] AS [FabricNo] + , [IDN].[IdentNr] AS [IdentNr] + , [PCBS].[MapPcbIdToSerialNumber_PcbId] AS [PcbId] + , [ER].[Adresse] AS [ErRadioAddress] + , [GM].[Adresse] AS [GmRadioAddress] + FROM [AuftragPositionSerienNr] AS [APS] + LEFT JOIN [AuftragPosition_Gesamt] AS [AP] + ON [AP].[AuftragNr] = [APS].[AuftragNr] + AND [AP].[PositionNr] = [APS].[PositionNr] + LEFT JOIN [Auftrag_Gesamt] AS [AG] + ON [AG].[AuftragNr] = [APS].[AuftragNr] + LEFT JOIN [Kunde] AS [KN] + ON [KN].[KundenNr] = [AG].[KundenNr] + LEFT JOIN [Identnr] AS [IDN] + ON [IDN].[IdentNr] = [AP].[Identnr] + LEFT JOIN [MapPcbIdToSerialNumber] AS [PCBS] + ON [PCBS].[MapPcbIdToSerialNumber_SerialNumber] = [APS].[SerienNr] + LEFT JOIN [eRegister] AS [ER] + ON [ER].[Seriennummer] = [APS].[SerienNr] + LEFT JOIN [Genesis_Meter] AS [GM] + ON [GM].[Seriennummer] = [APS].[SerienNr] + WHERE [APS].[SerienNr] IN (SELECT [Nr] FROM @serienNr)") + .SetParameter(nameof(model.Token), model.Token) + .ExecuteReader(reader => this.ToWildcardResult(reader, requiredFields)); + + return ordersFound; + } + + public IEnumerable Options() + => new string[] + { + "CustomerNo", + "Customer", + "ProductionOrderNo", + "CustomerOrderNo", + "PosNo", + "SerialNo", + "CustomerSerialNo", + "KurzBez", + "Typ", + "Nennweite", + "Baulaenge", + "Quantity", + "FabricNo", + "IdentNr", + "PcbId", + "ErRadioAddress", + "GmRadioAddress", + }; + + internal WildcardResult ToWildcardResult(IFluentSQLReader reader, IEnumerable fields) + { + var wildcardResult = new WildcardResult(); + + foreach (var field in fields) + { + wildcardResult[field] = reader.GetValue(field); + } + + return wildcardResult; + } + } +} diff --git a/LaaProductionWeb/LaaProductionWeb.Services/ShipmentsService.cs b/LaaProductionWeb/LaaProductionWeb.Services/ShipmentsService.cs index 35f60989..9bc0bfa5 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/ShipmentsService.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/ShipmentsService.cs @@ -12,9 +12,9 @@ public class ShipmentsService : IShipmentsService { - private readonly IFluentSQL fluentSQL; + private readonly IFluentSQLConnection fluentSQL; - public ShipmentsService(IFluentSQL fluentSQL) + public ShipmentsService(IFluentSQLConnection fluentSQL) => this.fluentSQL = fluentSQL; public OrderScanModel DeletePalletEntry(int id) diff --git a/LaaProductionWeb/LaaProductionWeb.Services/SoftwareService.cs b/LaaProductionWeb/LaaProductionWeb.Services/SoftwareService.cs index 7307ee68..5b79ce24 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/SoftwareService.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/SoftwareService.cs @@ -13,9 +13,9 @@ public class SoftwareService : ISoftwareService { - private readonly IFluentSQL fluentSQL; + private readonly IFluentSQLConnection fluentSQL; - public SoftwareService(IFluentSQL fluentSQL) + public SoftwareService(IFluentSQLConnection fluentSQL) => this.fluentSQL = fluentSQL; public void AddFunction(short appId, string name) diff --git a/LaaProductionWeb/LaaProductionWeb.UnitTests.Data/FluentSQLTestClass.cs b/LaaProductionWeb/LaaProductionWeb.UnitTests.Data/FluentSQLTestClass.cs deleted file mode 100644 index 05db71cf..00000000 --- a/LaaProductionWeb/LaaProductionWeb.UnitTests.Data/FluentSQLTestClass.cs +++ /dev/null @@ -1,29 +0,0 @@ -namespace LaaProductionWeb.UnitTests.Data -{ - using LaaProductionWeb.Data; - - using Microsoft.VisualStudio.TestTools.UnitTesting; - - using System; - using System.Collections.Generic; - - [TestClass] - public class FluentSQLTestClass - { - [TestMethod] - public void Constructor_ShouldThrow_ConnectionString_IsNull() - => Assert.ThrowsException(() => new FluentSQL(null)); - - [TestMethod] - public void Constructor_ShouldThrow_ConnectionString_IsWhiteSpace() - => Assert.ThrowsException(() => new FluentSQL(string.Empty)); - - [TestMethod] - public void Constructor_ShouldThrow_ConnectionString_KeyNotFound() - => Assert.ThrowsException(() => new FluentSQL("invalid connection string")); - - [TestMethod] - public void Constructor_ShouldThrow_ConnectionString_NotWellFormed() - => Assert.ThrowsException(() => new FluentSQL("Invalid Key=123")); - } -} diff --git a/LaaProductionWeb/LaaProductionWeb.UnitTests.Data/LaaProductionWeb.UnitTests.Data.csproj b/LaaProductionWeb/LaaProductionWeb.UnitTests.Data/LaaProductionWeb.UnitTests.Data.csproj deleted file mode 100644 index c209bcf4..00000000 --- a/LaaProductionWeb/LaaProductionWeb.UnitTests.Data/LaaProductionWeb.UnitTests.Data.csproj +++ /dev/null @@ -1,71 +0,0 @@ - - - - - - Debug - AnyCPU - {A14581DD-E1AC-4AB0-9329-B723D24A2F3A} - Library - Properties - LaaProductionWeb.UnitTests.Data - LaaProductionWeb.UnitTests.Data - v4.8.1 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 15.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll - - - ..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll - - - - - - - - - - - {4b5bf112-d3be-4e84-9a8e-74a0e314bba7} - LaaProductionWeb.Data - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - - \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb.UnitTests.Data/Properties/AssemblyInfo.cs b/LaaProductionWeb/LaaProductionWeb.UnitTests.Data/Properties/AssemblyInfo.cs deleted file mode 100644 index fbfc348f..00000000 --- a/LaaProductionWeb/LaaProductionWeb.UnitTests.Data/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("LaaProductionWeb.UnitTests.Data")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("LaaProductionWeb.UnitTests.Data")] -[assembly: AssemblyCopyright("Copyright © 2023")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -[assembly: ComVisible(false)] - -[assembly: Guid("a14581dd-e1ac-4ab0-9329-b723d24a2f3a")] - -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/LaaProductionWeb/LaaProductionWeb.sln b/LaaProductionWeb/LaaProductionWeb.sln index f1d21555..bc588f9f 100644 --- a/LaaProductionWeb/LaaProductionWeb.sln +++ b/LaaProductionWeb/LaaProductionWeb.sln @@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.33423.255 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LaaProductionWeb.Data", "LaaProductionWeb.Data\LaaProductionWeb.Data.csproj", "{4B5BF112-D3BE-4E84-9A8E-74A0E314BBA7}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LaaProductionWeb.Services", "LaaProductionWeb.Services\LaaProductionWeb.Services.csproj", "{FF167011-431A-41A7-A7DB-560E08860388}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Documents", "Documents", "{59875741-02AA-4D9A-9B3C-683CA6DDBE7B}" @@ -14,22 +12,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Documents", "Documents", "{ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LaaProductionWeb", "LaaProductionWeb\LaaProductionWeb.csproj", "{D1AD077B-00E3-4663-AB9F-23FF65D98D2F}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "UnitTests", "UnitTests", "{C01BB59F-25A6-4AC1-ADB5-C453EA57C35B}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LaaProductionWeb.UnitTests.Data", "LaaProductionWeb.UnitTests.Data\LaaProductionWeb.UnitTests.Data.csproj", "{A14581DD-E1AC-4AB0-9329-B723D24A2F3A}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentSQL", "FluentSQL\FluentSQL.csproj", "{68986A99-0DBA-407C-90BE-D5ED63C41BD4}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {4B5BF112-D3BE-4E84-9A8E-74A0E314BBA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4B5BF112-D3BE-4E84-9A8E-74A0E314BBA7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4B5BF112-D3BE-4E84-9A8E-74A0E314BBA7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4B5BF112-D3BE-4E84-9A8E-74A0E314BBA7}.Release|Any CPU.Build.0 = Release|Any CPU {FF167011-431A-41A7-A7DB-560E08860388}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {FF167011-431A-41A7-A7DB-560E08860388}.Debug|Any CPU.Build.0 = Debug|Any CPU {FF167011-431A-41A7-A7DB-560E08860388}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -38,21 +26,10 @@ Global {D1AD077B-00E3-4663-AB9F-23FF65D98D2F}.Debug|Any CPU.Build.0 = Debug|Any CPU {D1AD077B-00E3-4663-AB9F-23FF65D98D2F}.Release|Any CPU.ActiveCfg = Release|Any CPU {D1AD077B-00E3-4663-AB9F-23FF65D98D2F}.Release|Any CPU.Build.0 = Release|Any CPU - {A14581DD-E1AC-4AB0-9329-B723D24A2F3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A14581DD-E1AC-4AB0-9329-B723D24A2F3A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A14581DD-E1AC-4AB0-9329-B723D24A2F3A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A14581DD-E1AC-4AB0-9329-B723D24A2F3A}.Release|Any CPU.Build.0 = Release|Any CPU - {68986A99-0DBA-407C-90BE-D5ED63C41BD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {68986A99-0DBA-407C-90BE-D5ED63C41BD4}.Debug|Any CPU.Build.0 = Debug|Any CPU - {68986A99-0DBA-407C-90BE-D5ED63C41BD4}.Release|Any CPU.ActiveCfg = Release|Any CPU - {68986A99-0DBA-407C-90BE-D5ED63C41BD4}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {A14581DD-E1AC-4AB0-9329-B723D24A2F3A} = {C01BB59F-25A6-4AC1-ADB5-C453EA57C35B} - EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {9D3C9EBA-FB4B-4BF4-8158-4A9FE47D3E88} EndGlobalSection diff --git a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/AllowedRolesAttribute.cs b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/AllowedRolesAttribute.cs index bb3ade26..ee037d76 100644 --- a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/AllowedRolesAttribute.cs +++ b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/AllowedRolesAttribute.cs @@ -1,8 +1,9 @@ namespace LaaProductionWeb.App_Infrastructure { - using System.Security.Claims; using System.Web.Mvc; + using ClaimsPrincipal = System.Security.Claims.ClaimsPrincipal; + public class AllowedRolesAttribute : AuthorizeAttribute { public AllowedRolesAttribute(params string[] roles) diff --git a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/AuthorizationFilter.cs b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/AuthorizationFilter.cs index 01b80a83..08bdab7b 100644 --- a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/AuthorizationFilter.cs +++ b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/AuthorizationFilter.cs @@ -4,7 +4,9 @@ using System.Collections.Generic; using System.Security.Claims; - using System.Web.Mvc; + + using IAuthorizationFilter = System.Web.Mvc.IAuthorizationFilter; + using AuthorizationContext = System.Web.Mvc.AuthorizationContext; public class AuthorizationFilter : IAuthorizationFilter { diff --git a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/HttpResults.cs b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/HttpResults.cs new file mode 100644 index 00000000..1d9c5222 --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/HttpResults.cs @@ -0,0 +1,36 @@ +namespace LaaProductionWeb.App_Infrastructure +{ + using System.Collections.Generic; + using System.Linq; + + using WebAPIModelState = System.Web.Http.ModelBinding.ModelStateDictionary; + + + public class HttpErrorModel : Dictionary + { + private HttpErrorModel() + { + + } + + public static implicit operator HttpErrorModel(WebAPIModelState modelStateDictionary) + { + var badRequestErrors = new HttpErrorModel(); + + foreach (var kvp in modelStateDictionary) + { + var errorKey = kvp.Key ?? string.Empty; + var errorValue = kvp.Value.Errors?.FirstOrDefault()?.ErrorMessage; + + if (errorKey is null || errorValue is null) + { + continue; + } + + badRequestErrors[errorKey] = errorValue; + } + + return badRequestErrors; + } + } +} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/ServiceProvider.cs b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/ServiceProvider.cs index 3a40ec05..850fd717 100644 --- a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/ServiceProvider.cs +++ b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/ServiceProvider.cs @@ -1,8 +1,8 @@ namespace LaaProductionWeb { + using FluentSQLClient; + using LaaProductionWeb.App_Infrastructure; - using LaaProductionWeb.Data; - using LaaProductionWeb.Data.Interfaces; using LaaProductionWeb.Services; using LaaProductionWeb.Services.Interfaces; @@ -36,7 +36,7 @@ { var services = new ServiceCollection(); - services.AddSingleton(_ => new FluentSQL(Appsettings.ConnectionString)); + services.AddSingleton(_ => FluentSQLConnection.CreateClient(Appsettings.ConnectionString)); services.AddSingleton(_ => new HttpService(Appsettings.APIURL)); services.AddScoped(); diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Serach/Models/WildcardModel.cs b/LaaProductionWeb/LaaProductionWeb/Areas/Serach/Models/WildcardModel.cs index f974843e..d9cfaede 100644 --- a/LaaProductionWeb/LaaProductionWeb/Areas/Serach/Models/WildcardModel.cs +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Serach/Models/WildcardModel.cs @@ -1,6 +1,7 @@ namespace LaaProductionWeb.Areas.Serach.Models { - using LaaProductionWeb.Data.Interfaces; + using FluentSQLClient.Interfaces; + using LaaProductionWeb.Areas.Serach.Models.Interfaces; using LaaProductionWeb.Models; @@ -10,9 +11,9 @@ public class WildcardModel : IWildcardModel { - private readonly IFluentSQL fluentSQL; + private readonly IFluentSQLConnection fluentSQL; - public WildcardModel(IFluentSQL fluentSQL) + public WildcardModel(IFluentSQLConnection fluentSQL) => this.fluentSQL = fluentSQL; public ModelResult> Find(ModelStateDictionary validationState, WildcardInputModel model) diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Shipment/Models/ScanModel.cs b/LaaProductionWeb/LaaProductionWeb/Areas/Shipment/Models/ScanModel.cs index 7d5f1253..37404409 100644 --- a/LaaProductionWeb/LaaProductionWeb/Areas/Shipment/Models/ScanModel.cs +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Shipment/Models/ScanModel.cs @@ -1,19 +1,20 @@ namespace LaaProductionWeb.Areas.Shipment.Models { + using FluentSQLClient.Interfaces; + using LaaProductionWeb.Areas.Shipment.Models.Interfaces; using LaaProductionWeb.Models; using LaaProductionWeb.Models.SMTP; - using LaaProductionWeb.Data.Interfaces; using System.Collections.Generic; using System.Threading.Tasks; public class ScanModel : IScanModel { - private readonly IFluentSQL fluentSQL; + private readonly IFluentSQLConnection fluentSQL; private readonly SMTPClient smtpClient; - public ScanModel(IFluentSQL fluentSQL, SMTPClient smtpClient) + public ScanModel(IFluentSQLConnection fluentSQL, SMTPClient smtpClient) { this.fluentSQL = fluentSQL; this.smtpClient = smtpClient; diff --git a/LaaProductionWeb/LaaProductionWeb/LaaProductionWeb.csproj b/LaaProductionWeb/LaaProductionWeb/LaaProductionWeb.csproj index fa9eee80..49ff8d38 100644 --- a/LaaProductionWeb/LaaProductionWeb/LaaProductionWeb.csproj +++ b/LaaProductionWeb/LaaProductionWeb/LaaProductionWeb.csproj @@ -45,6 +45,9 @@ 4 + + ..\packages\FluentSQLClient.1.0.0\lib\netstandard2.0\FluentSQLClient.dll + ..\packages\Microsoft.Bcl.AsyncInterfaces.7.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll @@ -65,18 +68,36 @@ ..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll + + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + + + + ..\packages\System.Data.SqlClient.4.8.5\lib\net461\System.Data.SqlClient.dll + + + + ..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll + + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.9\lib\net45\System.Net.Http.Formatting.dll + + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + ..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll - - ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll - + + + @@ -114,6 +135,9 @@ ..\packages\Microsoft.AspNet.WebPages.3.2.9\lib\net45\System.Web.WebPages.Razor.dll + + + True ..\packages\WebGrease.1.6.0\lib\WebGrease.dll @@ -122,6 +146,7 @@ True ..\packages\Antlr.3.5.0.2\lib\Antlr3.Runtime.dll + @@ -211,7 +236,6 @@ - @@ -242,14 +266,11 @@ + - - {4B5BF112-D3BE-4E84-9A8E-74A0E314BBA7} - LaaProductionWeb.Data - {ff167011-431a-41a7-a7db-560e08860388} LaaProductionWeb.Services diff --git a/LaaProductionWeb/LaaProductionWeb/Web.config b/LaaProductionWeb/LaaProductionWeb/Web.config index c848064c..ccc2f64e 100644 --- a/LaaProductionWeb/LaaProductionWeb/Web.config +++ b/LaaProductionWeb/LaaProductionWeb/Web.config @@ -14,18 +14,11 @@ - + - - + + @@ -35,30 +28,30 @@ - - - - - + + + + + + + + + + + + + - - - - - - - - @@ -75,6 +68,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LaaProductionWeb/LaaProductionWeb/packages.config b/LaaProductionWeb/LaaProductionWeb/packages.config index c3094d13..acd7311c 100644 --- a/LaaProductionWeb/LaaProductionWeb/packages.config +++ b/LaaProductionWeb/LaaProductionWeb/packages.config @@ -1,22 +1,10 @@  - - - - - - - - - - - - - + - + + + - - \ No newline at end of file diff --git a/nuget.config b/nuget.config index c45c96ff..9df06048 100644 --- a/nuget.config +++ b/nuget.config @@ -1,13 +1,8 @@ - + - + + - - - - - -