Ejemplo n.º 1
0
        private IEnumerable <StockPrice> GetStockPriceList()
        {
            var cse = new CompanyStockExchange
            {
                CompanyId         = 1,
                StockExchangeCode = "BSE"
            };

            return(new List <StockPrice>
            {
                new StockPrice
                {
                    Id = 1,
                    CurrentPrice = 100,
                    Date = new DateTime().ToShortDateString(),
                    Time = new DateTime().ToShortTimeString(),
                    CompanyStockExchange = cse
                },
                new StockPrice
                {
                    Id = 2,
                    CurrentPrice = 101,
                    Date = new DateTime().ToShortDateString(),
                    Time = new DateTime().AddMinutes(1).ToShortTimeString(),
                    CompanyStockExchange = cse
                }
            });
        }
Ejemplo n.º 2
0
        public async Task <bool> AddCompany(AddCompanyModel model)
        {
            var sectorInfo = _db.Sectors.Where(s => s.SectorID == model.SectorID).FirstOrDefault();

            Company company = new Company
            {
                CompanyName      = model.CompanyName,
                TurnOver         = model.TurnOver,
                CEO              = model.CEO,
                BoardOfDirectors = model.BoardOfDirectors,
                SectorID         = model.SectorID,
                Sector           = sectorInfo,
                WriteUp          = model.WriteUp,
                stockCodes       = null,
                Active           = model.Active
            };

            await using var transaction = await _db.Database.BeginTransactionAsync();

            try
            {
                _db.Companies.Add(company);
                List <CompanyStockExchange> iecse = new List <CompanyStockExchange>();
                foreach (string exchangeShortName in model.Exchanges)
                {
                    var ex = _db.StockExchanges.Where(e => e.shortName == exchangeShortName).FirstOrDefault();
                    //var cid = _db.Companies.Where(c => c.CompanyName == model.CompanyName).FirstOrDefault().CompanyID;
                    CompanyStockExchange cse = new CompanyStockExchange
                    {
                        Company         = company,
                        StockExchangeID = ex.StockExchangeID,
                        StockExchange   = ex
                    };
                    iecse.Add(cse);
                }
                _db.companyStockExchanges.AddRange(iecse);
                _db.SaveChanges();
                await transaction.CommitAsync();

                return(true);
            }
            catch (Exception err)
            {
                Console.WriteLine(err);
                await transaction.RollbackAsync();

                return(false);
            }
        }