public int Add(nhaxuatban entity) { try { db.nhaxuatbans.InsertOnSubmit(entity); db.SubmitChanges(); return(entity.manxb); } catch (Exception) { return(0); throw; } }
private void Luu_NXB_Click(object sender, EventArgs e) { if (Them_bool == true && Sua_bool == false) { var nxb = new nhaxuatban(); nxb.tennxb = tennxbtxt.Text; nxb.diachi = diachinxbtxt.Text; nxb.sdt = sdtnxbtxt.Text; var entity = new NhaXuatBanController(); if (entity.Add(nxb) > 0) { HienThi_NXB(); } else { MessageBox.Show("Thêm không thành công"); } } if (Them_bool == false && Sua_bool == true) { var nxb = new nhaxuatban(); nxb.tennxb = tennxbtxt.Text; nxb.diachi = diachinxbtxt.Text; nxb.sdt = sdtnxbtxt.Text; var entity = new NhaXuatBanController(); if (entity.Edit(nxb)) { HienThi_NXB(); } else { MessageBox.Show("Sửa không thành công"); } } btn_enable(false); }
public bool Edit(nhaxuatban nxb) { var obj = db.nhaxuatbans.First(m => m.manxb == nxb.manxb); if (obj != null) { try { obj.tennxb = nxb.tennxb; obj.diachi = nxb.diachi; obj.sdt = nxb.sdt; db.SubmitChanges(); return(true); } catch (Exception) { return(false); throw; } } return(true); }