Пример #1
0
        public List <SharesEntity> GetShares(AddingSharesToThUserEntity addingSharesToThUserEntity)
        {
            int idShares = addingSharesToThUserEntity.ShareId;
            var shares   = dbContext.Shares.Where(q => q.Id == idShares).ToList();

            return(shares);
        }
Пример #2
0
        public AddingSharesToThUserEntity SelectStocksForUserObjectParameters(UserEntity userEntity, SharesEntity sharesEntity)
        {
            var usersAndShare = transactionService.SelectStocksForUserObjectParameters(userEntity, sharesEntity);
            int count         = usersAndShare.Count;

            try
            {
                return(usersAndShare[0]);
            }
            catch (System.ArgumentOutOfRangeException)
            {
                AddingSharesToThUserEntity addingSharesToThUserEntity = new AddingSharesToThUserEntity();
                return(addingSharesToThUserEntity);
            }
        }
Пример #3
0
        public void RegisterNewSharesToTheUser(AddingSharesToThUserEntity args)
        {
            var entityToAdd = new AddingSharesToThUserEntity()
            {
                UserId = args.UserId, ShareId = args.ShareId, AmountStocks = args.AmountStocks
            };


            if (this.sharesTableRepository.ContainsById(entityToAdd.ShareId) && this.userTableRepository.ContainsById(entityToAdd.UserId))
            {
                this.addingSharesToThUserServiceTableRepository.Add(entityToAdd);
            }

            this.addingSharesToThUserServiceTableRepository.SaveChanges();
        }
Пример #4
0
        public void Run()
        {
            Console.WriteLine("#################################");
            Console.WriteLine("Welcome to the: Trading Simulator");
            Console.WriteLine("#################################");
            Console.WriteLine(@"The database already contains some values necessary to run the application!");
            Console.WriteLine("-----------------------------------------------------------------------------");
            Console.WriteLine("press '1' to start bidding!");
            int userSelectedNumber = int.Parse(Console.ReadLine());

            Console.Clear();
            Console.WriteLine("Bidding start:");
            while (true)
            {
                if (userSelectedNumber == 1)
                {
                    Thread.Sleep(5000);
                    UserEntity seller   = tradingSimulation.ChooseARandomUser();
                    UserEntity customer = tradingSimulation.ChooseARandomUser();
                    while (seller.Equals(customer))
                    {
                        customer = tradingSimulation.ChooseARandomUser();
                    }

                    AddingSharesToThUserEntity sellerSharesToThUserEntity = tradingSimulation.SelectSharesAndUser(seller);

                    SharesEntity sellerShares = tradingSimulation.ChooseShareskValue(sellerSharesToThUserEntity);

                    AddingSharesToThUserEntity 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.RegisterNewTransactionHistory(transactionHistoryEntity);
                }
            }
        }
Пример #5
0
        public void ShouldUpdateUserTable()
        {
            var transactionRepositories           = Substitute.For <ITransactionRepositories>();
            TransactionService transactionService = new TransactionService(transactionRepositories);
            UserEntity         userEntity1        = new UserEntity()
            {
                Balance = 1000
            };
            UserEntity userEntity2 = new UserEntity();
            AddingSharesToThUserEntity addingSharesToThUserEntity1 = new AddingSharesToThUserEntity();
            AddingSharesToThUserEntity addingSharesToThUserEntity2 = new AddingSharesToThUserEntity();

            transactionService.StockPurchaseTransaction(userEntity1, userEntity2, 10, 3, addingSharesToThUserEntity1, addingSharesToThUserEntity2);

            transactionRepositories.Received(1).UpdateUserTable(Arg.Is <UserEntity>(w => w.Balance == userEntity1.Balance));
            transactionRepositories.Received(1).SaveChanges();
        }
Пример #6
0
 public void StockPurchaseTransaction(UserEntity seller, UserEntity customer, int sharePrice, int numberOfSharesToSell, AddingSharesToThUserEntity sellerSharesToThUserEntity, AddingSharesToThUserEntity customerSharesToThUserEntity)
 {
     seller.Balance   += sharePrice * numberOfSharesToSell;
     customer.Balance -= sharePrice * numberOfSharesToSell;
     sellerSharesToThUserEntity.AmountStocks   -= numberOfSharesToSell;
     customerSharesToThUserEntity.AmountStocks += numberOfSharesToSell;
     transactionService.StockPurchaseTransaction(seller, customer, sharePrice, numberOfSharesToSell, sellerSharesToThUserEntity, customerSharesToThUserEntity);
     Console.WriteLine("__________________________________________________________________________________");
     Console.WriteLine(DateTime.Now + " | " + seller.Id + " | " + customer.Id + " | " + sharePrice + " | " + numberOfSharesToSell + " | " + customerSharesToThUserEntity.AmountStocks + " | " + sellerSharesToThUserEntity.AmountStocks + " | ");
     Console.WriteLine("__________________________________________________________________________________");
 }
Пример #7
0
        public SharesEntity ChooseShareskValue(AddingSharesToThUserEntity addingSharesToThUserEntity)
        {
            var shares = transactionService.FindOutTheValueOfShares(addingSharesToThUserEntity);

            return(shares[0]);
        }
 public void Add(AddingSharesToThUserEntity addingSharesToThUserEntity)
 {
     this.dbContext.UsersAndShares.Add(addingSharesToThUserEntity);
 }
Пример #9
0
 public void UpdateUserTable(AddingSharesToThUserEntity userAndShares)
 {
     this.dbContext.Update(userAndShares);
 }
Пример #10
0
 public void StockPurchaseTransaction(UserEntity seller, UserEntity customer, int sharePrice, int numberOfSharesToSell, AddingSharesToThUserEntity sellerSharesToThUserEntity, AddingSharesToThUserEntity customerSharesToThUserEntity)
 {
     transactionRepositories.UpdateUserTable(seller);
     transactionRepositories.UpdateUserTable(customer);
     transactionRepositories.UpdateUserTable(sellerSharesToThUserEntity);
     transactionRepositories.UpdateUserTable(customerSharesToThUserEntity);
     transactionRepositories.SaveChanges();
 }
Пример #11
0
        public List <SharesEntity> FindOutTheValueOfShares(AddingSharesToThUserEntity addingSharesToThUserEntity)
        {
            var shares = transactionRepositories.GetShares(addingSharesToThUserEntity);

            return(shares);
        }