public async Task <IActionResult> Edit(int DangerId, int YearId, [Bind("DangerId,YearId,Amount")] DangerYear dangerYear) { if (DangerId != dangerYear.DangerId) { return(NotFound()); } if (YearId != dangerYear.YearId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(dangerYear); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DangerYearExists(dangerYear.DangerId, dangerYear.YearId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["DangerId"] = new SelectList(_context.Dangers, "Id", "Descr", dangerYear.DangerId); ViewData["YearId"] = new SelectList(_context.Years, "Id", "Value", dangerYear.YearId); return(View(dangerYear)); }
public async Task <IActionResult> Create([Bind("DangerId,YearId,Amount")] DangerYear dangerYear) { if (ModelState.IsValid) { if (DangerYearExists(dangerYear.DangerId, dangerYear.YearId)) { var dangerYearOld = await _context.DangerYears.SingleOrDefaultAsync(m => m.DangerId == dangerYear.DangerId && m.YearId == dangerYear.YearId); dangerYearOld.Amount = dangerYear.Amount; _context.Update(dangerYearOld); } else { _context.Add(dangerYear); } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["DangerId"] = new SelectList(_context.Dangers, "Id", "Descr", dangerYear.DangerId); ViewData["YearId"] = new SelectList(_context.Years, "Id", "Value", dangerYear.YearId); return(View(dangerYear)); }