Пример #1
0
        public void UpdatingBalance(TraiderBalance sellerBalance, TraiderBalance buyerBalance, SharesType sharesType, Deal newDeal)
        {
            if (sharesType == SharesType.SimpleType)
            {
                sellerBalance.SimpleType -= (int)newDeal.Price;
            }
            if (sharesType == SharesType.PreferenceShare)
            {
                sellerBalance.PreferenceShare -= (int)newDeal.Price;
            }

            sellerBalance.Balance += newDeal.Price * (decimal)sharesType;

            if (sellerBalance.Balance == 0)
            {
                sellerBalance.Zone = "Red";
            }
            if (sellerBalance.Balance > 0 && sellerBalance.Balance <= 1000)
            {
                sellerBalance.Zone = "Orange";
            }
            if (sellerBalance.Balance > 1000)
            {
                sellerBalance.Zone = "Green";
            }

            if (sharesType == SharesType.SimpleType)
            {
                buyerBalance.SimpleType += (int)newDeal.Price;
            }
            if (sharesType == SharesType.PreferenceShare)
            {
                buyerBalance.PreferenceShare += (int)newDeal.Price;
            }

            buyerBalance.Balance -= newDeal.Price * (decimal)sharesType;

            if (buyerBalance.Balance == 0)
            {
                buyerBalance.Zone = "Red";
            }
            if (buyerBalance.Balance > 0 && buyerBalance.Balance <= 1000)
            {
                buyerBalance.Zone = "Orange";
            }
            if (buyerBalance.Balance > 1000)
            {
                buyerBalance.Zone = "Green";
            }

            this.dataContex.Update(sellerBalance);
            this.dataContex.Update(buyerBalance);
            this.dataContex.SaveChanges();
        }
Пример #2
0
        public void RegisterNewDeal(Deal deal)
        {
            TraiderBalance newSellerBalance = GetMostWantedBalanceById(deal.ID_seller);
            TraiderBalance newBuyerBalance  = GetMostWantedBalanceById(deal.ID_buyer);

            if (deal.SharesType == SharesType.SimpleType)
            {
                UpdatingBalance(newSellerBalance, newBuyerBalance, SharesType.SimpleType, deal);
            }
            if (deal.SharesType == SharesType.PreferenceShare)
            {
                UpdatingBalance(newSellerBalance, newBuyerBalance, SharesType.PreferenceShare, deal);
            }
        }
Пример #3
0
        public void AddNewTraiderWithStarterPack(Traider traider)
        {
            this.dataContex.Add(traider);
            TraiderBalance starterPack = new TraiderBalance()
            {
                ID              = traider.ID,
                SimpleType      = 5000,
                PreferenceShare = 1000,
                Balance         = 10000,
                Zone            = "Green"
            };

            this.dataContex.Add(starterPack);
            this.dataContex.SaveChanges();
        }
Пример #4
0
        public void RegisterNewDeal(Deal deal)
        {
            TraiderBalance newSellerBalance = GetMostWantedBalanceById(deal.ID_seller);
            TraiderBalance newBuyerBalance  = GetMostWantedBalanceById(deal.ID_buyer);

            if (newBuyerBalance.Balance > 0)
            {
                if (deal.SharesType == SharesType.SimpleType)
                {
                    UpdatingBalance(newSellerBalance, newBuyerBalance, SharesType.SimpleType, deal);
                }
                if (deal.SharesType == SharesType.PreferenceShare)
                {
                    UpdatingBalance(newSellerBalance, newBuyerBalance, SharesType.PreferenceShare, deal);
                }
            }
            else
            {
                Console.WriteLine("Deal not confirm, buyer is bankrot");
            }
        }