public IActionResult Delete(string id) { try { Chucdanh cn = db.Chucdanh.Find(id); if (cn != null) { if (db.Vienchuc.Where(x => x.Machucdanh == cn.Machucdanh).Count() > 0) { return(BadRequest()); } db.Chucdanh.Remove(cn); db.SaveChanges(); return(Ok()); } else { return(BadRequest("Không tìm thấy id này!")); } } catch { throw; } }
public int Edit(Chucdanh cd) { try { db.Entry(cd).State = EntityState.Modified; db.SaveChanges(); return(1); } catch { throw; } }
public int Create([FromBody] Chucdanh cd) { db.Chucdanh.Add(cd); try { if (ModelState.IsValid) { db.SaveChanges(); } return(1); } catch (DbUpdateException) { throw; } }