WIP: Refactorization #1

Draft
don wants to merge 6 commits from refactor into dev

@ -10,7 +10,7 @@
"request": "launch", "request": "launch",
"preLaunchTask": "build", "preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path. // 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": [], "args": [],
"cwd": "${workspaceFolder}/OSI-API", "cwd": "${workspaceFolder}/OSI-API",
"stopAtEntry": false, "stopAtEntry": false,

@ -1,9 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using OSI.API.Business.Database; namespace OSI.API.DAL.Base
using OSI.API.Business.Objects;
namespace OSI.API.Business.DAO
{ {
public abstract class DAOBase<T> : MySQL public abstract class DAOBase<T> : MySQL

@ -1,16 +1,15 @@
using System; using System;
using System.Data; using System.Data;
using System.IO; using System.IO;
using OSI.API.Business.Database.Base;
using MySql.Data.MySqlClient; using MySql.Data.MySqlClient;
namespace OSI.API.Business.Database namespace OSI.API.DAL.Base
{ {
public class MySQL : SQLBase public class MySQL : SQLBase
{ {
protected MySqlConnection DBConnection { get; set; } protected MySqlConnection? DBConnection {get;set;}
protected MySqlCommand DBCommand { get; set; } protected MySqlCommand? DBCommand {get;set;}
protected MySqlDataReader DBReader { get; set; } protected MySqlDataReader? DBReader {get;set;}
public MySQL(string server, string database, string username, string password) public MySQL(string server, string database, string username, string password)
{ {
@ -201,5 +200,17 @@ namespace OSI.API.Business.Database
{ {
return GetDateTime(GetOrdinal(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);
}
} }
} }

@ -1,7 +1,7 @@
using System; using System;
using System.Text; using System.Text;
namespace OSI.API.Business.Database.Base namespace OSI.API.DAL.Base
{ {
public abstract class SQLBase : IDisposable public abstract class SQLBase : IDisposable
{ {

@ -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; }
}
}

@ -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<string, string> states = new Dictionary<string, string>()
{
{"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;
}
}
}

@ -1,9 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using OSI.API.Business.Database; using OSI.API.DAL.Base;
using OSI.API.Business.Objects;
namespace OSI.API.Business.DAO namespace OSI.API.DAL.Invoice
{ {
public class InvoiceDAO : DAOBase<InvoiceObject> public class InvoiceDAO : DAOBase<InvoiceObject>

@ -1,7 +1,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using System; using System;
using OSI.API.DAL.Client;
namespace OSI.API.Business.Objects namespace OSI.API.DAL.Invoice
{ {
public class InvoiceObject public class InvoiceObject
{ {
@ -9,17 +10,17 @@ namespace OSI.API.Business.Objects
public float InvoiceAmount { get; set; } public float InvoiceAmount { get; set; }
public float Discount { get; set; } public float Discount { get; set; }
public float Tax { get; set; } public float Tax { get; set; }
public List<InvoiceObjectLineItems> InvoiceLineItems { get; set; } public List<InvoiceObjectLineItems>? InvoiceLineItems { get; set; }
public Notes Notes { get; set; } public Notes? Notes { get; set; }
public DateTime InvoiceDate { get; set; } public DateTime InvoiceDate { get; set; }
public DateTime DueDate { get; set; } public DateTime DueDate { get; set; }
public ClientObject Client { get; set; } public ClientObject? Client { get; set; }
} }
public class InvoiceObjectLineItems public class InvoiceObjectLineItems
{ {
public string Item { get; set; } public string? Item { get; set; }
public string Description { get; set; } public string? Description { get; set; }
public float Cost { get; set; } public float Cost { get; set; }
public float Quantity { get; set; } public float Quantity { get; set; }
public float Tax { get; set; } public float Tax { get; set; }
@ -30,9 +31,9 @@ namespace OSI.API.Business.Objects
public class Notes public class Notes
{ {
public string PublicNotes { get; set; } public string? PublicNotes { get; set; }
public string PrivateNotes { get; set; } public string? PrivateNotes { get; set; }
public string Terms { get; set; } public string? Terms { get; set; }
} }
} }

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>OSI_API.DAL</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Mysql.Data" Version="8.0.33" />
</ItemGroup>
</Project>

@ -1,9 +0,0 @@
namespace OSI.API.Business.Objects
{
public class ClientObject
{
public int ClientID { get; set; }
public string ClientName { get; set; }
}
}

@ -4,8 +4,7 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using OSI.API.Business.Objects; using OSI.API.DAL.Invoice;
using OSI.API.Business.DAO;
namespace OSI.API.Controllers namespace OSI.API.Controllers
{ {
@ -21,13 +20,13 @@ namespace OSI.API.Controllers
public override IActionResult Get() public override IActionResult Get()
{ {
//> get all invoices as a list of InvoiceObjects //> 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()); return new JsonResult(dao.GetAll());
} }
public override IActionResult Get(int id) 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)); return new JsonResult(dao.Get(id));
} }

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net5.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<RootNamespace>OSI_API</RootNamespace> <RootNamespace>OSI_API</RootNamespace>
</PropertyGroup> </PropertyGroup>
@ -10,8 +10,12 @@
<PackageReference Include="dbup-mysql" Version="4.5.0" /> <PackageReference Include="dbup-mysql" Version="4.5.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" /> <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" />
<PackageReference Include="Mysql.Data" Version="8.0.25" /> <PackageReference Include="Mysql.Data" Version="8.0.33" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OSI-API.DAL\OSI-API.DAL.csproj" />
</ItemGroup>
</Project> </Project>

Loading…
Cancel
Save