コード例 #1
0
ファイル: DBCore.cs プロジェクト: tyrgin/net-courses
        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
ファイル: DBCore.cs プロジェクト: tyrgin/net-courses
        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
ファイル: DBCore.cs プロジェクト: tyrgin/net-courses
        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
ファイル: DBCore.cs プロジェクト: tyrgin/net-courses
        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");
            }
        }