示例#1
0
        private void GenerateStocks(int companyId, StocksDBContext context)
        {
            Stock[] stocks = new Stock[7];

            for (int i = 0; i < 7; i++)
            {
                var isEven = i % 2 == 1;
                stocks[i] = new Stock
                {
                    CompanyId = companyId,
                    Date      = DateTime.Now.AddDays(i * -1),
                    Cost      = new Random().Next(200 * i, 400 * i) + 470 * (i + 1)
                };
            }

            context.Stocks.AddRange(stocks);
            context.SaveChanges();
        }
示例#2
0
        public void InitCompanies(StocksDBContext context)
        {
            var companies = new Company[9];

            for (int i = 0; i < companies.Length; i++)
            {
                var comp = new Company
                {
                    Id           = i + 1,
                    Name         = companiesName[i],
                    Description  = "BlaBla",
                    IsOpenStocks = i % 2 == 0
                };

                context.Add(comp);
                context.SaveChanges();


                GenerateStocks(i + 1, context);
            }
        }
 public CompaniesEFRepository(StocksDBContext stockDbContext)
 {
     _stockDbContext = stockDbContext;
 }