Пример #1
0
        public TradeOffer(Traider traider, Price price)
        {
            Contract.Requires(() => traider != null, $"{nameof(traider)} may not be null");
            Contract.Requires(() => price != null, $"{nameof(price)} may not be null");

            Traider = traider;
            Price   = price;
        }
Пример #2
0
        public void Update(Traider entity)
        {
            Traider upd = this.Traiders.First(f => f.ID == entity.ID);

            upd.FirstName = entity.FirstName;
            upd.Surname   = entity.Surname;
            upd.PhoneNum  = entity.PhoneNum;
        }
Пример #3
0
        public void Withdraw(Traider traider, Stock stock)
        {
            var _stock = traider.Stocks.Single(x => x.StockType == stock.StockType);

            _stock.Quantity -= stock.Quantity;
            traider.Balance += stock.StockType.Price * stock.Quantity;
            UpdateStock(_stock);
        }
Пример #4
0
 public void ProcessTrade(Traider seller, Traider buyer, Stock stock)
 {
     Withdraw(seller, stock);
     Acquire(buyer, stock);
     RegisterOperation(buyer, seller, stock);
     UpdateTraider(buyer);
     UpdateTraider(seller);
 }
Пример #5
0
        public void Update(Traider entity)
        {
            var modified = Traiders.Single(x => x.Id == entity.Id);

            modified.FirstName  = entity.FirstName;
            modified.Balance    = entity.Balance;
            modified.SecondName = entity.SecondName;
            modified.Status     = Status.ApplyStatus(modified);
        }
Пример #6
0
        public static void AddNewTraiders(BussinesService bussinesService)
        {
            IDataContex dataContext  = bussinesService.GetDataContex();
            Traider     existTraider = dataContext.Traiders.AsEnumerable().LastOrDefault();

            int newID = 0;

            if (existTraider != null)
            {
                newID = existTraider.ID;
            }

            List <Traider> traiders = new List <Traider>()
            {
                new Traider()
                {
                    ID        = ++newID,
                    FirstName = "Black",
                    Surname   = "Whiteson",
                    PhoneNum  = "34872642891"
                },
                new Traider()
                {
                    ID        = ++newID,
                    FirstName = "Red",
                    Surname   = "Greenson",
                    PhoneNum  = "56454"
                },
                new Traider()
                {
                    ID        = ++newID,
                    FirstName = "Homer(Doy!)",
                    Surname   = "Simpson",
                    PhoneNum  = "1241414"
                },
                new Traider()
                {
                    ID        = ++newID,
                    FirstName = "Marge",
                    Surname   = "Simpson",
                    PhoneNum  = "67868313"
                },
                new Traider()
                {
                    ID        = ++newID,
                    FirstName = "Bart(Ay caramba!)",
                    Surname   = "Simpson",
                    PhoneNum  = "231897193"
                }
            };

            foreach (Traider traider in traiders)
            {
                bussinesService.AddNewTraiderWithStarterPack(traider);
            }
        }
Пример #7
0
        public void RegisterStock(StockType type, Traider traider, int amount)
        {
            var entity = new Stock
            {
                StockType = type,
                Traider   = traider,
                Quantity  = amount
            };

            _dataContext.Add(entity);
            _dataContext.SaveChanges();
        }
Пример #8
0
 public void Acquire(Traider traider, Stock stock)
 {
     if (traider.Stocks.Select(x => x.StockType).Contains(stock.StockType))
     {
         var _stock = traider.Stocks.Single(x => x.StockType == stock.StockType);
         _stock.Quantity += stock.Quantity;
     }
     else
     {
         traider.Stocks.Add(stock);
     }
     traider.Balance -= stock.StockType.Price * stock.Quantity;
 }
Пример #9
0
        public void RegisterTraider(string fName, string sName, decimal cash, ICollection <Stock> stock = null)
        {
            var entity = new Traider
            {
                FirstName  = fName,
                SecondName = sName,
                Balance    = cash,
                Stocks     = stock
            };

            Logger.Log.Info("New Traider ---> " + entity.GetInfo());
            _dataContext.Add(entity);
            _dataContext.SaveChanges();
        }
Пример #10
0
        public void RegisterOperation(Traider buyer, Traider seller, Stock stock)
        {
            var operation = new Operation
            {
                Buyer       = buyer,
                Seller      = seller,
                StockAmount = stock.Quantity,
                StockType   = stock.StockType,
                Date        = DateTime.Now,
                Cash        = stock.StockType.Price * stock.Quantity
            };

            Logger.Log.Info("New Operation ---> " + operation.GetInfo() + "\n");
            _dataContext.Add(operation);
            _dataContext.SaveChanges();
        }
Пример #11
0
        public void TestSetup()
        {
            this.dataContex      = Substitute.For <IDataContex>();
            this.bussinesService = new BussinesService(this.dataContex);
            this.testTraider     = new Traider()
            {
                ID = 1, FirstName = "testName", Surname = "testSurname", PhoneNum = "testPhoneNum"
            };

            balancesList = new List <TraiderBalance>()
            {
                new TraiderBalance {
                    ID = 1, Balance = 0
                },
                new TraiderBalance {
                    ID = 2, Balance = 0
                },
                new TraiderBalance {
                    ID = 3, SimpleType = 20, PreferenceShare = 30, Balance = 2000
                },
                new TraiderBalance {
                    ID = 4, SimpleType = 20, PreferenceShare = 30, Balance = 2000
                }
            }.AsQueryable();

            dataContex.TraiderBalances.Returns(balancesList);

            traidersList = new List <Traider>()
            {
                new Traider {
                    ID = 1
                },
                new Traider {
                    ID = 2
                },
                new Traider {
                    ID = 3
                },
                new Traider {
                    ID = 4
                }
            }.AsQueryable();

            dataContex.Traiders.Returns(traidersList);
        }
Пример #12
0
        static void Main(string[] args)
        {
            Hero    hero    = new Hero(100f);
            Traider traider = new Traider();

            traider.CreateTraiderItems();

            while (true)
            {
                Console.WriteLine("Добро пожаловать в магазин!");
                Console.WriteLine("Для покупки доступно:");
                traider.ShowItemsInShop();
                Console.Write("Введите ID предмета которого хотите купить: ");
                int id = Convert.ToInt32(Console.ReadLine());
                traider.Traid(id, hero);
                Console.WriteLine("В вашем ивентаре:  ");
                hero.ShowItemsinHero();
            }
        }
Пример #13
0
        static void RunTradeDay(BussinesService bussinesService, ILoggerService loggerService)
        {
            var traiders = bussinesService.GetMostWantedTraider();

            List <Traider> traidersList = new List <Traider>();

            foreach (Traider traider in traiders)
            {
                traidersList.Add(traider);
            }

            Random  rnd         = new Random();
            int     sellerIndex = rnd.Next(0, traidersList.Count);
            Traider seller      = traidersList.ElementAt(sellerIndex);

            traidersList.RemoveAt(sellerIndex);

            int     buyerIndex = rnd.Next(0, traidersList.Count);
            Traider buyer      = traidersList.ElementAt(buyerIndex);

            var  arrayOfSharesTypes = Enum.GetValues(typeof(SharesType));
            var  randomSharesType   = (SharesType)arrayOfSharesTypes.GetValue(rnd.Next(arrayOfSharesTypes.Length));
            Deal deal = new Deal
            {
                ID_seller  = seller.ID,
                ID_buyer   = buyer.ID,
                Price      = rnd.Next(1, 100),
                SharesType = randomSharesType
            };

            bussinesService.RegisterNewDeal(deal);

            string sellerName = bussinesService.GetMostWantedTraiderNameById(deal.ID_seller).FirstName +
                                bussinesService.GetMostWantedTraiderNameById(deal.ID_seller).Surname;
            string buyerName = bussinesService.GetMostWantedTraiderNameById(deal.ID_buyer).FirstName +
                               bussinesService.GetMostWantedTraiderNameById(deal.ID_buyer).Surname;

            Console.WriteLine($"Deal done!: Seller: {sellerName} | Buyer: {buyerName} | ShareType: {deal.SharesType} | Price: {deal.Price}");
            loggerService.Info($"Seller: {sellerName} | Buyer: {buyerName} | ShareType: {deal.SharesType} | Price: {deal.Price}");
        }
Пример #14
0
 public void Remove(Traider entity) => this.Traiders.Remove(entity);
Пример #15
0
 public void Add(Traider entity) => this.Traiders.Add(entity);
Пример #16
0
 public void UpdateTraider(Traider traider)
 {
     _dataContext.Update(traider);
     _dataContext.SaveChanges();
 }