예제 #1
0
        public List <SharesEntity> GetShares(UserAndSharesEntity addingSharesToThUserEntity)
        {
            int idShares = addingSharesToThUserEntity.ShareId;
            var shares   = dbContext.Shares.Where(q => q.Id == idShares).ToList();

            return(shares);
        }
예제 #2
0
        public List <SharesEntity> FindOutTheValueOfShares(UserAndSharesEntity userAndSharesEntity)
        {
            TransactionRepositories transactionRepositories = new TransactionRepositories(dbContext);
            var shares = transactionRepositories.GetShares(userAndSharesEntity);

            return(shares);
        }
        public void RunTradingSimulation()
        {
            TradingSimulation tradingSimulation = new TradingSimulation(dbContext);
            UserEntity        seller            = tradingSimulation.ChooseARandomUser();
            UserEntity        customer          = tradingSimulation.ChooseARandomUser();

            while (seller.Equals(customer))
            {
                customer = tradingSimulation.ChooseARandomUser();
            }

            UserAndSharesEntity sellerSharesToThUserEntity = tradingSimulation.SelectSharesAndUser(seller);

            SharesEntity sellerShares = tradingSimulation.ChooseShareskValue(sellerSharesToThUserEntity);

            UserAndSharesEntity customerSharesToThUserEntity = tradingSimulation.SelectStocksForUserObjectParameters(customer, sellerShares);

            int Price = tradingSimulation.RandomNumberGenerator((int)sellerShares.Price);

            int NumberOfShares = tradingSimulation.RandomNumberGenerator(sellerSharesToThUserEntity.AmountStocks);

            tradingSimulation.StockPurchaseTransaction(seller, customer, Price, NumberOfShares, sellerSharesToThUserEntity, customerSharesToThUserEntity);

            TransactionHistoryEntity transactionHistoryEntity = new TransactionHistoryEntity()
            {
                DateTimeBay = DateTime.Now,
                SellerId    = seller.Id,
                CustomerId  = customer.Id,
                AmountShare = NumberOfShares,
                Cost        = Price
            };
            TransactionService transactionService = new TransactionService(dbContext);

            transactionService.RegisterNewTransactionHistory(transactionHistoryEntity);
        }
        public SharesEntity ChooseShareskValue(UserAndSharesEntity addingSharesToThUserEntity)
        {
            TransactionService transactionService = new TransactionService(dbContext);
            var shares = transactionService.FindOutTheValueOfShares(addingSharesToThUserEntity);

            return(shares[0]);
        }
        public UserAndSharesEntity SelectStocksForUserObjectParameters(UserEntity userEntity, SharesEntity sharesEntity)
        {
            TransactionService transactionService = new TransactionService(dbContext);
            var usersAndShare = transactionService.SelectStocksForUserObjectParameters(userEntity, sharesEntity);
            int count         = usersAndShare.Count;

            try
            {
                return(usersAndShare[0]);
            }
            catch (System.ArgumentOutOfRangeException)
            {
                UserAndSharesEntity userAndSharesEntity = new UserAndSharesEntity();
                return(userAndSharesEntity);
            }
        }
예제 #6
0
        public void StockPurchaseTransaction(UserEntity seller, UserEntity customer, int sharePrice, int numberOfSharesToSell, UserAndSharesEntity sellerSharesToThUserEntity, UserAndSharesEntity customerSharesToThUserEntity)
        {
            TransactionRepositories transactionRepositories = new TransactionRepositories(dbContext);

            transactionRepositories.UpdateUserTable(seller);
            transactionRepositories.UpdateUserTable(customer);
            transactionRepositories.UpdateUserTable(sellerSharesToThUserEntity);
            transactionRepositories.UpdateUserTable(customerSharesToThUserEntity);
            transactionRepositories.SaveChanges();
        }
예제 #7
0
 public void UpdateUserTable(UserAndSharesEntity userAndShares)
 {
     this.dbContext.Update(userAndShares);
 }
        public void StockPurchaseTransaction(UserEntity seller, UserEntity customer, int sharePrice, int numberOfSharesToSell, UserAndSharesEntity sellerSharesToThUserEntity, UserAndSharesEntity customerSharesToThUserEntity)
        {
            TransactionService transactionService = new TransactionService(dbContext);

            seller.Balance   += sharePrice * numberOfSharesToSell;
            customer.Balance -= sharePrice * numberOfSharesToSell;
            sellerSharesToThUserEntity.AmountStocks   -= numberOfSharesToSell;
            customerSharesToThUserEntity.AmountStocks += numberOfSharesToSell;
            transactionService.StockPurchaseTransaction(seller, customer, sharePrice, numberOfSharesToSell, sellerSharesToThUserEntity, customerSharesToThUserEntity);
        }