public bool InsertNewCustomer(string name, string adress, string phoneNumber) { try { BTAPIEntities dbCustomer = new BTAPIEntities(); KhachHang customer = new KhachHang(); customer.TenKhach = name; customer.DiaChi = adress; customer.DienThoai = phoneNumber; dbCustomer.KhachHangs.Add(customer); dbCustomer.SaveChanges(); return(true); } catch { return(false); } }
public bool DeleteCustomer(int id) { try { BTAPIEntities dbCustomer = new BTAPIEntities(); //Lấy mã khách đã có KhachHang customer = dbCustomer.KhachHangs.FirstOrDefault(x => x.ID == id); if (customer == null) { return(false); } dbCustomer.KhachHangs.Remove(customer); dbCustomer.SaveChanges(); return(true); } catch { return(false); } }
public bool UpdateCustomer(int id, string name, string adress, string phoneNumber) { try { BTAPIEntities dbCustomer = new BTAPIEntities(); //Lấy mã khách đã có KhachHang customer = dbCustomer.KhachHangs.FirstOrDefault(x => x.ID == id); if (customer == null) { return(false); } customer.TenKhach = name; customer.DiaChi = adress; customer.DienThoai = phoneNumber; dbCustomer.SaveChanges();//Xác nhận chỉnh sửa return(true); } catch { return(false); } }