//Changes the state if the account balance changes and if its not a mortgage account public override void StateChangeCheck(BankAccount bankAccount) { if (bankAccount.Balance > UPPER_LIMIT && !bankAccount.Description.Equals("Mortgage")) { bankAccount.AccountStateId = PlatinumState.GetInstance().AccountStateId; } if (bankAccount.Balance < LOWER_LIMIT && !bankAccount.Description.Equals("Mortgage")) { bankAccount.AccountStateId = SilverState.GetInstance().AccountStateId; } }
//Checks if the State is null public static PlatinumState GetInstance() { if (platinumState == null) { //takes the single or default value if its null platinumState = db.PlatinumStates.SingleOrDefault(); //If the state is still null in the db, creates a new state and adds it to the database. if (platinumState == null) { platinumState = new PlatinumState(); db.AccountStates.Add(platinumState); db.SaveChanges(); } } return(platinumState); }