public bool DeleteProduct(int id) { try { using (QLBH_PHONE_Entities data = new QLBH_PHONE_Entities()) { var product = data.products.Single(p => p.id == id); var exportBill_Detail = data.export_bill_detail.Where(e => e.id_product == id).ToList(); foreach(var item in exportBill_Detail) { data.export_bill_detail.Remove(item); } var importBill_Detail = data.import_bill_detail.Where(i => i.id_product == id).ToList(); foreach (var item in importBill_Detail) { data.import_bill_detail.Remove(item); } data.products.Remove(product); data.SaveChanges(); return true; } } catch (Exception e) { Debug.WriteLine(e); return false; } }
public bool DeleteUser(int id) { try { using (QLBH_PHONE_Entities data = new QLBH_PHONE_Entities()) { var user = data.users.Single(u => u.id == id); var exportBill = data.export_bill.Where(e => e.id_user == id).ToList(); foreach (var item in exportBill) { var exportBill_Detail = data.export_bill_detail.Where(e => e.id_export_bill == item.id).ToList(); foreach (var item2 in exportBill_Detail) { data.export_bill_detail.Remove(item2); } data.export_bill.Remove(item); } data.users.Remove(user); data.SaveChanges(); return true; } } catch (Exception e) { Debug.WriteLine(e); return false; } }
public role GetRoleWithId(int id) { try { using (QLBH_PHONE_Entities data = new QLBH_PHONE_Entities()) { var my_save = data.roles.First(s => s.id == id); return my_save; } } catch (Exception e) { Debug.WriteLine(e); return null; } }
public List<role> GetAllRole() { try { using (QLBH_PHONE_Entities data = new QLBH_PHONE_Entities()) { var my_role = (data.roles.Select(p => p)).ToList(); return my_role; } } catch (Exception e) { Debug.WriteLine(e); return null; } }
public bool AddProduct(product product) { try { using (QLBH_PHONE_Entities data = new QLBH_PHONE_Entities()) { data.products.Add(product); data.SaveChanges(); return true; } } catch (Exception e) { Debug.WriteLine(e); return false; } }
public bool UpdateRole(role s) { try { using (QLBH_PHONE_Entities data = new QLBH_PHONE_Entities()) { data.Entry(s).State = EntityState.Modified; data.SaveChanges(); return true; } } catch (Exception e) { Debug.WriteLine(e); return false; } }
public List<product> GetAllProduct() { try { using (QLBH_PHONE_Entities data = new QLBH_PHONE_Entities()) { var my_product = (data.products.Select(p => p)).ToList(); return my_product; } } catch (Exception e) { Debug.WriteLine(e); return null; } }
public bool AddRole(role s) { try { using (QLBH_PHONE_Entities data = new QLBH_PHONE_Entities()) { data.roles.Add(s); data.SaveChanges(); return true; } } catch (Exception e) { Debug.WriteLine(e); return false; } }
public bool AddUser(user user) { try { using (QLBH_PHONE_Entities data = new QLBH_PHONE_Entities()) { data.users.Add(user); data.SaveChanges(); return true; } } catch (Exception e) { Debug.WriteLine(e); return false; } }
public bool CheckUser(string email, string pass) { try { using (QLBH_PHONE_Entities data = new QLBH_PHONE_Entities()) { var my_data = data.users.AsNoTracking() .Where(u => u.email == email && u.password == pass).FirstOrDefault(); if (my_data == null) return false; return true; } } catch (Exception e) { Debug.WriteLine(e); return false; } }
public List<user> GetAllUser() { try { using (QLBH_PHONE_Entities data = new QLBH_PHONE_Entities()) { var my_data = (data.users.Select(p => p)).ToList(); return my_data; } } catch (Exception e) { Debug.WriteLine(e); return null; } }
public List<product> GetProductByName(string n) { try { using (QLBH_PHONE_Entities data = new QLBH_PHONE_Entities()) { var my_product = data.products.AsNoTracking() .Where(p => p.name.ToUpper().Contains(n) || p.name.ToLower().Contains(n)).ToList(); return my_product; } } catch (Exception e) { Debug.WriteLine(e); return null; } }
public bool UpdateUser(user user) { try { using (QLBH_PHONE_Entities data = new QLBH_PHONE_Entities()) { //Code first //data.Entry(user).State = EntityState.Modified; //data.SaveChanges(); //return true; //////////// Code change var getItem = data.users.Single(p => p.id == user.id); getItem.id_role = user.id_role; getItem.address = user.address; getItem.email = user.email; getItem.name = user.name; getItem.password = user.password; getItem.phone_number = user.phone_number; data.SaveChanges(); return true; } } catch (Exception e) { Debug.WriteLine(e); return false; } }
public List<user> GetUserByName(string name) { try { using (QLBH_PHONE_Entities data = new QLBH_PHONE_Entities()) { var my_data = data.users.AsNoTracking() .Where(u => u.name.ToUpper().Contains(name) || u.name.ToLower().Contains(name)).ToList(); return my_data; } } catch (Exception e) { Debug.WriteLine(e); return null; } }
public user GetUserById(int id) { try { using (QLBH_PHONE_Entities data = new QLBH_PHONE_Entities()) { var my_data = data.users.First(s => s.id == id); return my_data; } } catch (Exception e) { Debug.WriteLine(e); return null; } }
public List<product> GetProductByIdManuAndNameProduct(int idManu, string namePro) { try { using (QLBH_PHONE_Entities data = new QLBH_PHONE_Entities()) { var my_product = data.products.AsNoTracking() .Where(p => p.id_manufacturer == idManu && p.name.Contains(namePro)).ToList(); return my_product; } } catch (Exception e) { Debug.WriteLine(e); return null; } }
public List<product> GetProductSave() { try { using (QLBH_PHONE_Entities data = new QLBH_PHONE_Entities()) { var my_product = data.products.AsNoTracking() .OrderByDescending(p => p.save.percent_save).Take(18).ToList(); return my_product; } } catch (Exception e) { Debug.WriteLine(e); return null; } }
public List<user> FindUserByEmail(string email) { try { using (QLBH_PHONE_Entities data = new QLBH_PHONE_Entities()) { var my_data = data.users.AsNoTracking() .Where(u => u.email.ToUpper().Contains(email) || u.email.ToLower().Contains(email)).ToList(); return my_data; } } catch (Exception e) { Debug.WriteLine(e); return null; } }
public List<product> GetAllProductOrByNameManu(string nManu) { try { using (QLBH_PHONE_Entities data = new QLBH_PHONE_Entities()) { var my_product = data.products.AsNoTracking() .Where(p => p.manufacturer.name == nManu || nManu == null).ToList(); return my_product; } } catch (Exception e) { Debug.WriteLine(e); return null; } }
public bool UpdateProduct(product product) { try { using (QLBH_PHONE_Entities data = new QLBH_PHONE_Entities()) { //data.products.Attach(product); //data.Entry(product).State = EntityState.Modified; //getItem.id = product.id; var getItem = data.products.Single(p => p.id == product.id);//get the specific product getItem.id_manufacturer = product.id_manufacturer; getItem.id_save = product.id_save; getItem.name = product.name; getItem.sale_price = product.sale_price; getItem.number = product.number; getItem.image = product.image; getItem.product_info = product.product_info; data.SaveChanges(); return true; } } catch (Exception e) { Debug.WriteLine(e); return false; } }
public user GetUserByEmail(string email) { try { using (QLBH_PHONE_Entities data = new QLBH_PHONE_Entities()) { var my_data = data.users.AsNoTracking() .Where(u => u.email == email).FirstOrDefault(); return my_data; } } catch (Exception e) { Debug.WriteLine(e); return null; } }
public product GetProductById(int id) { try { using (QLBH_PHONE_Entities data = new QLBH_PHONE_Entities()) { var my_product = data.products.First(s => s.id == id); return my_product; } } catch (Exception e) { Debug.WriteLine(e); return null; } }