/// <summary> /// Checks if balance is more than the upper limit and sets the right state. /// </summary> public override void StateChangeCheck(BankAccount bankAccount) { //Checks if balance is more than the upper limit to change the state to the next one if (bankAccount.Balance > UpperLimit) { bankAccount.AccountStateId = SilverState.GetInstance().AccountStateId; } }
/// <summary> /// Checks if the balance is greater than the upper limit - If so, change the state to silver /// </summary> /// <param name="bankAccount">Evaluates bankAccount.balance</param> public override void StateChangeCheck(BankAccount bankAccount) { if (!bankAccount.Description.Equals("Mortgage")) //Check to see if the bank account is not a Mortgage account { if (bankAccount.Balance > UPPER_LIMIT) { //Set bankAccount's AccountStateId equal to the GoldState's AccountStateId field //if the balance is greater than the UPPER_LIMIT of this instance bankAccount.AccountStateId = SilverState.GetInstance().AccountStateId; } } }
/// <summary> /// Checks if the balance is greater than the upper limit - If so, change the state to Platinum /// Checks if the balance is less than the lower limit - If so, change the state to Silver /// </summary> /// <param name="bankAccount">Evaluates the bankAccount.Balance</param> public override void StateChangeCheck(BankAccount bankAccount) { if (!bankAccount.Description.Equals("Mortgage")) { if (bankAccount.Balance > UPPER_LIMIT) { bankAccount.AccountStateId = PlatinumState.GetInstance().AccountStateId; } else if (bankAccount.Balance < LOWER_LIMIT) { bankAccount.AccountStateId = SilverState.GetInstance().AccountStateId; } } }
/// <summary> /// Setting the current state to the right one /// </summary> /// <param name="bankAccount"></param> public override void StateChangeCheck(BankAccount bankAccount) { //Checks if balance is less than lower limit if (bankAccount.Balance < this.LowerLimit) { bankAccount.AccountStateId = SilverState.GetInstance().AccountStateId; } //Checks if balance is more than upper limit if (bankAccount.Balance > this.UpperLimit) { bankAccount.AccountStateId = PlatinumState.GetInstance().AccountStateId; } }
/// <summary> /// Gets an instatce of silverstate object /// </summary> /// <returns></returns> public static SilverState GetInstance() { BankOfBITContext db = new BankOfBITContext(); //Checks the database for a silverstate if (silverState == null) { silverState = db.SilverStates.SingleOrDefault(); if (silverState == null) { silverState = new SilverState(); silverState = db.SilverStates.Add(silverState); db.SaveChanges(); } } return(silverState); }
/// <summary> /// Returns an instance of the SilverState /// </summary> /// <returns>SilverState</returns> public static SilverState GetInstance() { //Checks if there is already an instance of SilverState if (silverState == null) { //Retrieves the instance of SilverState from the SilverStates table or null silverState = db.SilverStates.SingleOrDefault(); if (silverState == null) { //Creates a new SilverState object and adds it to the database //Save changes to the database silverState = new SilverState(); db.SilverStates.Add(silverState); db.SaveChanges(); } } return(silverState); }