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