//constructor for seasonpass public SeasonPass(int id, string vt, string iun, DateTime sd, DateTime ed, Vehicle v, string validity) { // season pass states goes here pendingState = new PendingState(this); validState = new ValidState(this); terminatedState = new TerminatedState(this); expiredState = new ExpiredState(this); rejectedState = new RejectedState(this); // added the ability to force seasonpass at the correct state upon creation if (validity == "pending") { currentState = pendingState; } else if (validity == "valid") { currentState = validState; } else if (validity == "terminated") { currentState = terminatedState; } else if (validity == "expired") { currentState = expiredState; } else if (validity == "rejected") { currentState = rejectedState; } //rest of the property define below for seasonpass seasonPassID = id; vehicleType = vt; iuNumber = iun; startDate = sd; endDate = ed; vehicle = v; if (DateTime.Now >= startDate) { remainingMonth = ((endDate.Year - DateTime.Now.Year) * 12) + endDate.Month - DateTime.Now.Month; } else { remainingMonth = ((endDate.Year - startDate.Year) * 12) + endDate.Month - startDate.Month; } //Check for negatives and sets it it 0, and state to expired if (remainingMonth <= 0) { remainingMonth = 0; currentState = expiredState; } v.VehicleSeasonPass = this; payment = new List <Payment>(); // a list of payment }
// sets the state public void SetCurrentState(ISeasonPassState currentState) { this.currentState = currentState; }