public NhanVien Get_NhanVien_by_ID(int id) { QLCH_Model DB = new QLCH_Model(); var li_method = DB.NhanViens.Where(p => p.id == id).FirstOrDefault();; return(li_method); }
// các hàm tương tác với đối tượng NhanVien public List <NhanVien> Get_NhanViens() { QLCH_Model DB = new QLCH_Model(); var li_method = DB.NhanViens.Select(p => p); return(li_method.ToList()); }
public List <NhanVien> Search_by_Name(string name) { QLCH_Model DB = new QLCH_Model(); var li_method = DB.NhanViens.Where(p => p.Name.Contains(name)); return(li_method.ToList()); }
public int Get_Lastest_ID() { QLCH_Model DB = new QLCH_Model(); try { return(DB.NhanViens.OrderByDescending(p => p.id).First().id); } catch (InvalidOperationException) { return(0); } }
public void Delete_Staff(int id) { QLCH_Model db = new QLCH_Model(); id = db.NhanViens.Where(p => p.id == id).Select(p => p.id).FirstOrDefault(); foreach (NhanVien i in db.NhanViens) { if (i.id == id) { db.NhanViens.Remove(i); } } db.SaveChanges(); }
public void Add_Staff(string name, string gender, DateTime dob, string cmnd, string quequan, string diachi, string email, string phone) { QLCH_Model DB = new QLCH_Model(); NhanVien n = new NhanVien { Name = name, Gender = gender, DOB = dob, CMND = cmnd, QueQuan = quequan, DiaChi = diachi, Email = email, Phone = phone }; DB.NhanViens.Add(n); DB.SaveChanges(); }
public void Edit_Staff(int id, string name, string gender, DateTime dob, string cmnd, string quequan, string diachi, string email, string phone, string pass) { QLCH_Model db = new QLCH_Model(); NhanVien nv = db.NhanViens.Where(p => p.id == id).FirstOrDefault(); nv.Name = name; nv.Gender = gender; nv.DOB = dob; nv.CMND = cmnd; nv.QueQuan = quequan; nv.DiaChi = diachi; nv.Email = email; nv.Phone = phone; if (pass != "") { Account ac = db.Accounts.Where(p => p.idNhanVien == id).FirstOrDefault(); ac.PassWord = pass; } db.SaveChanges(); }