diff --git a/OpheliasOasis/Models/Guest.cs b/OpheliasOasis/Models/Guest.cs index aac2fa4..9dc015b 100644 --- a/OpheliasOasis/Models/Guest.cs +++ b/OpheliasOasis/Models/Guest.cs @@ -5,6 +5,14 @@ namespace Ophelias.Models { 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 string FirstName; 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) { + /* + * 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; - 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) " + "VALUES (@Fname, @Lname, @Email, @CreditCard, @Expiry, @CCV);"; @@ -30,29 +45,21 @@ namespace Ophelias.Models 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; + Id = (int)Manager.con.LastInsertRowId; // Gets the auto incremented ID of the guest that was just created and assigns it to the guest } + 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) { + /* + * This creates an instance of a guest assuming they already exist as an ID is required. + */ this.Id = Id; this.FirstName = FirstName; 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) { - 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.Parameters.AddWithValue("@Fname", FirstName); cmd.Parameters.AddWithValue("@Lname", LastName); @@ -104,20 +117,5 @@ namespace Ophelias.Models 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 Guests; - - internal GuestList() - { - Guests = new(); - } } }