public async Task <ActionResult <Bophan> > addBoPhan(Bophan bophan) { if (bophan.mabophan == null || bophan.mabophan == "") { return(BadRequest()); } var newBophan = await context.Bophan.FindAsync(bophan.mabophan); if (newBophan != null) { return(BadRequest()); } if (ModelState.IsValid) { try { context.Add(bophan); await context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { return(NotFound(new { status = "404", message = "error" })); } } return(CreatedAtAction("", new { status = true, Bophan = bophan })); }
private Models.Nhanvien GetData() { Models.Nhanvien nv = new Models.Nhanvien(); nv.Hoten = textBox2.Text; nv.Ngaysinh = DateTime.Parse(dateTimePicker1.Text); nv.Diachi = textBox6.Text; if (textBox7.Text != "") { nv.NhanvienID = int.Parse(textBox7.Text); } if (radioButton1.Checked == true) { nv.Gioitinh = true; } else { nv.Gioitinh = false; } nv.Hesoluong = float.Parse(textBox3.Text); Bophan bp = lstBophan.Find(x => x.Tenbophan == comboBox1.SelectedItem.ToString()); nv.BophanID = bp.BophanID; nv.Tenbophan = bp.Tenbophan; nv.Password = ""; return(nv); }
public static List <Bophan> compoboxBophan() { List <Bophan> bp = new List <Bophan>(); Bophan bp1; DataTable ds = DA.Ketnoi.ExcecuteQuery("select * from Bophan"); for (int i = 0; i < ds.Rows.Count; i++) { bp1 = new Bophan(); bp1.Mabophan = ds.Rows[i]["Mabophan"].ToString(); bp1.Tenbophan = ds.Rows[i]["Tenbophan"].ToString(); bp.Add(bp1); } return(bp); }
public async Task <IActionResult> editBophan(string id, Bophan bophan) { if (id != bophan.mabophan) { return(Ok(new { Status = false, Message = "Ma bo phan khong ton tai" })); } context.Entry(bophan).State = EntityState.Modified; try { await context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { return(BadRequest()); } return(CreatedAtAction("", new { status = true, Bophan = bophan })); }
public async Task <IActionResult> deleteBophan(Bophan bp) { var _bophan = await context.Bophan.FindAsync(bp.mabophan); if (_bophan == null) { return(Ok(new { Status = false, Message = "Bo phan khong ton tai" })); } try { context.Bophan.Remove(_bophan); await context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { return(Ok(new { Status = false, Message = "Bo phan khong ton tai" })); } return(CreatedAtAction("", new { Status = true, Message = "Xoa thanh cong" })); }