public async Task<IActionResult> Edit(int id, [Bind("Matinnhanh,Noidung,Machuyenmuc")] Tinnhanh tinnhanh) { if (id != tinnhanh.Matinnhanh) { return NotFound(); } if (ModelState.IsValid) { try { _context.Update(tinnhanh); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TinnhanhExists(tinnhanh.Matinnhanh)) { return NotFound(); } else { throw; } } return RedirectToAction("Index"); } ViewData["Machuyenmuc"] = new SelectList(_context.Chuyenmuc, "Machuyenmuc", "Tenchuyenmuc", tinnhanh.Machuyenmuc); return View(tinnhanh); }
public async Task<IActionResult> Create([Bind("Matinnhanh,Noidung,Machuyenmuc")] Tinnhanh tinnhanh,Chuyenmuc chuyenmuc) { if (ModelState.IsValid) { var sbv =await _context.Chuyenmuc.SingleOrDefaultAsync(c => c.Machuyenmuc == tinnhanh.Machuyenmuc); //sbv.Sobaiviet = sbv.Sobaiviet + 1; _context.Add(tinnhanh); await _context.SaveChangesAsync(); return RedirectToAction("Index"); } ViewData["Machuyenmuc"] = new SelectList(_context.Chuyenmuc, "Machuyenmuc", "Tenchuyenmuc", tinnhanh.Machuyenmuc); return View(tinnhanh); }