public async Task <IActionResult> Update(CompanyModel companyUpdate)
        {
            if (companyUpdate == null)
            {
                return(BadRequest("Company not recieved"));
            }

            var existingCompany = await companyDAO.GetCompanyById(companyUpdate.Id);

            if (existingCompany.ISIN != companyUpdate.ISIN && !this.ValidateISIN(companyUpdate.ISIN))
            {
                return(BadRequest("ISIN value must begin with two letters and be unique"));
            }


            //Update Company
            var updatedCompany = await companyDAO.UpdateCompany(new Company.DataAccess.Models.Company
            {
                Id      = companyUpdate.Id,
                Name    = companyUpdate.Name,
                ISIN    = companyUpdate.ISIN,
                Website = companyUpdate.Website
            });


            //Create / check exchanges exist already
            var exchangeIds = new List <int>();

            foreach (string s in companyUpdate.CompanyExchange)
            {
                var newExchange = await exchangeDAO.CreateExchange(new Company.DataAccess.Models.Exchange
                {
                    Name = s
                });

                exchangeIds.Add(newExchange.Id);
            }

            //Update join table
            var updatedExchange = await companyExchangeDAO.UpdateCompanyExchanges(companyUpdate.Id, exchangeIds);

            //Create/Update Tickers
            var updatedTicker = await tickerDAO.UpdateCompanyTickers(companyUpdate.Id, companyUpdate.Ticker);

            if (updatedCompany != null)
            {
                return(Ok());
            }
            else
            {
                return(BadRequest("Error occured please try again."));
            }
        }
Beispiel #2
0
        public async Task CreateExchange(string exchangeName)
        {
            var ret = await dao.CreateExchange(new Exchange { Name = exchangeName });

            Assert.NotNull(ret);
            Assert.AreEqual(exchangeName, ret.Name);
            Assert.Pass();
        }