Updates the guest model with documentation

Some other changes besides documentation was removal of unused code.
This commit is contained in:
雲華
2022-04-17 00:59:38 -04:00
parent 28890a2b6a
commit 2c6aac58b2

View File

@@ -5,6 +5,14 @@ namespace Ophelias.Models
{ {
internal class Guest internal class Guest
{ {
/*
* This class represents a guest in the real world.
* A guest in the eyes of the system is comprised of
* a unique ID, a first and last name, an email, and
* payment information. The payment information is optional
* as they may not specify it at the time or have none readily
* available.
*/
internal int Id; internal int Id;
internal string FirstName; internal string FirstName;
internal string LastName; internal string LastName;
@@ -15,10 +23,17 @@ namespace Ophelias.Models
internal Guest(string FirstName, string LastName, string Email, string? CreditCard = null, string? Expiration = null, string? CCV = null) internal Guest(string FirstName, string LastName, string Email, string? CreditCard = null, string? Expiration = null, string? CCV = null)
{ {
/*
* This creates a new guest under the assumption that they never existed previously.
* As a result, this function will create a new entry in the database and generate
* a unique ID for that customer. These details are then assigned to create a new instance
* of the guest after the database query is executed. For constraints on Guests, see the Database
* class.
*/
int Id; int Id;
using (Database Manager = new()) using (Database Manager = new()) // Opens a new connection to the database
{ {
using (SQLiteCommand cmd = Manager.con.CreateCommand()) using (SQLiteCommand cmd = Manager.con.CreateCommand()) // Creates a new command that will be executed in the database
{ {
cmd.CommandText = "INSERT INTO guests (Fname, Lname, Email, CreditCard, Expiration, CCV) " + cmd.CommandText = "INSERT INTO guests (Fname, Lname, Email, CreditCard, Expiration, CCV) " +
"VALUES (@Fname, @Lname, @Email, @CreditCard, @Expiry, @CCV);"; "VALUES (@Fname, @Lname, @Email, @CreditCard, @Expiry, @CCV);";
@@ -30,29 +45,21 @@ namespace Ophelias.Models
cmd.Parameters.AddWithValue("@CCV", CCV); cmd.Parameters.AddWithValue("@CCV", CCV);
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
} }
Id = (int)Manager.con.LastInsertRowId; Id = (int)Manager.con.LastInsertRowId; // Gets the auto incremented ID of the guest that was just created and assigns it to the guest
}
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;
} }
this.Id = Id;
this.FirstName = FirstName;
this.LastName = LastName;
this.Email = Email;
this.CreditCard = CreditCard;
this.Expiration = Expiration;
this.CCV = CCV;
} }
internal Guest(int Id, string FirstName, string LastName, string Email, string? CreditCard = null, string? Expiration = null, string? CCV = null) internal Guest(int Id, string FirstName, string LastName, string Email, string? CreditCard = null, string? Expiration = null, string? CCV = null)
{ {
/*
* This creates an instance of a guest assuming they already exist as an ID is required.
*/
this.Id = Id; this.Id = Id;
this.FirstName = FirstName; this.FirstName = FirstName;
this.LastName = LastName; this.LastName = LastName;
@@ -63,9 +70,15 @@ namespace Ophelias.Models
} }
internal void UpdateGuest(int Id, string? FirstName = null, string? LastName = null, string? Email = null, string? CreditCard = null, string? Expiration = null, string? CCV = null) internal void UpdateGuest(int Id, string? FirstName = null, string? LastName = null, string? Email = null, string? CreditCard = null, string? Expiration = null, string? CCV = null)
{ {
using (Database Manager = new()) /*
* UpdateGuest provides functionality that enables guests to update their account information.
* This information is first passed off to the database so the changes can accurately be reflected
* and then the changes are copied to the existing guest if they are not null. Null changes are considered
* to be no changes and not an erasure of data.
*/
using (Database Manager = new()) // Opens a new connection to the database
{ {
using SQLiteCommand cmd = Manager.con.CreateCommand(); using SQLiteCommand cmd = Manager.con.CreateCommand(); // Creates a new command that will be executed in the database
cmd.CommandText = QueryBuilder.UpdateGuest(Id, FirstName, LastName, Email, CreditCard, Expiration, CCV); cmd.CommandText = QueryBuilder.UpdateGuest(Id, FirstName, LastName, Email, CreditCard, Expiration, CCV);
cmd.Parameters.AddWithValue("@Fname", FirstName); cmd.Parameters.AddWithValue("@Fname", FirstName);
cmd.Parameters.AddWithValue("@Lname", LastName); cmd.Parameters.AddWithValue("@Lname", LastName);
@@ -104,20 +117,5 @@ namespace Ophelias.Models
this.CCV = CCV; this.CCV = CCV;
} }
} }
internal void SetCreditCardInformation(string CreditCard, string Expiration, string CCV)
{
this.CreditCard = CreditCard;
this.Expiration = Expiration;
this.CCV = CCV;
}
}
internal class GuestList
{
internal List<Guest> Guests;
internal GuestList()
{
Guests = new();
}
} }
} }