Further major refactoring of code
This is another commit to mostly version the code. There have been a considerable number of changes and there is functionality that I am still determining whether it should lie within the manager or the model class itself. It makes the most sense to possibly add the "Update" or database manipulation functions on the models themselves. On the other hand, instead of creating and generating the ID in the model, the current design is to create the entry in the database first, get the last insert row ID and create a new and complete model that is returned back by the function. This allows us to leverage the autoincrement functionality of the database rather than trying to design a function and/ or make an additional call to the database. **NOTE: Code is non-functional due to some classes not having their errors resolved.
This commit is contained in:
@@ -4,7 +4,6 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Ophelias.Models;
|
||||
using System.Net.Mail;
|
||||
|
||||
namespace Ophelias.Models
|
||||
{
|
||||
@@ -14,34 +13,30 @@ 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 string? Expiration;
|
||||
|
||||
internal Guest(int id, string fname, string lname, string email, string phone)
|
||||
internal Guest(string FirstName, string LastName, string Email)
|
||||
{
|
||||
Id = id;
|
||||
FirstName = fname;
|
||||
LastName = lname;
|
||||
Email = email;
|
||||
PhoneNumber = phone;
|
||||
this.FirstName = FirstName;
|
||||
this.LastName = LastName;
|
||||
this.Email = Email;
|
||||
}
|
||||
internal Guest(int id, string fname, string lname, string email, string phone, string cc, DateTime expiration, string ccv)
|
||||
internal Guest(string FirstName, string LastName, string Email, string CreditCard, string Expiration, string CCV)
|
||||
{
|
||||
Id = id;
|
||||
FirstName = fname;
|
||||
LastName = lname;
|
||||
Email = email;
|
||||
PhoneNumber = phone;
|
||||
CreditCard = cc;
|
||||
CreditCardExpiration = expiration;
|
||||
this.FirstName = FirstName;
|
||||
this.LastName = LastName;
|
||||
this.Email = Email;
|
||||
this.CreditCard = CreditCard;
|
||||
this.Expiration = Expiration;
|
||||
this.CCV = CCV;
|
||||
}
|
||||
internal void SetCreditCardInformation(string cc, DateTime expiration, string ccv)
|
||||
internal void SetCreditCardInformation(string CreditCard, string Expiration, string CCV)
|
||||
{
|
||||
CreditCard = cc;
|
||||
CreditCardExpiration = expiration;
|
||||
CCV = ccv;
|
||||
this.CreditCard = CreditCard;
|
||||
this.Expiration = Expiration;
|
||||
this.CCV = CCV;
|
||||
}
|
||||
}
|
||||
internal class GuestList
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
using Ophelias.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Ophelias.Models;
|
||||
using Ophelias.Managers;
|
||||
|
||||
namespace Ophelias.Models
|
||||
{
|
||||
@@ -43,18 +49,6 @@ namespace Ophelias.Models
|
||||
CheckOut = null;
|
||||
DateChanged = null;
|
||||
}
|
||||
internal void ChangeReservation(ReservationType type, Transaction t, BaseRate b)
|
||||
{
|
||||
Status = ReservationStatus.Changed;
|
||||
Type = type;
|
||||
t.Penalize(this, b.Rate);
|
||||
}
|
||||
internal void CancelReservation(Transaction t)
|
||||
{
|
||||
Status = ReservationStatus.Cancelled;
|
||||
t.Penalize(this);
|
||||
|
||||
}
|
||||
}
|
||||
internal enum ReservationStatus
|
||||
{
|
||||
@@ -70,13 +64,4 @@ namespace Ophelias.Models
|
||||
Incentive,
|
||||
SixtyDayAdvance,
|
||||
}
|
||||
internal class ReservationList
|
||||
{
|
||||
internal List<Reservation> Reservations;
|
||||
|
||||
internal ReservationList()
|
||||
{
|
||||
Reservations = new List<Reservation>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,57 +14,28 @@ namespace Ophelias.Models
|
||||
|
||||
internal int Id { get; set; }
|
||||
internal double Rate { get; set; }
|
||||
internal double Paid { get; set; }
|
||||
internal double Owed { get; set; }
|
||||
internal double? Penalty { get; set; }
|
||||
internal double Penalty { get; set; }
|
||||
internal double Multiplier { get; set; }
|
||||
internal double RefundAmount { get; set; }
|
||||
internal bool? Late { get; set; }
|
||||
internal bool PaidOff { get; set; }
|
||||
internal DateTime PayBy { get; set; }
|
||||
internal DateTime PaidOn { get; set; }
|
||||
internal DateTime? PaidOn { get; set; } = null;
|
||||
|
||||
internal Transaction(int id, Reservation r, DateTime payby)
|
||||
internal Transaction(int Id, double Rate, double Owed, double Penalty,
|
||||
double Multiplier, double RefundAmount,
|
||||
DateTime PayBy, DateTime? PaidOn = null)
|
||||
{
|
||||
Id = id;
|
||||
Paid = 0;
|
||||
Owed = 0;
|
||||
RefundAmount = 0;
|
||||
PaidOff = false;
|
||||
PayBy = SetPayByDate(r);
|
||||
Multiplier = Fee(r.Type);
|
||||
this.Id = Id;
|
||||
this.Rate = Rate;
|
||||
this.Owed = Owed;
|
||||
this.Penalty = Penalty;
|
||||
this.Multiplier = Multiplier;
|
||||
this.RefundAmount = RefundAmount;
|
||||
this.PayBy = PayBy;
|
||||
this.PaidOn = PaidOn;
|
||||
}
|
||||
private bool IsOverdue()
|
||||
{
|
||||
if (DateTime.Now > PayBy)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
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)
|
||||
{
|
||||
case ReservationType.Conventional: return;
|
||||
case ReservationType.Prepaid: SetFee(PenaltyMultipler); SetRate(rate); return;
|
||||
case ReservationType.Incentive: return;
|
||||
case ReservationType.SixtyDayAdvance: SetFee(PenaltyMultipler); SetRate(rate); return;
|
||||
default: throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
private void CancellationHandler(ReservationType type)
|
||||
|
||||
private void Cancellation(ReservationType type)
|
||||
{
|
||||
void SetRefund()
|
||||
{
|
||||
@@ -98,84 +69,43 @@ namespace Ophelias.Models
|
||||
}
|
||||
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 GetIncentiveRate();
|
||||
case ReservationType.SixtyDayAdvance: return 0.85;
|
||||
default: throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
private double GetIncentiveRate()
|
||||
{
|
||||
return 0.80;
|
||||
}
|
||||
private void SetFee(double mult)
|
||||
{
|
||||
Multiplier = mult;
|
||||
}
|
||||
private void SetRate(double rate)
|
||||
{
|
||||
Rate = rate;
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
internal void Pay(double amount)
|
||||
{
|
||||
if (RefundAmount > -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Paid += amount;
|
||||
if (Paid == Owed)
|
||||
{
|
||||
Owed -= Paid;
|
||||
PaidOn = DateTime.Now;
|
||||
PaidOff = true;
|
||||
} else if (Paid > Owed)
|
||||
{
|
||||
RefundAmount = Paid - Owed;
|
||||
Owed = Owed - Paid + RefundAmount;
|
||||
PaidOn = DateTime.Now;
|
||||
PaidOff = true;
|
||||
} else
|
||||
{
|
||||
Owed -= Paid;
|
||||
PaidOn = DateTime.Now;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
internal static class TransactionFees
|
||||
internal static class TransactionInfo
|
||||
{
|
||||
static double ConventionalFee = 1.0;
|
||||
static double PrepaidFee = 0.75;
|
||||
static double IncentiveFee = OccupancyIncentive();
|
||||
static double SixtyDayFee = 0.85;
|
||||
internal static double ConventionalFee = 1.0;
|
||||
internal static double PrepaidFee = 0.75;
|
||||
internal static double IncentiveFee = IncentiveRate();
|
||||
internal static double SixtyDayFee = 0.85;
|
||||
|
||||
private static double OccupancyIncentive()
|
||||
private static double IncentiveRate()
|
||||
{
|
||||
int thirtyDayOcc;
|
||||
using (DatabaseManager dbm = new DatabaseManager())
|
||||
{
|
||||
if (dbm.cur == null)
|
||||
throw new NotImplementedException();
|
||||
|
||||
thirtyDayOcc = DatabaseFunctions.GetThirtyDayOccupancy(dbm.cur, DateTime.Now);
|
||||
}
|
||||
thirtyDayOcc = HotelManager.GetThirtyDayOccupancy(DateTime.Now);
|
||||
if ((double)(thirtyDayOcc / 45.0) <= 0.6)
|
||||
return 0.80;
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
internal static DateTime GetPayByDate(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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
internal class TransactionList
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user