public Boolean UpdateDishType(DishTypeDTO lst) { try { DISH_TYPE query = (from p in Context.DISH_TYPE where p.Id == lst.ID select p).SingleOrDefault(); query.NAME = lst.NAME; Context.SaveChanges(); return true; } catch (Exception ex) { throw ex; } }
//Thêm loại món ăn vào danh sách public Boolean InsertDishType(DishTypeDTO lst) { try { DISH_TYPE newDishType = new DISH_TYPE() { Id = Guid.NewGuid(), NAME = lst.NAME }; Context.DISH_TYPE.AddObject(newDishType); Context.SaveChanges(); return true; } catch (Exception ex) { throw ex; } }
private void tsbSave_Click(object sender, EventArgs e) { DishTypeDTO dt = new DishTypeDTO(); if (FormState == FormStateType.New) { dt.NAME = textBox1.Text.Trim(); rep.InsertDishType(dt); } else if (FormState == FormStateType.Edit) { dt.ID = PKEY; dt.NAME = textBox1.Text.Trim(); rep.UpdateDishType(dt); } FormState = FormStateType.Normal; panel1.Enabled = false; tsbSave.Enabled = false; tsbCancel.Enabled = false; tsbAddNew.Enabled = true; tsbEdit.Enabled = true; tsbDelete.Enabled = true; LoadDataThucDon(); }