public bool delete_nhanvien(int id) { try { using (sql_NCKHContext db = new sql_NCKHContext()) { Tblnhanvien d = db.Tblnhanviens.SingleOrDefault(x => x.Id == id); if (string.IsNullOrEmpty(d.ToString())) { return(true); } db.Tblnhanviens.Remove(d); db.SaveChanges(); return(true); } } catch (Exception) { return(false); } }
public bool edit_nhanvien(int id, [FromBody] Tblnhanvien nv) { try { using (sql_NCKHContext db = new sql_NCKHContext()) { Tblnhanvien d = db.Tblnhanviens.SingleOrDefault(x => x.Id == id); if (string.IsNullOrEmpty(d.ToString())) { return(false); } if (nv.Hinhanh != null) { var arrData = nv.Hinhanh.Split(';'); if (arrData.Length == 3) { var savePath = $@"assets/images/emloye/{arrData[0]}"; nv.Hinhanh = $"{arrData[0]}"; SaveFileFromBase64String(savePath, arrData[2]); } } else { nv.Hinhanh = d.Hinhanh; } d.Hoten = nv.Hoten; d.Bidanh = nv.Bidanh; d.Hinhanh = nv.Hinhanh; d.Gioitinh = nv.Gioitinh; d.Ngaysinh = nv.Ngaysinh; d.Noisinh = nv.Noisinh; d.Cmnd = nv.Cmnd; d.Ncapcmnd = nv.Ncapcmnd; d.Dantoc = nv.Dantoc; d.Tongiao = nv.Tongiao; d.Quoctich = nv.Quoctich; d.Tthonnhan = nv.Tthonnhan; d.Quequan = nv.Quequan; d.Dcttru = nv.Dcttru; d.Noiohnay = nv.Noiohnay; d.Dienthoai = nv.Dienthoai; d.Email = nv.Email; d.Idpban = nv.Idpban; d.Idchucvu = nv.Idchucvu; d.Tdhocvan = nv.Tdhocvan; d.Tdcaonhat = nv.Tdcaonhat; d.Ngdaotao = nv.Ngdaotao; d.Cngdaotao = nv.Cngdaotao; d.Noidaotao = nv.Noidaotao; d.Htdaotao = nv.Htdaotao; d.Trinhdonn = nv.Trinhdonn; d.Tinhoc = nv.Tinhoc; db.SaveChanges(); return(true); } } catch (Exception) { return(false); } }