Ejemplo n.º 1
0
        /// <summary>
        /// Gets an instance of the next transaction number
        /// </summary>
        /// <returns></returns>
        public static NextTransactionNumber GetInstance()
        {
            BankOfBITContext db = new BankOfBITContext();

            if (nextTransactionNumber == null)
            {
                nextTransactionNumber = db.NextTransactionNumbers.SingleOrDefault();

                if (nextTransactionNumber == null)
                {
                    nextTransactionNumber = new NextTransactionNumber();
                    nextTransactionNumber = db.NextTransactionNumbers.Add(nextTransactionNumber);
                    db.SaveChanges();
                }
            }
            return(nextTransactionNumber);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Checks if there is a record of the bronze state in the database,
        /// if there is one, it returns it, if there is not, it creates one
        /// </summary>
        /// <returns>The bronze state found or created</returns>
        public static BronzeState GetInstance()
        {
            BankOfBITContext db = new BankOfBITContext();

            if (bronzeState == null)
            {
                bronzeState = db.BronzeStates.SingleOrDefault();

                if (bronzeState == null)
                {
                    bronzeState = new BronzeState();
                    bronzeState = db.BronzeStates.Add(bronzeState);
                    db.SaveChanges();
                }
            }
            return(bronzeState);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets an instance of the next savings account
        /// </summary>
        public static NextSavingsAccount GetInstance()
        {
            BankOfBITContext db = new BankOfBITContext();

            if (nextSavingsAccount == null)
            {
                nextSavingsAccount = db.NextSavingsAccounts.SingleOrDefault();

                if (nextSavingsAccount == null)
                {
                    nextSavingsAccount = new NextSavingsAccount();
                    nextSavingsAccount = db.NextSavingsAccounts.Add(nextSavingsAccount);
                    db.SaveChanges();
                }
            }
            return(nextSavingsAccount);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets an instance of a gold state (singleton pattern)
        /// </summary>
        public static GoldState GetInstance()
        {
            BankOfBITContext db = new BankOfBITContext();

            //Checks if gold state has a value
            if (goldState == null)
            {
                goldState = db.GoldStates.SingleOrDefault();

                if (goldState == null)
                {
                    goldState = new GoldState();
                    goldState = db.GoldStates.Add(goldState);
                    db.SaveChanges();
                }
            }
            return(goldState);
        }
Ejemplo n.º 5
0
        /// <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);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Changes the state of the account based on the balance
        /// </summary>
        public void ChangeState()
        {
            //Creating a new instance of the database
            BankOfBITContext db = new BankOfBITContext();

            //Loops through the number of the available bank account types
            for (int i = 0; i < NUMBER_OF_ACCOUNT_STATES; i++)
            {
                //Sets the state id to the account sate id
                int currentStateId = this.AccountStateId;

                //Sets the account current state to the one that is stored in the database
                AccountState currentState = db.AccountStates.Where(x => x.AccountStateId == currentStateId).SingleOrDefault();

                //Changing the current state
                currentState.StateChangeCheck(this);

                //Saving the entries to the database
                db.SaveChanges();
            }
        }