TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Paulo Luis Zampieri
NA
9
441
ASP NET CORE MVC - Can't update 2 tables in only one event.
Feb 16 2021 3:54 PM
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();
//Until here, the code above works fine and no errors.
// this is the code that it insn't working. I have a second table 'CostCenter' which Key is CCid
// this is a simple update method I'm trying to implement.
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);
}
Reply
Answers (
3
)
Sharepoint Issue while converting from to CSOM
I created a mvc website for a project and i need the students in my cl