public Tbldonvi get_donvi_id(int id) { Tbldonvi dv = new Tbldonvi(); using (sql_NCKHContext db = new sql_NCKHContext()) { dv = db.Tbldonvis.SingleOrDefault(x => x.Id == id); } return(dv); }
public bool create_donvi([FromBody] Tbldonvi dv) { try { using (sql_NCKHContext db = new sql_NCKHContext()) { db.Tbldonvis.Add(dv); db.SaveChanges(); return(true); } } catch (Exception) { return(false); } }
public bool delete_donvi(int id) { try { using (sql_NCKHContext db = new sql_NCKHContext()) { Tbldonvi d = db.Tbldonvis.SingleOrDefault(x => x.Id == id); if (string.IsNullOrEmpty(d.ToString())) { return(true); } db.Tbldonvis.Remove(d); db.SaveChanges(); return(true); } } catch (Exception) { return(false); } }
public bool edit_donvi(int id, [FromBody] Tbldonvi dv) { try { using (sql_NCKHContext db = new sql_NCKHContext()) { Tbldonvi d = db.Tbldonvis.SingleOrDefault(x => x.Id == id); if (string.IsNullOrEmpty(d.ToString())) { return(false); } d.Tendv = dv.Tendv; d.Tyle = dv.Tyle; d.Ghichu = dv.Ghichu; db.SaveChanges(); return(true); } } catch (Exception) { return(false); } }