public async Task <IActionResult> Edit(string id, [Bind("NhMa,NhNamhoc")] Namhoc namhoc) { if (id != namhoc.NhMa) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(namhoc); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!NamhocExists(namhoc.NhMa)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(namhoc)); }
public IActionResult Delete(int id) { try { Namhoc nh = db.Namhoc.Find(id); if (nh != null) { if (db.Congviec.Where(x => x.Manamhoc == nh.Manamhoc).Count() > 0 || db.Khenthuong.Where(a => a.Manamhoc == nh.Manamhoc).Count() > 0 || db.Danhgia.Where(y => y.Manamhoc == nh.Manamhoc).Count() > 0) { return(BadRequest()); } else { db.Namhoc.Remove(nh); db.SaveChanges(); return(Ok()); } } else { return(BadRequest()); } } catch { throw; } }
public async Task <IActionResult> Create([Bind("NhMa,NhNamhoc")] Namhoc namhoc) { if (ModelState.IsValid) { _context.Add(namhoc); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(namhoc)); }
public int Edit(Namhoc nh) { try { db.Entry(nh).State = EntityState.Modified; db.SaveChanges(); return(1); } catch { throw; } }
public int Create([FromBody] Namhoc nh) { db.Namhoc.Add(nh); try { if (ModelState.IsValid) { db.SaveChanges(); } return(1); } catch (DbUpdateException) { throw; } }