Beispiel #1
0
 public IQueryable <Shareholder> GetMostWantedShareholdersByShareholder(Shareholder shareholder)
 {
     return(this.dataContext.Shareholders.Where(w =>
                                                w.FirstName == shareholder.FirstName
                                                &&
                                                w.LastName == shareholder.LastName
                                                &&
                                                w.PhoneNumber == shareholder.PhoneNumber));
 }
Beispiel #2
0
        public void RegisterNewShareholderWithStartingBalance(Shareholder shareholder)
        {
            this.dataContext.Add(shareholder);

            RegisterNewBalance(
                shareholderId: shareholder.Id,
                firstType: 1000,
                secondType: 1000,
                thirdType: 1000,
                balanceValue: 7000,
                balanceZone: "middle");
            //this.dataContext.SaveChanges();
        }
Beispiel #3
0
        public void RegisterNewTrade(Trade trade, Shareholder shareholder, Shareholder buyer)
        {
            this.dataContext.Add(trade);

            var newShareholderBalance = GetMostWantedBalanceById(shareholder.Id);

            var newBuyerBalance = GetMostWantedBalanceById(buyer.Id);

            switch (trade.ValueType)
            {
            case SharesTypes.FirstType:
            {
                PreparationsForUpdatingBalances(newShareholderBalance, newBuyerBalance, SharesTypes.FirstType, trade);

                UpdateBalancesAndSaveChanges(newBuyerBalance, newShareholderBalance);

                break;
            }

            case SharesTypes.SecondType:
            {
                PreparationsForUpdatingBalances(newShareholderBalance, newBuyerBalance, SharesTypes.SecondType, trade);

                UpdateBalancesAndSaveChanges(newBuyerBalance, newShareholderBalance);

                break;
            }

            case SharesTypes.ThirdType:
            {
                PreparationsForUpdatingBalances(newShareholderBalance, newBuyerBalance, SharesTypes.ThirdType, trade);

                UpdateBalancesAndSaveChanges(newBuyerBalance, newShareholderBalance);

                break;
            }
            }

            void UpdateBalancesAndSaveChanges(Balance buyerBalance, Balance shareholderBalance)
            {
                this.dataContext.Update(buyerBalance);

                this.dataContext.Update(shareholderBalance);

                this.dataContext.SaveChanges();
            }
        }
Beispiel #4
0
        public void RegisterNewTrade(Trade trade, Shareholder shareholder, Shareholder buyer)
        {
            this.dataContext.Add(trade);

            var newShareholderBalance = GetMostWantedBalanceById(shareholder.Id);

            var newBuyerBalance = GetMostWantedBalanceById(buyer.Id);

            switch (trade.ValueType)
            {
            case SharesTypes.FirstType:
            {
                PreparationsForUpdatingBalances(newShareholderBalance, newBuyerBalance, SharesTypes.FirstType, trade);

                UpdateBalancesAndSaveChanges(newBuyerBalance, newShareholderBalance);

                break;
            }

            case SharesTypes.SecondType:
            {
                PreparationsForUpdatingBalances(newShareholderBalance, newBuyerBalance, SharesTypes.SecondType, trade);

                UpdateBalancesAndSaveChanges(newBuyerBalance, newShareholderBalance);

                break;
            }

            case SharesTypes.ThirdType:
            {
                PreparationsForUpdatingBalances(newShareholderBalance, newBuyerBalance, SharesTypes.ThirdType, trade);

                UpdateBalancesAndSaveChanges(newBuyerBalance, newShareholderBalance);

                break;
            }
            }

            void UpdateBalancesAndSaveChanges(Balance buyerBalance, Balance shareholderBalance)
            {
                this.dataContext.Update(buyerBalance);

                this.dataContext.Update(shareholderBalance);

                this.dataContext.SaveChanges();
            }

            void PreparationsForUpdatingBalances(Balance shareholderBalance, Balance buyerBalance, SharesTypes sharesType, Trade inputedTrade)
            {
                if (sharesType == SharesTypes.FirstType)
                {
                    shareholderBalance.FirstType -= (int)inputedTrade.Value;
                }

                if (sharesType == SharesTypes.SecondType)
                {
                    shareholderBalance.SecondType -= (int)inputedTrade.Value;
                }

                if (sharesType == SharesTypes.ThirdType)
                {
                    shareholderBalance.ThirdType -= (int)inputedTrade.Value;
                }


                shareholderBalance.BalanceValue += inputedTrade.Value * (Decimal)sharesType;//SharesTypes.SecondType;

                if (shareholderBalance.BalanceValue == 0)
                {
                    shareholderBalance.BalanceZone = "Orange Zone!";
                }

                if (shareholderBalance.BalanceValue > 0)
                {
                    shareholderBalance.BalanceZone = "low";
                }

                if (shareholderBalance.BalanceValue > 5000)
                {
                    shareholderBalance.BalanceZone = "middle";
                }

                if (shareholderBalance.BalanceValue > 10000)
                {
                    shareholderBalance.BalanceZone = "hihg";
                }

                if (shareholderBalance.BalanceValue > 10000)
                {
                    shareholderBalance.BalanceZone = "insane";
                }

                if (sharesType == SharesTypes.FirstType)
                {
                    buyerBalance.FirstType += (int)inputedTrade.Value;
                }

                if (sharesType == SharesTypes.SecondType)
                {
                    buyerBalance.SecondType += (int)inputedTrade.Value;
                }

                if (sharesType == SharesTypes.ThirdType)
                {
                    buyerBalance.ThirdType += (int)inputedTrade.Value;
                }

                buyerBalance.BalanceValue -= inputedTrade.Value * (Decimal)sharesType;//SharesTypes.SecondType;

                if (buyerBalance.BalanceValue < 5000)
                {
                    buyerBalance.BalanceZone = "low";
                }

                if (buyerBalance.BalanceValue == 0)
                {
                    buyerBalance.BalanceZone = "Orange Zone!";
                }

                if (buyerBalance.BalanceValue < 0)
                {
                    buyerBalance.BalanceZone = "Black Zone!";
                }
            }
        }