Finishes the guest part of the models and UI integration
This commit branch has been muddled with changes that are out of scope and cover more than just the models. Specifically it includes completion of basic guest related models, database access, command line interface integration and preventing SQL injection. Total summary of changes: **IMPORTANT CHANGE: All queries are now parameterized to prevent SQL injections. Prior versions are subject to it since the strings were built. - HotelManager This class is used to provide database operations that are outside of scope from a given model. Furthermore if there is no model to work off of, such as creating a new model based off an existing entry, these functions live outside of the model since it makes no sense for models to contain functions where it would retrieve itself with no context. Realistically this could be placed in an empty constructor and address itself, however, for now this functionality has been moved off the model since it is a one use and is not guaranteed to generate a guest. Some functionality for the coming employee management functions are already in there since they share overlap with the guest module. Specifically GetBaseRate for checking and getting the base rate. - DatabaseManager This class has mostly migrated functionality out or switch to parameterized query generation to prevent SQL injections. - Guest, Reservation, and Transaction Classes Migrated functionality to create the database entry and a new entry of guest upon creation as well as update them. - Program (Terminal app) Fully integrated the guest module. Has not undergone extensive testing but does work as of this commit.
This commit is contained in:
@@ -1,9 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Ophelias.Models;
|
||||
using Ophelias.Managers;
|
||||
using System.Data.SQLite;
|
||||
|
||||
namespace Ophelias.Models
|
||||
{
|
||||
@@ -17,6 +13,44 @@ namespace Ophelias.Models
|
||||
internal string? CCV;
|
||||
internal string? Expiration;
|
||||
|
||||
internal Guest(string FirstName, string LastName, string Email, string? CreditCard = null, string? Expiration = null, string? CCV = null)
|
||||
{
|
||||
int Id;
|
||||
using (DatabaseManager Manager = new DatabaseManager())
|
||||
{
|
||||
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "INSERT INTO guests (Fname, Lname, Email, CreditCard, Expiration, CCV) " +
|
||||
"VALUES (@Fname, @Lname, @Email, @CC, @Expiry, @CCV);";
|
||||
cmd.Parameters.AddWithValue("@Fname", FirstName);
|
||||
cmd.Parameters.AddWithValue("@Lname", LastName);
|
||||
cmd.Parameters.AddWithValue("@Email", Email);
|
||||
cmd.Parameters.AddWithValue("@CreditCard", CreditCard);
|
||||
cmd.Parameters.AddWithValue("@Expiration", Expiration);
|
||||
cmd.Parameters.AddWithValue("@CCV", CCV);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
Id = (int)Manager.con.LastInsertRowId;
|
||||
}
|
||||
|
||||
if (CreditCard != null && Expiration != null && CCV != null)
|
||||
{
|
||||
this.Id = Id;
|
||||
this.FirstName = FirstName;
|
||||
this.LastName = LastName;
|
||||
this.Email = Email;
|
||||
this.CreditCard = CreditCard;
|
||||
this.Expiration = Expiration;
|
||||
this.CCV = CCV;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Id = Id;
|
||||
this.FirstName = FirstName;
|
||||
this.LastName = LastName;
|
||||
this.Email = Email;
|
||||
}
|
||||
}
|
||||
internal Guest(int Id, string FirstName, string LastName, string Email, string? CreditCard = null, string? Expiration = null, string? CCV = null)
|
||||
{
|
||||
this.Id = Id;
|
||||
@@ -27,6 +61,28 @@ namespace Ophelias.Models
|
||||
this.Expiration = Expiration;
|
||||
this.CCV = CCV;
|
||||
}
|
||||
internal void UpdateGuest(int Id, string? FirstName = null, string? LastName = null, string? Email = null, string? CreditCard = null, string? Expiration = null, string? CCV = null)
|
||||
{
|
||||
using (DatabaseManager Manager = new DatabaseManager())
|
||||
{
|
||||
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = QueryBuilder.UpdateGuest(Id, FirstName, LastName, Email, CreditCard, Expiration, CCV);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
if (FirstName != null)
|
||||
this.FirstName = FirstName;
|
||||
if (LastName != null)
|
||||
this.LastName = LastName;
|
||||
if (FirstName != null)
|
||||
this.Email = Email;
|
||||
this.CreditCard = CreditCard;
|
||||
if (FirstName != null)
|
||||
this.Expiration = Expiration;
|
||||
if (FirstName != null)
|
||||
this.CCV = CCV;
|
||||
}
|
||||
internal void SetCreditCardInformation(string CreditCard, string Expiration, string CCV)
|
||||
{
|
||||
this.CreditCard = CreditCard;
|
||||
|
||||
Reference in New Issue
Block a user