From f1a1b5d067bcfba780f3c45bb67af29d8b5408d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B2=E8=8F=AF?= <42814579+yunwah@users.noreply.github.com> Date: Sat, 9 Apr 2022 04:45:42 -0400 Subject: [PATCH] Update models with more functionality This is a small commit that aims to add some more descriptive functionality to the models. Guest now has more creditcard information such as CCV and an expiration date to bring it in-line with what would be expected. Reservation implemented a very loose cancellation function, this may be moved out. Transaction has a few more tweaks that follows the same goal as guest, however this functionality may be migrated as well. --- OpheliasOasis/Models/Guest.cs | 18 +++++++++-- OpheliasOasis/Models/Reservation.cs | 6 ++-- OpheliasOasis/Models/Transaction.cs | 48 +++++++++++++++++++++-------- 3 files changed, 54 insertions(+), 18 deletions(-) diff --git a/OpheliasOasis/Models/Guest.cs b/OpheliasOasis/Models/Guest.cs index 2bdc344..681fdc8 100644 --- a/OpheliasOasis/Models/Guest.cs +++ b/OpheliasOasis/Models/Guest.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Ophelias.Models; namespace Ophelias.Models { @@ -12,24 +13,35 @@ namespace Ophelias.Models internal string FirstName; internal string LastName; internal string Email; + internal string PhoneNumber; internal string? CreditCard; + internal string? CCV; + internal DateTime CreditCardExpiration; - internal Guest(int id, string fname, string lname, string email) + internal Guest(int id, string fname, string lname, string email, string phone) { Id = id; FirstName = fname; LastName = lname; Email = email; + PhoneNumber = phone; } - internal Guest(int id, string fname, string lname, string email, string cc) + internal Guest(int id, string fname, string lname, string email, string phone, string cc, DateTime expiration, string ccv) { Id = id; FirstName = fname; LastName = lname; Email = email; + PhoneNumber = phone; CreditCard = cc; + CreditCardExpiration = expiration; + } + internal void SetCreditCardInformation(string cc, DateTime expiration, string ccv) + { + CreditCard = cc; + CreditCardExpiration = expiration; + CCV = ccv; } - } internal class GuestList { diff --git a/OpheliasOasis/Models/Reservation.cs b/OpheliasOasis/Models/Reservation.cs index 0e628d6..851c096 100644 --- a/OpheliasOasis/Models/Reservation.cs +++ b/OpheliasOasis/Models/Reservation.cs @@ -48,14 +48,16 @@ namespace Ophelias.Models CheckOut = null; DateChanged = null; } - internal void ChangeReservation(ReservationType type) + internal void ChangeReservation(ReservationType type, Transaction t, BaseRate b) { Status = ReservationStatus.Changed; Type = type; + t.Penalize(this, b.Rate); } - internal void CancelReservation() + internal void CancelReservation(Transaction t) { Status = ReservationStatus.Cancelled; + t.Penalize(this); } } internal enum ReservationStatus diff --git a/OpheliasOasis/Models/Transaction.cs b/OpheliasOasis/Models/Transaction.cs index 887f4ee..598c9d6 100644 --- a/OpheliasOasis/Models/Transaction.cs +++ b/OpheliasOasis/Models/Transaction.cs @@ -26,15 +26,15 @@ namespace Ophelias.Models internal DateTime PayBy; internal DateTime PaidOn; - internal Transaction(int id, ReservationType type, DateTime payby) + internal Transaction(int id, Reservation r, DateTime payby) { Id = id; Paid = 0; Owed = 0; RefundAmount = 0; PaidOff = false; - PayBy = payby; - Multiplier = Fee(type); + PayBy = SetPayByDate(r); + Multiplier = Fee(r.Type); } private bool IsOverdue() { @@ -44,7 +44,17 @@ namespace Ophelias.Models } return false; } - + private DateTime SetPayByDate(Reservation r) + { + switch(r.Type) + { + case ReservationType.Conventional: return r.EndDate; + case ReservationType.Prepaid: return r.StartDate; + case ReservationType.Incentive: return r.EndDate; + case ReservationType.SixtyDayAdvance: return r.StartDate.AddDays(-30); + default: throw new NotImplementedException(); + } + } private void SetChangeFees(ReservationType type, double rate) { switch (type) @@ -78,32 +88,44 @@ namespace Ophelias.Models default: throw new NotImplementedException(); } } - - internal void Penalize(ReservationStatus status, ReservationType type, double rate) + internal void Penalize(Reservation r) { - switch(status) + switch (r.Status) { case ReservationStatus.Active: IsOverdue(); return; - case ReservationStatus.Cancelled: CancellationHandler(type); return; - case ReservationStatus.Changed: SetChangeFees(type, rate); return; + case ReservationStatus.Ended: IsOverdue(); return; + case ReservationStatus.Cancelled: CancellationHandler(r.Type); return; + default: throw new NotImplementedException(); } } - internal double Fee(ReservationType type) + internal void Penalize(Reservation r, double rate) + { + switch(r.Status) + { + case ReservationStatus.Changed: SetChangeFees(r.Type, rate); return; + default: throw new NotImplementedException(); + } + } + private double Fee(ReservationType type) { switch (type) { case ReservationType.Conventional: return 1.0; case ReservationType.Prepaid: return 0.75; - case ReservationType.Incentive: return 1.0; + case ReservationType.Incentive: return GetIncentiveRate(); case ReservationType.SixtyDayAdvance: return 0.85; default: throw new NotImplementedException(); } } - internal void SetFee(double mult) + private double GetIncentiveRate() + { + return 0.80; + } + private void SetFee(double mult) { Multiplier = mult; } - internal void SetRate(double rate) + private void SetRate(double rate) { Rate = rate; }