Exemplo n.º 1
0
        public List <SharesEntity> GetShares(AddingSharesToThUserEntity addingSharesToThUserEntity)
        {
            int idShares = addingSharesToThUserEntity.ShareId;
            var shares   = dbContext.Shares.Where(q => q.Id == idShares).ToList();

            return(shares);
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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();
        }
Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 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();
        }
Exemplo n.º 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("__________________________________________________________________________________");
 }
Exemplo n.º 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);
 }
Exemplo n.º 9
0
 public void UpdateUserTable(AddingSharesToThUserEntity userAndShares)
 {
     this.dbContext.Update(userAndShares);
 }
Exemplo n.º 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();
 }
Exemplo n.º 11
0
        public List <SharesEntity> FindOutTheValueOfShares(AddingSharesToThUserEntity addingSharesToThUserEntity)
        {
            var shares = transactionRepositories.GetShares(addingSharesToThUserEntity);

            return(shares);
        }