public ZipCode PullZipCode(Company company) { var zip = (from z in db.zip_codes where z.zip_code1 == company.ZipCode select new ZipCode { Id = z.id, Zip = z.zip_code1, City = z.city }).First(); if (zip == null) { ZipCode newZip = new ZipCode(); newZip.Zip = company.ZipCode; newZip.City = company.City; CreateZipCode(newZip); zip = PullZipCode(company); } return zip; }
public string UpdateCompany(int companyId, Company newCompany) { var company = (from c in db.companies where c.id == companyId select c).First(); company.name = newCompany.Name; ZipCodeApiController zipControl = new ZipCodeApiController(); var zip = zipControl.PullZipCode(newCompany); company.cvr = Int32.Parse(newCompany.CVR); company.phone = Int32.Parse(newCompany.Phone); company.email = newCompany.Email; company.ceo = newCompany.CEO; company.startup_date = newCompany.StartUpDate; company.is_activ = newCompany.Active; company.description = newCompany.ReasonNotActive; company.financial_report = newCompany.FinancialReport; company.advertising_protected = newCompany.AdverticingProtected; company.empoye_count = newCompany.EmployeeCount; company.address = newCompany.Address; company.zip_code_id = zip.Id; try { db.SubmitChanges(); return newCompany.Name + " opdateret."; } catch (Exception e) { return "Operationen mislykkedes. Kontakt IT-Support med følgende fejlbesked: " + e.Message; } }