From 9e62eb5c05c3f51b328cf9fa0019df9aea39f138 Mon Sep 17 00:00:00 2001 From: Don Oerkfitz Date: Mon, 1 Aug 2022 00:30:15 -0500 Subject: [PATCH 1/6] initial refactor commit upgraded to net 6.0 minor changes to support .net upgrade --- .vscode/launch.json | 2 +- OSI-API/Business/DAO/DAOBase.cs | 2 +- OSI-API/Business/Database/Base/SQLBase.cs | 100 ----------- OSI-API/Business/Database/MySQL/MySQL.cs | 205 ---------------------- OSI-API/Controllers/InvoicesController.cs | 4 +- OSI-API/OSI-API.csproj | 6 +- 6 files changed, 9 insertions(+), 310 deletions(-) delete mode 100644 OSI-API/Business/Database/Base/SQLBase.cs delete mode 100644 OSI-API/Business/Database/MySQL/MySQL.cs diff --git a/.vscode/launch.json b/.vscode/launch.json index 5d77af8..db07bf0 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,7 +10,7 @@ "request": "launch", "preLaunchTask": "build", // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/OSI-API/bin/Debug/net5.0/OSI-API.dll", + "program": "${workspaceFolder}/OSI-API/bin/Debug/net6.0/OSI-API.dll", "args": [], "cwd": "${workspaceFolder}/OSI-API", "stopAtEntry": false, diff --git a/OSI-API/Business/DAO/DAOBase.cs b/OSI-API/Business/DAO/DAOBase.cs index 913b214..6e8a7ac 100644 --- a/OSI-API/Business/DAO/DAOBase.cs +++ b/OSI-API/Business/DAO/DAOBase.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -using OSI.API.Business.Database; using OSI.API.Business.Objects; +using Common.Library.SQL.MySQL; namespace OSI.API.Business.DAO { diff --git a/OSI-API/Business/Database/Base/SQLBase.cs b/OSI-API/Business/Database/Base/SQLBase.cs deleted file mode 100644 index b803263..0000000 --- a/OSI-API/Business/Database/Base/SQLBase.cs +++ /dev/null @@ -1,100 +0,0 @@ -using System; -using System.Text; - -namespace OSI.API.Business.Database.Base -{ - public abstract class SQLBase : IDisposable - { - protected DBConnectionInformation DBConnectionInfo; - - public enum DBType - { - MSSQL, - MYSQL - } - public struct DBConnectionInformation - { - public string DBHost { get; set; } - public string DBName { get; set; } - public string DBUserName { get; set; } - public string DBPassword { get; set; } - public DBType DBType { get; set; } - - public string GetConnectionString() - { - string rv = string.Empty; - - switch (DBType) - { - case DBType.MSSQL: - break; - case DBType.MYSQL: - rv = string.Format("Server={0};Database={1};Uid={2};Pwd={3}", DBHost, DBName, DBUserName, DBPassword); - break; - } - - return rv; - } - } - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - protected virtual void Dispose(bool disposing) - { - if (disposing) - { - // free managed resources - } - // free native resources if there are any. - } - - protected string FormatNewLineForHTML(string input) - { - return input.Replace("\\r\\n", "
"); - } - - protected string FormatNewLineForHTML(string input, int numberOfBreaksToAdd) - { - StringBuilder breaks = new(); - for (int x = 0; x < numberOfBreaksToAdd; x++) - { - breaks.Append("
"); - } - - return input.Replace("\\r\\n", breaks.ToString()); - } - - protected string FormatBoldForHTML(string input) - { - return input.Replace("[b]", "").Replace("[/b]", ""); - } - - protected abstract void InitConnection(); - protected abstract void DisposeConnection(); - - protected abstract int GetOrdinal(string columnName); - protected abstract int? GetInt(int columnID); - protected abstract int? GetInt(string columnName); - protected abstract byte? GetByte(int columnID); - protected abstract byte? GetByte(string columnName); - protected abstract byte[] GetBytes(int columnID); - protected abstract byte[] GetBytes(string columnName); - protected abstract decimal? GetDecimal(int columnID); - protected abstract decimal? GetDecimal(string columnName); - protected abstract long? GetLong(int columnID); - protected abstract long? GetLong(string columnName); - protected abstract short? GetShort(int columnID); - protected abstract short? GetShort(string columnName); - protected abstract string GetString(int columnID); - protected abstract string GetString(string columnName); - protected abstract bool? GetBool(int columnID); - protected abstract bool? GetBool(string columnName); - protected abstract DateTime? GetDateTime(int columnID); - protected abstract DateTime? GetDateTime(string columnName); - - } -} diff --git a/OSI-API/Business/Database/MySQL/MySQL.cs b/OSI-API/Business/Database/MySQL/MySQL.cs deleted file mode 100644 index 665b9b9..0000000 --- a/OSI-API/Business/Database/MySQL/MySQL.cs +++ /dev/null @@ -1,205 +0,0 @@ -using System; -using System.Data; -using System.IO; -using OSI.API.Business.Database.Base; -using MySql.Data.MySqlClient; - -namespace OSI.API.Business.Database -{ - public class MySQL : SQLBase - { - protected MySqlConnection DBConnection { get; set; } - protected MySqlCommand DBCommand { get; set; } - protected MySqlDataReader DBReader { get; set; } - - public MySQL(string server, string database, string username, string password) - { - DBConnectionInfo = new DBConnectionInformation() - { - DBHost = server, - DBUserName = username, - DBName = database, - DBPassword = password, - DBType = DBType.MYSQL - }; - } - - public MySQL(DBConnectionInformation connectionInformation) - { - DBConnectionInfo = connectionInformation; - } - - protected override void InitConnection() - { - DBConnection = new MySqlConnection(DBConnectionInfo.GetConnectionString()); - DBConnection.Open(); - DBCommand = DBConnection.CreateCommand(); - } - - protected override void DisposeConnection() - { - if (DBConnection.State == ConnectionState.Open) - { - DBConnection.Close(); - } - } - - protected override int GetOrdinal(string columnName) - { - return DBReader.GetOrdinal(columnName); - } - - protected override int? GetInt(int columnID) - { - int? rv = null; - - if (!DBReader.IsDBNull(columnID)) - { - rv = DBReader.GetInt32(columnID); - } - - return rv; - } - - protected override int? GetInt(string columnName) - { - return GetInt(GetOrdinal(columnName)); - } - - protected override byte? GetByte(int columnID) - { - byte? rv = null; - - if (!DBReader.IsDBNull(columnID)) - { - rv = DBReader.GetByte(columnID); - } - - return rv; - } - - protected override byte? GetByte(string columnName) - { - return GetByte(GetOrdinal(columnName)); - } - - protected override byte[] GetBytes(int columnID) - { - byte[] rv = null; - - if (!DBReader.IsDBNull(columnID)) - { - rv = (byte[])DBReader[columnID]; - } - - return rv; - } - - protected override byte[] GetBytes(string columnName) - { - return GetBytes(GetOrdinal(columnName)); - } - - protected override decimal? GetDecimal(int columnID) - { - decimal? rv = null; - - if (!DBReader.IsDBNull(columnID)) - { - rv = DBReader.GetDecimal(columnID); - } - - return rv; - } - - protected override decimal? GetDecimal(string columnName) - { - return GetDecimal(GetOrdinal(columnName)); - } - - protected override long? GetLong(int columnID) - { - long? rv = null; - - if (!DBReader.IsDBNull(columnID)) - { - rv = DBReader.GetInt64(columnID); - } - - return rv; - } - - protected override long? GetLong(string columnName) - { - return GetLong(GetOrdinal(columnName)); - } - - protected override short? GetShort(int columnID) - { - short? rv = null; - - if (!DBReader.IsDBNull(columnID)) - { - rv = DBReader.GetInt16(columnID); - } - - return rv; - } - - protected override short? GetShort(string columnName) - { - return GetShort(GetOrdinal(columnName)); - } - - protected override string GetString(int columnID) - { - string rv = string.Empty; - - if (!DBReader.IsDBNull(columnID)) - { - rv = DBReader.GetString(columnID); - } - - return rv; - } - - protected override string GetString(string columnName) - { - return GetString(GetOrdinal(columnName)); - } - - protected override bool? GetBool(int columnID) - { - bool? rv = null; - - if (!DBReader.IsDBNull(columnID)) - { - rv = DBReader.GetBoolean(columnID); - } - - return rv; - } - - protected override bool? GetBool(string columnName) - { - return GetBool(GetOrdinal(columnName)); - } - - protected override DateTime? GetDateTime(int columnID) - { - DateTime? rv = null; - - if (!DBReader.IsDBNull(columnID)) - { - rv = GetDateTime(columnID); - } - - return rv; - } - - protected override DateTime? GetDateTime(string columnName) - { - return GetDateTime(GetOrdinal(columnName)); - } - } -} diff --git a/OSI-API/Controllers/InvoicesController.cs b/OSI-API/Controllers/InvoicesController.cs index c85a905..796c31d 100644 --- a/OSI-API/Controllers/InvoicesController.cs +++ b/OSI-API/Controllers/InvoicesController.cs @@ -21,13 +21,13 @@ namespace OSI.API.Controllers public override IActionResult Get() { //> get all invoices as a list of InvoiceObjects - using InvoiceDAO dao = new(new Business.Database.Base.SQLBase.DBConnectionInformation()); + using InvoiceDAO dao = new(new Common.Library.SQL.Base.SQLBase.DBConnectionInformation()); return new JsonResult(dao.GetAll()); } public override IActionResult Get(int id) { - using InvoiceDAO dao = new(new Business.Database.Base.SQLBase.DBConnectionInformation()); + using InvoiceDAO dao = new(new Common.Library.SQL.Base.SQLBase.DBConnectionInformation()); return new JsonResult(dao.Get(id)); } diff --git a/OSI-API/OSI-API.csproj b/OSI-API/OSI-API.csproj index ef37e92..b84310a 100644 --- a/OSI-API/OSI-API.csproj +++ b/OSI-API/OSI-API.csproj @@ -1,7 +1,7 @@ - net5.0 + net6.0 OSI_API @@ -14,4 +14,8 @@ + + + + -- 2.46.2 From cdedda1c37d093cfe680775620518ae87849bcd2 Mon Sep 17 00:00:00 2001 From: Don Oerkfitz Date: Mon, 1 Aug 2022 00:53:51 -0500 Subject: [PATCH 2/6] moved to submodule system --- .gitmodules | 4 ++++ Library.System | 1 + OSI-API/OSI-API.csproj | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .gitmodules create mode 160000 Library.System diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..6e5d9d5 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "Library.System"] + path = Library.System + url = https://git.oerkfitz.com/DMCDynamics/Library.System.git + branch = net6.0 diff --git a/Library.System b/Library.System new file mode 160000 index 0000000..edf4b22 --- /dev/null +++ b/Library.System @@ -0,0 +1 @@ +Subproject commit edf4b22c16749e165bff4529c81cc3ab5f96b968 diff --git a/OSI-API/OSI-API.csproj b/OSI-API/OSI-API.csproj index b84310a..fdc299a 100644 --- a/OSI-API/OSI-API.csproj +++ b/OSI-API/OSI-API.csproj @@ -15,7 +15,7 @@ - + -- 2.46.2 From b9fad50539e3860aaf9472298a313370dcf0cd1c Mon Sep 17 00:00:00 2001 From: Don Oerkfitz Date: Fri, 12 May 2023 01:39:07 -0500 Subject: [PATCH 3/6] removed submodule --- .gitmodules | 4 ---- Library.System | 1 - 2 files changed, 5 deletions(-) delete mode 160000 Library.System diff --git a/.gitmodules b/.gitmodules index 6e5d9d5..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +0,0 @@ -[submodule "Library.System"] - path = Library.System - url = https://git.oerkfitz.com/DMCDynamics/Library.System.git - branch = net6.0 diff --git a/Library.System b/Library.System deleted file mode 160000 index edf4b22..0000000 --- a/Library.System +++ /dev/null @@ -1 +0,0 @@ -Subproject commit edf4b22c16749e165bff4529c81cc3ab5f96b968 -- 2.46.2 From c2a47bd539c1ab2df9632fae26ba498dbb5ae6f4 Mon Sep 17 00:00:00 2001 From: Don Oerkfitz Date: Fri, 12 May 2023 01:39:31 -0500 Subject: [PATCH 4/6] moving DB files to DAL project --- .../DAO => OSI-API.DAL/Base}/DAOBase.cs | 3 +- OSI-API.DAL/Base/MySQL.cs | 231 ++++++++++++++++++ OSI-API.DAL/Base/SQLBase.cs | 100 ++++++++ .../Client}/ClientObjects.cs | 2 +- .../DAO => OSI-API.DAL/Invoice}/InvoiceDAO.cs | 4 +- .../Invoice}/InvoiceObjects.cs | 2 +- OSI-API.DAL/OSI-API.DAL.csproj | 14 ++ OSI-API/OSI-API.csproj | 2 +- 8 files changed, 350 insertions(+), 8 deletions(-) rename {OSI-API/Business/DAO => OSI-API.DAL/Base}/DAOBase.cs (91%) create mode 100644 OSI-API.DAL/Base/MySQL.cs create mode 100644 OSI-API.DAL/Base/SQLBase.cs rename {OSI-API/Business/Objects => OSI-API.DAL/Client}/ClientObjects.cs (79%) rename {OSI-API/Business/DAO => OSI-API.DAL/Invoice}/InvoiceDAO.cs (91%) rename {OSI-API/Business/Objects => OSI-API.DAL/Invoice}/InvoiceObjects.cs (96%) create mode 100644 OSI-API.DAL/OSI-API.DAL.csproj diff --git a/OSI-API/Business/DAO/DAOBase.cs b/OSI-API.DAL/Base/DAOBase.cs similarity index 91% rename from OSI-API/Business/DAO/DAOBase.cs rename to OSI-API.DAL/Base/DAOBase.cs index 6e8a7ac..b5abcc0 100644 --- a/OSI-API/Business/DAO/DAOBase.cs +++ b/OSI-API.DAL/Base/DAOBase.cs @@ -1,9 +1,8 @@ using System; using System.Collections.Generic; using OSI.API.Business.Objects; -using Common.Library.SQL.MySQL; -namespace OSI.API.Business.DAO +namespace OSI.API.DAL.Base { public abstract class DAOBase : MySQL diff --git a/OSI-API.DAL/Base/MySQL.cs b/OSI-API.DAL/Base/MySQL.cs new file mode 100644 index 0000000..57e926c --- /dev/null +++ b/OSI-API.DAL/Base/MySQL.cs @@ -0,0 +1,231 @@ +using System; +using System.Data; +using System.IO; +using MySql.Data.MySqlClient; + +namespace OSI.API.DAL.Base +{ + public class MySQL : SQLBase + { + protected MySqlConnection DBConnection {get;set;} + protected MySqlCommand DBCommand {get;set;} + protected MySqlDataReader DBReader {get;set;} + + public MySQL(string server, string database, string username, string password) + { + DBConnectionInfo = new DBConnectionInformation() + { + DBHost = server, + DBUserName = username, + DBName = database, + DBPassword = password, + DBType = DBType.MYSQL + }; + } + + public MySQL(DBConnectionInformation connectionInformation) + { + DBConnectionInfo = connectionInformation; + } + + protected override void InitConnection() + { + DBConnection = new MySqlConnection(DBConnectionInfo.GetConnectionString()); + DBConnection.Open(); + DBCommand = DBConnection.CreateCommand(); + } + + protected override void DisposeConnection() + { + if(DBConnection.State == ConnectionState.Open) + { + DBConnection.Close(); + } + } + + protected override int GetOrdinal(string columnName) + { + return DBReader.GetOrdinal(columnName); + } + + protected override int? GetInt(int columnID) + { + int? rv = null; + + if(!DBReader.IsDBNull(columnID)) + { + rv = DBReader.GetInt32(columnID); + } + + return rv; + } + + protected override int? GetInt(string columnName) + { + return GetInt(GetOrdinal(columnName)); + } + + protected override byte? GetByte(int columnID) + { + byte? rv = null; + + if(!DBReader.IsDBNull(columnID)) + { + rv = DBReader.GetByte(columnID); + } + + return rv; + } + + protected override byte? GetByte(string columnName) + { + return GetByte(GetOrdinal(columnName)); + } + + protected override byte[] GetBytes(int columnID) + { + byte[] rv = null; + + if (!DBReader.IsDBNull(columnID)) + { + // const int CHUNK_SIZE = 2 * 1024; + // byte[] buffer = new byte[CHUNK_SIZE]; + // long bytesRead; + // long fieldOffset = 0; + + // using (var stream = new MemoryStream()) + // { + // while ((bytesRead = DBReader.GetBytes(columnID, fieldOffset, buffer, 0, buffer.Length)) == buffer.Length) + // { + // stream.Write(buffer, 0, (int)bytesRead); + // fieldOffset += bytesRead; + // } + // rv = stream.ToArray(); + // } + + rv = (byte[])DBReader[columnID]; + } + + return rv; + } + + protected override byte[] GetBytes(string columnName) + { + return GetBytes(GetOrdinal(columnName)); + } + + protected override decimal? GetDecimal(int columnID) + { + decimal? rv = null; + + if(!DBReader.IsDBNull(columnID)) + { + rv = DBReader.GetDecimal(columnID); + } + + return rv; + } + + protected override decimal? GetDecimal(string columnName) + { + return GetDecimal(GetOrdinal(columnName)); + } + + protected override long? GetLong(int columnID) + { + long? rv = null; + + if(!DBReader.IsDBNull(columnID)) + { + rv = DBReader.GetInt64(columnID); + } + + return rv; + } + + protected override long? GetLong(string columnName) + { + return GetLong(GetOrdinal(columnName)); + } + + protected override short? GetShort(int columnID) + { + short? rv = null; + + if(!DBReader.IsDBNull(columnID)) + { + rv = DBReader.GetInt16(columnID); + } + + return rv; + } + + protected override short? GetShort(string columnName) + { + return GetShort(GetOrdinal(columnName)); + } + + protected override string GetString(int columnID) + { + string rv = string.Empty; + + if(!DBReader.IsDBNull(columnID)) + { + rv = DBReader.GetString(columnID); + } + + return rv; + } + + protected override string GetString(string columnName) + { + return GetString(GetOrdinal(columnName)); + } + + protected override bool? GetBool(int columnID) + { + bool? rv = null; + + if(!DBReader.IsDBNull(columnID)) + { + rv = DBReader.GetBoolean(columnID); + } + + return rv; + } + + protected override bool? GetBool(string columnName) + { + return GetBool(GetOrdinal(columnName)); + } + + protected override DateTime? GetDateTime(int columnID) + { + DateTime? rv = null; + + if(!DBReader.IsDBNull(columnID)) + { + rv = GetDateTime(columnID); + } + + return rv; + } + + protected override DateTime? GetDateTime(string columnName) + { + return GetDateTime(GetOrdinal(columnName)); + } + + + //new MySqlParameter("GUID", MySqlDbType.VarChar, 255, ParameterDirection.Input, false, 0, 0, string.Empty, DataRowVersion.Proposed, guid) + protected MySqlParameter GetParameter(string columnName, MySqlDbType dataType, ParameterDirection direction, object data) + { + return null; + } + + protected MySqlParameter GetParameter(string columnName, MySqlDbType dataType, int size, ParameterDirection direction, object data) + { + return new MySqlParameter(columnName, dataType, size, direction, false, 0, 0, string.Empty, DataRowVersion.Proposed, data); + } + } +} diff --git a/OSI-API.DAL/Base/SQLBase.cs b/OSI-API.DAL/Base/SQLBase.cs new file mode 100644 index 0000000..89cd780 --- /dev/null +++ b/OSI-API.DAL/Base/SQLBase.cs @@ -0,0 +1,100 @@ +using System; +using System.Text; + +namespace OSI.API.DAL.Base +{ + public abstract class SQLBase : IDisposable + { + protected DBConnectionInformation DBConnectionInfo; + + public enum DBType + { + MSSQL, + MYSQL + } + public struct DBConnectionInformation + { + public string DBHost {get;set;} + public string DBName {get;set;} + public string DBUserName {get;set;} + public string DBPassword {get;set;} + public DBType DBType {get;set;} + + public string GetConnectionString() + { + string rv = string.Empty; + + switch(DBType) + { + case DBType.MSSQL: + break; + case DBType.MYSQL: + rv = string.Format("Server={0};Database={1};Uid={2};Pwd={3}", DBHost, DBName, DBUserName, DBPassword); + break; + } + + return rv; + } + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + // free managed resources + } + // free native resources if there are any. + } + + protected string FormatNewLineForHTML(string input) + { + return input.Replace("\\r\\n", "
"); + } + + protected string FormatNewLineForHTML(string input, int numberOfBreaksToAdd) + { + StringBuilder breaks = new(); + for (int x = 0; x < numberOfBreaksToAdd; x++) + { + breaks.Append("
"); + } + + return input.Replace("\\r\\n", breaks.ToString()); + } + + protected string FormatBoldForHTML(string input) + { + return input.Replace("[b]", "").Replace("[/b]", ""); + } + + protected abstract void InitConnection(); + protected abstract void DisposeConnection(); + + protected abstract int GetOrdinal(string columnName); + protected abstract int? GetInt(int columnID); + protected abstract int? GetInt(string columnName); + protected abstract byte? GetByte(int columnID); + protected abstract byte? GetByte(string columnName); + protected abstract byte[] GetBytes(int columnID); + protected abstract byte[] GetBytes(string columnName); + protected abstract decimal? GetDecimal(int columnID); + protected abstract decimal? GetDecimal(string columnName); + protected abstract long? GetLong(int columnID); + protected abstract long? GetLong(string columnName); + protected abstract short? GetShort(int columnID); + protected abstract short? GetShort(string columnName); + protected abstract string GetString(int columnID); + protected abstract string GetString(string columnName); + protected abstract bool? GetBool(int columnID); + protected abstract bool? GetBool(string columnName); + protected abstract DateTime? GetDateTime(int columnID); + protected abstract DateTime? GetDateTime(string columnName); + + } +} diff --git a/OSI-API/Business/Objects/ClientObjects.cs b/OSI-API.DAL/Client/ClientObjects.cs similarity index 79% rename from OSI-API/Business/Objects/ClientObjects.cs rename to OSI-API.DAL/Client/ClientObjects.cs index 0a64eb5..e5b3fa3 100644 --- a/OSI-API/Business/Objects/ClientObjects.cs +++ b/OSI-API.DAL/Client/ClientObjects.cs @@ -1,4 +1,4 @@ -namespace OSI.API.Business.Objects +namespace OSI.API.DAL.Client { public class ClientObject { diff --git a/OSI-API/Business/DAO/InvoiceDAO.cs b/OSI-API.DAL/Invoice/InvoiceDAO.cs similarity index 91% rename from OSI-API/Business/DAO/InvoiceDAO.cs rename to OSI-API.DAL/Invoice/InvoiceDAO.cs index c1d57f2..2bb08f7 100644 --- a/OSI-API/Business/DAO/InvoiceDAO.cs +++ b/OSI-API.DAL/Invoice/InvoiceDAO.cs @@ -1,9 +1,7 @@ using System; using System.Collections.Generic; -using OSI.API.Business.Database; -using OSI.API.Business.Objects; -namespace OSI.API.Business.DAO +namespace OSI.API.DAL.Invoice { public class InvoiceDAO : DAOBase diff --git a/OSI-API/Business/Objects/InvoiceObjects.cs b/OSI-API.DAL/Invoice/InvoiceObjects.cs similarity index 96% rename from OSI-API/Business/Objects/InvoiceObjects.cs rename to OSI-API.DAL/Invoice/InvoiceObjects.cs index 15881c1..cbdf1c1 100644 --- a/OSI-API/Business/Objects/InvoiceObjects.cs +++ b/OSI-API.DAL/Invoice/InvoiceObjects.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System; -namespace OSI.API.Business.Objects +namespace OSI.API.DAL.Invoice { public class InvoiceObject { diff --git a/OSI-API.DAL/OSI-API.DAL.csproj b/OSI-API.DAL/OSI-API.DAL.csproj new file mode 100644 index 0000000..2c3bced --- /dev/null +++ b/OSI-API.DAL/OSI-API.DAL.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + OSI_API.DAL + enable + enable + + + + + + + diff --git a/OSI-API/OSI-API.csproj b/OSI-API/OSI-API.csproj index fdc299a..0709f2c 100644 --- a/OSI-API/OSI-API.csproj +++ b/OSI-API/OSI-API.csproj @@ -15,7 +15,7 @@ - + -- 2.46.2 From e6b5eaf8511791d4b019189c43fd859d60f7aded Mon Sep 17 00:00:00 2001 From: Don Oerkfitz Date: Fri, 12 May 2023 01:52:06 -0500 Subject: [PATCH 5/6] fixing project issues --- OSI-API.DAL/Base/DAOBase.cs | 2 - OSI-API.DAL/Base/MySQL.cs | 15 ----- OSI-API.DAL/Common/CommonObjects.cs | 81 +++++++++++++++++++++++ OSI-API.DAL/Invoice/InvoiceDAO.cs | 1 + OSI-API.DAL/Invoice/InvoiceObjects.cs | 17 ++--- OSI-API/Controllers/InvoicesController.cs | 7 +- OSI-API/OSI-API.csproj | 2 +- 7 files changed, 95 insertions(+), 30 deletions(-) create mode 100644 OSI-API.DAL/Common/CommonObjects.cs diff --git a/OSI-API.DAL/Base/DAOBase.cs b/OSI-API.DAL/Base/DAOBase.cs index b5abcc0..80b7827 100644 --- a/OSI-API.DAL/Base/DAOBase.cs +++ b/OSI-API.DAL/Base/DAOBase.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using OSI.API.Business.Objects; - namespace OSI.API.DAL.Base { diff --git a/OSI-API.DAL/Base/MySQL.cs b/OSI-API.DAL/Base/MySQL.cs index 57e926c..4b9daf9 100644 --- a/OSI-API.DAL/Base/MySQL.cs +++ b/OSI-API.DAL/Base/MySQL.cs @@ -88,21 +88,6 @@ namespace OSI.API.DAL.Base if (!DBReader.IsDBNull(columnID)) { - // const int CHUNK_SIZE = 2 * 1024; - // byte[] buffer = new byte[CHUNK_SIZE]; - // long bytesRead; - // long fieldOffset = 0; - - // using (var stream = new MemoryStream()) - // { - // while ((bytesRead = DBReader.GetBytes(columnID, fieldOffset, buffer, 0, buffer.Length)) == buffer.Length) - // { - // stream.Write(buffer, 0, (int)bytesRead); - // fieldOffset += bytesRead; - // } - // rv = stream.ToArray(); - // } - rv = (byte[])DBReader[columnID]; } diff --git a/OSI-API.DAL/Common/CommonObjects.cs b/OSI-API.DAL/Common/CommonObjects.cs new file mode 100644 index 0000000..e14b75a --- /dev/null +++ b/OSI-API.DAL/Common/CommonObjects.cs @@ -0,0 +1,81 @@ +namespace OSI.API.DAL.Common +{ + public class AddressObject + { + public string? Name { get; set; } + public string? AddressLine1 { get; set; } + public string? AddressLine2 { get; set; } + public string? AddressLine3 { get; set; } + public string? City { get; set; } + public string? State { get; set; } + public string? Zip { get; set; } + + public string CSZ { get => $"{City}, {StateNameFromAbbreviation(State)} {Zip}"; } + + private string StateNameFromAbbreviation(string abbr) + { + string rv = abbr; + + Dictionary states = new Dictionary() + { + {"AL", "Alabama"}, + {"AK", "Alaska"}, + {"AZ", "Arizona"}, + {"AR", "Arkansas"}, + {"CA", "California"}, + {"CO", "Colorado"}, + {"CT", "Connecticut"}, + {"DE", "Delaware"}, + {"DC", "District of Columbia"}, + {"FL", "Florida"}, + {"GA", "Georgia"}, + {"HI", "Hawaii"}, + {"ID", "Idaho"}, + {"IL", "Illinois"}, + {"IN", "Indiana"}, + {"IA", "Iowa"}, + {"KS", "Kansas"}, + {"KY", "Kentucky"}, + {"LA", "Louisiana"}, + {"ME", "Maine"}, + {"MD", "Maryland"}, + {"MA", "Massachusetts"}, + {"MI", "Michigan"}, + {"MN", "Minnesota"}, + {"MS", "Mississippi"}, + {"MO", "Missouri"}, + {"MT", "Montana"}, + {"NE", "Nebraska"}, + {"NV", "Nevada"}, + {"NH", "New Hampshire"}, + {"NJ", "New Jersey"}, + {"NM", "New Mexico"}, + {"NY", "New York"}, + {"NC", "North Carolina"}, + {"ND", "North Dakota"}, + {"OH", "Ohio"}, + {"OK", "Oklahoma"}, + {"OR", "Oregon"}, + {"PA", "Pennsylvania"}, + {"RI", "Rhode Island"}, + {"SC", "South Carolina"}, + {"SD", "South Dakota"}, + {"TN", "Tennessee"}, + {"TX", "Texas"}, + {"UT", "Utah"}, + {"VT", "Vermont"}, + {"VA", "Virginia"}, + {"WA", "Washington"}, + {"WV", "West Virginia"}, + {"WI", "Wisconsin"}, + {"WY", "Wyoming"} + }; + + if (states.ContainsKey(abbr)) + rv = states[abbr]; + + return rv; + } + + } +} \ No newline at end of file diff --git a/OSI-API.DAL/Invoice/InvoiceDAO.cs b/OSI-API.DAL/Invoice/InvoiceDAO.cs index 2bb08f7..555cf99 100644 --- a/OSI-API.DAL/Invoice/InvoiceDAO.cs +++ b/OSI-API.DAL/Invoice/InvoiceDAO.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using OSI.API.DAL.Base; namespace OSI.API.DAL.Invoice { diff --git a/OSI-API.DAL/Invoice/InvoiceObjects.cs b/OSI-API.DAL/Invoice/InvoiceObjects.cs index cbdf1c1..080ceaf 100644 --- a/OSI-API.DAL/Invoice/InvoiceObjects.cs +++ b/OSI-API.DAL/Invoice/InvoiceObjects.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System; +using OSI.API.DAL.Client; namespace OSI.API.DAL.Invoice { @@ -9,17 +10,17 @@ namespace OSI.API.DAL.Invoice public float InvoiceAmount { get; set; } public float Discount { get; set; } public float Tax { get; set; } - public List InvoiceLineItems { get; set; } - public Notes Notes { get; set; } + public List? InvoiceLineItems { get; set; } + public Notes? Notes { get; set; } public DateTime InvoiceDate { get; set; } public DateTime DueDate { get; set; } - public ClientObject Client { get; set; } + public ClientObject? Client { get; set; } } public class InvoiceObjectLineItems { - public string Item { get; set; } - public string Description { get; set; } + public string? Item { get; set; } + public string? Description { get; set; } public float Cost { get; set; } public float Quantity { get; set; } public float Tax { get; set; } @@ -30,9 +31,9 @@ namespace OSI.API.DAL.Invoice public class Notes { - public string PublicNotes { get; set; } - public string PrivateNotes { get; set; } - public string Terms { get; set; } + public string? PublicNotes { get; set; } + public string? PrivateNotes { get; set; } + public string? Terms { get; set; } } } \ No newline at end of file diff --git a/OSI-API/Controllers/InvoicesController.cs b/OSI-API/Controllers/InvoicesController.cs index 796c31d..809d933 100644 --- a/OSI-API/Controllers/InvoicesController.cs +++ b/OSI-API/Controllers/InvoicesController.cs @@ -4,8 +4,7 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using OSI.API.Business.Objects; -using OSI.API.Business.DAO; +using OSI.API.DAL.Invoice; namespace OSI.API.Controllers { @@ -21,13 +20,13 @@ namespace OSI.API.Controllers public override IActionResult Get() { //> get all invoices as a list of InvoiceObjects - using InvoiceDAO dao = new(new Common.Library.SQL.Base.SQLBase.DBConnectionInformation()); + using InvoiceDAO dao = new(new OSI.API.DAL.Base.SQLBase.DBConnectionInformation()); return new JsonResult(dao.GetAll()); } public override IActionResult Get(int id) { - using InvoiceDAO dao = new(new Common.Library.SQL.Base.SQLBase.DBConnectionInformation()); + using InvoiceDAO dao = new(new OSI.API.DAL.Base.SQLBase.DBConnectionInformation()); return new JsonResult(dao.Get(id)); } diff --git a/OSI-API/OSI-API.csproj b/OSI-API/OSI-API.csproj index 0709f2c..5453354 100644 --- a/OSI-API/OSI-API.csproj +++ b/OSI-API/OSI-API.csproj @@ -10,7 +10,7 @@ - + -- 2.46.2 From bf60d12a9ac26c413e99fa0dab7546c8cac91b59 Mon Sep 17 00:00:00 2001 From: Don Oerkfitz Date: Fri, 12 May 2023 02:01:22 -0500 Subject: [PATCH 6/6] more refactoring --- .gitmodules | 0 OSI-API.DAL/Base/MySQL.cs | 6 +++--- OSI-API.DAL/Client/ClientObjects.cs | 5 ++++- OSI-API.DAL/Common/CommonObjects.cs | 6 +++--- 4 files changed, 10 insertions(+), 7 deletions(-) delete mode 100644 .gitmodules diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index e69de29..0000000 diff --git a/OSI-API.DAL/Base/MySQL.cs b/OSI-API.DAL/Base/MySQL.cs index 4b9daf9..c87b1a0 100644 --- a/OSI-API.DAL/Base/MySQL.cs +++ b/OSI-API.DAL/Base/MySQL.cs @@ -7,9 +7,9 @@ namespace OSI.API.DAL.Base { public class MySQL : SQLBase { - protected MySqlConnection DBConnection {get;set;} - protected MySqlCommand DBCommand {get;set;} - protected MySqlDataReader DBReader {get;set;} + protected MySqlConnection? DBConnection {get;set;} + protected MySqlCommand? DBCommand {get;set;} + protected MySqlDataReader? DBReader {get;set;} public MySQL(string server, string database, string username, string password) { diff --git a/OSI-API.DAL/Client/ClientObjects.cs b/OSI-API.DAL/Client/ClientObjects.cs index e5b3fa3..142dfa1 100644 --- a/OSI-API.DAL/Client/ClientObjects.cs +++ b/OSI-API.DAL/Client/ClientObjects.cs @@ -1,9 +1,12 @@ +using OSI.API.DAL.Common; + namespace OSI.API.DAL.Client { public class ClientObject { public int ClientID { get; set; } - public string ClientName { get; set; } + public string? ClientName { get; set; } + public AddressObject? ClientAddress { get; set; } } } \ No newline at end of file diff --git a/OSI-API.DAL/Common/CommonObjects.cs b/OSI-API.DAL/Common/CommonObjects.cs index e14b75a..d0a0895 100644 --- a/OSI-API.DAL/Common/CommonObjects.cs +++ b/OSI-API.DAL/Common/CommonObjects.cs @@ -12,9 +12,9 @@ namespace OSI.API.DAL.Common public string CSZ { get => $"{City}, {StateNameFromAbbreviation(State)} {Zip}"; } - private string StateNameFromAbbreviation(string abbr) + private string? StateNameFromAbbreviation(string? abbr) { - string rv = abbr; + string? rv = abbr; Dictionary states = new Dictionary() { @@ -71,7 +71,7 @@ namespace OSI.API.DAL.Common {"WY", "Wyoming"} }; - if (states.ContainsKey(abbr)) + if ((abbr != null) && states.ContainsKey(abbr)) rv = states[abbr]; return rv; -- 2.46.2