Hi,
I'm trying to update 2 tables at the same time using only one event. Below is code, however, I can't make it work in second update described below.
The error is at the bottom of this page
Does anyone has any idea what's going on?
thanks in advance.
This is the code:
- [HttpPost]
- [ValidateAntiForgeryToken]
- public async Task<IActionResult> Edit(int id, [Bind("Companyid,Name,Code,Currency")] Company company)
- {
- if (id != company.Companyid)
- {
- return NotFound();
- }
- if (ModelState.IsValid)
- {
- try
- {
- TempData["Confirmation"] = company.Name + " was updated.";
- _context.Update(company);
- await _context.SaveChangesAsync();
-
-
-
-
-
- int ccid = 1;
- CostCenter costCenter = new CostCenter();
- costCenter = _context.Costcenter.Find(ccid);
- costCenter.Department = "Testing....";
- _context.SaveChanges();
- }
- catch (DbUpdateConcurrencyException)
- {
- if (!CompanyExists(company.Companyid))
- {
- return NotFound();
- }
- else
- {
- throw;
- }
- }
- return RedirectToAction(nameof(Index));
- }
- return View(company);
- }
