Exemple #1
0
 /// <summary>
 /// 保存一个修改的关联单位(客户/供货商)
 /// </summary>
 /// <param name="company">修改的关联单位</param>
 /// <param name="Modifier">修改人</param>
 public void SaveCompany(Company company, string Modifier)
 {
     using (IDbConnection conn = DAOFactory.Instance.OpenConnection())
     {
         ICompanyDAO dao = DAOFactory.Instance.CreateCompanyDAO();
         dao.UpdateCompany(company, conn);
     }
 }
        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."));
            }
        }