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.DAL/Base/DAOBase.cs similarity index 86% rename from OSI-API/Business/DAO/DAOBase.cs rename to OSI-API.DAL/Base/DAOBase.cs index 913b214..80b7827 100644 --- a/OSI-API/Business/DAO/DAOBase.cs +++ b/OSI-API.DAL/Base/DAOBase.cs @@ -1,9 +1,6 @@ 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.Base { public abstract class DAOBase : MySQL diff --git a/OSI-API/Business/Database/MySQL/MySQL.cs b/OSI-API.DAL/Base/MySQL.cs similarity index 77% rename from OSI-API/Business/Database/MySQL/MySQL.cs rename to OSI-API.DAL/Base/MySQL.cs index 665b9b9..c87b1a0 100644 --- a/OSI-API/Business/Database/MySQL/MySQL.cs +++ b/OSI-API.DAL/Base/MySQL.cs @@ -1,16 +1,15 @@ using System; using System.Data; using System.IO; -using OSI.API.Business.Database.Base; using MySql.Data.MySqlClient; -namespace OSI.API.Business.Database +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) { @@ -28,7 +27,7 @@ namespace OSI.API.Business.Database { DBConnectionInfo = connectionInformation; } - + protected override void InitConnection() { DBConnection = new MySqlConnection(DBConnectionInfo.GetConnectionString()); @@ -38,7 +37,7 @@ namespace OSI.API.Business.Database protected override void DisposeConnection() { - if (DBConnection.State == ConnectionState.Open) + if(DBConnection.State == ConnectionState.Open) { DBConnection.Close(); } @@ -53,7 +52,7 @@ namespace OSI.API.Business.Database { int? rv = null; - if (!DBReader.IsDBNull(columnID)) + if(!DBReader.IsDBNull(columnID)) { rv = DBReader.GetInt32(columnID); } @@ -70,7 +69,7 @@ namespace OSI.API.Business.Database { byte? rv = null; - if (!DBReader.IsDBNull(columnID)) + if(!DBReader.IsDBNull(columnID)) { rv = DBReader.GetByte(columnID); } @@ -104,7 +103,7 @@ namespace OSI.API.Business.Database { decimal? rv = null; - if (!DBReader.IsDBNull(columnID)) + if(!DBReader.IsDBNull(columnID)) { rv = DBReader.GetDecimal(columnID); } @@ -121,7 +120,7 @@ namespace OSI.API.Business.Database { long? rv = null; - if (!DBReader.IsDBNull(columnID)) + if(!DBReader.IsDBNull(columnID)) { rv = DBReader.GetInt64(columnID); } @@ -138,7 +137,7 @@ namespace OSI.API.Business.Database { short? rv = null; - if (!DBReader.IsDBNull(columnID)) + if(!DBReader.IsDBNull(columnID)) { rv = DBReader.GetInt16(columnID); } @@ -155,7 +154,7 @@ namespace OSI.API.Business.Database { string rv = string.Empty; - if (!DBReader.IsDBNull(columnID)) + if(!DBReader.IsDBNull(columnID)) { rv = DBReader.GetString(columnID); } @@ -172,7 +171,7 @@ namespace OSI.API.Business.Database { bool? rv = null; - if (!DBReader.IsDBNull(columnID)) + if(!DBReader.IsDBNull(columnID)) { rv = DBReader.GetBoolean(columnID); } @@ -189,7 +188,7 @@ namespace OSI.API.Business.Database { DateTime? rv = null; - if (!DBReader.IsDBNull(columnID)) + if(!DBReader.IsDBNull(columnID)) { rv = GetDateTime(columnID); } @@ -201,5 +200,17 @@ namespace OSI.API.Business.Database { 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/Business/Database/Base/SQLBase.cs b/OSI-API.DAL/Base/SQLBase.cs similarity index 90% rename from OSI-API/Business/Database/Base/SQLBase.cs rename to OSI-API.DAL/Base/SQLBase.cs index b803263..89cd780 100644 --- a/OSI-API/Business/Database/Base/SQLBase.cs +++ b/OSI-API.DAL/Base/SQLBase.cs @@ -1,7 +1,7 @@ using System; using System.Text; -namespace OSI.API.Business.Database.Base +namespace OSI.API.DAL.Base { public abstract class SQLBase : IDisposable { @@ -14,17 +14,17 @@ namespace OSI.API.Business.Database.Base } 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 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) + switch(DBType) { case DBType.MSSQL: break; diff --git a/OSI-API.DAL/Client/ClientObjects.cs b/OSI-API.DAL/Client/ClientObjects.cs new file mode 100644 index 0000000..142dfa1 --- /dev/null +++ b/OSI-API.DAL/Client/ClientObjects.cs @@ -0,0 +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 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 new file mode 100644 index 0000000..d0a0895 --- /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 ((abbr != null) && states.ContainsKey(abbr)) + rv = states[abbr]; + + return rv; + } + + } +} \ No newline at end of file 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..555cf99 100644 --- a/OSI-API/Business/DAO/InvoiceDAO.cs +++ b/OSI-API.DAL/Invoice/InvoiceDAO.cs @@ -1,9 +1,8 @@ using System; using System.Collections.Generic; -using OSI.API.Business.Database; -using OSI.API.Business.Objects; +using OSI.API.DAL.Base; -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 60% rename from OSI-API/Business/Objects/InvoiceObjects.cs rename to OSI-API.DAL/Invoice/InvoiceObjects.cs index 15881c1..080ceaf 100644 --- a/OSI-API/Business/Objects/InvoiceObjects.cs +++ b/OSI-API.DAL/Invoice/InvoiceObjects.cs @@ -1,7 +1,8 @@ using System.Collections.Generic; using System; +using OSI.API.DAL.Client; -namespace OSI.API.Business.Objects +namespace OSI.API.DAL.Invoice { public class InvoiceObject { @@ -9,17 +10,17 @@ namespace OSI.API.Business.Objects 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.Business.Objects 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.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/Business/Objects/ClientObjects.cs b/OSI-API/Business/Objects/ClientObjects.cs deleted file mode 100644 index 0a64eb5..0000000 --- a/OSI-API/Business/Objects/ClientObjects.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace OSI.API.Business.Objects -{ - public class ClientObject - { - public int ClientID { get; set; } - public string ClientName { get; set; } - - } -} \ No newline at end of file diff --git a/OSI-API/Controllers/InvoicesController.cs b/OSI-API/Controllers/InvoicesController.cs index c85a905..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 Business.Database.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 Business.Database.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 ef37e92..5453354 100644 --- a/OSI-API/OSI-API.csproj +++ b/OSI-API/OSI-API.csproj @@ -1,7 +1,7 @@ - net5.0 + net6.0 OSI_API @@ -10,8 +10,12 @@ - + + + + +