//Cập nhật 1 đầu bếp public Boolean UpdateChef(ChefDTO lst) { try { CHEF_INFO query = (from p in Context.CHEF_INFO where p.Id == lst.ID select p).SingleOrDefault(); query.NAME = lst.NAME; query.ADDRESS=lst.ADDRESS; query.BIRTHDAY=lst.BIRTHDAY; query.PHONE = lst.PHONE; Context.SaveChanges(); return true; } catch (Exception ex) { throw ex; } }
//Thêm 1 đầu bếp vào danh sách public Boolean InsertChef(ChefDTO lst) { try { CHEF_INFO newDishType = new CHEF_INFO() { Id = Guid.NewGuid(), NAME = lst.NAME, ADDRESS = lst.ADDRESS, BIRTHDAY = lst.BIRTHDAY, PHONE = lst.PHONE }; Context.CHEF_INFO.AddObject(newDishType); Context.SaveChanges(); return true; } catch (Exception ex) { throw ex; } }
private void tsbSave_Click(object sender, EventArgs e) { BindDataDauBep(); ChefDTO dt = new ChefDTO(); if (FormState == FormBase.FormStateType.New) { dt.NAME = textBox3.Text.Trim(); dt.BIRTHDAY = dateTimePicker1.Value; dt.ADDRESS = textBox1.Text.Trim(); dt.PHONE = textBox2.Text.Trim(); rep.InsertChef(dt); } else if (FormState == FormBase.FormStateType.Edit) { dt.ID = PKEY; dt.NAME = textBox1.Text.Trim(); dt.BIRTHDAY = dateTimePicker1.Value; dt.ADDRESS = textBox1.Text.Trim(); dt.PHONE = textBox2.Text.Trim(); rep.UpdateChef(dt); } FormState = FormStateType.Normal; panel1.Enabled = false; tsbSave.Enabled = false; tsbCancel.Enabled = false; tbsAddNew.Enabled = true; tsbEdit.Enabled = true; tsbDelete.Enabled = true; LoadDataDauBep(); }