public bool DeleteProduct(int id) { try { using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY()) { 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 DeleteExportBillByIdUser(int idUser) { try { using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY()) { var listExport = data.export_bill.Where(e => e.id_user == idUser).ToList(); foreach (var item in listExport) { 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); } return true; } } catch (Exception e) { Debug.WriteLine(e); return false; } }
public bool DeleteUser(int id) { try { using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY()) { 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_ENTITY data = new QLBH_PHONE_ENTITY()) { 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_ENTITY data = new QLBH_PHONE_ENTITY()) { var my_role = (data.roles.Select(p => p)).ToList(); return my_role; } } catch (Exception e) { Debug.WriteLine(e); return null; } }
public import_bill GetImportBillById(int id) { try { using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY()) { var my_data = data.import_bill.First(s => s.id == id); return my_data; } } catch (Exception e) { Debug.WriteLine(e); return null; } }
public manufacturer GetManufacturerById(int id) { try { using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY()) { var my_save = data.manufacturers.First(s => s.id == id); return my_save; } } catch (Exception e) { Debug.WriteLine(e); return null; } }
public List<Models.save_date> GetAllSaveDate() { try { using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY()) { var my_save = (data.save_date.Select(p => p)).ToList(); return my_save; } } catch (Exception e) { Debug.WriteLine(e); return null; } }
public Models.save_date GetSaveDateWithId(int id) { try { using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY()) { var my_save = data.save_date.First(s => s.id == id); return my_save; } } catch (Exception e) { Debug.WriteLine(e); return null; } }
public List<import_bill_detail> GetAllImportBill_Detail() { try { using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY()) { var my_data = (data.import_bill_detail.Select(p => p)).ToList(); return my_data; } } catch (Exception e) { Debug.WriteLine(e); return null; } }
public List<manufacturer> GetAllManufacturer() { try { using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY()) { var my_save = (data.manufacturers.Select(p => p)).ToList(); return my_save; } } catch (Exception e) { Debug.WriteLine(e); return null; } }
public bool UpdateRole(role s) { try { using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY()) { data.Entry(s).State = EntityState.Modified; data.SaveChanges(); return true; } } catch (Exception e) { Debug.WriteLine(e); return false; } }
public bool AddExportBill(export_bill eb) { try { using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY()) { data.export_bill.Add(eb); data.SaveChanges(); return true; } } catch (Exception e) { Debug.WriteLine(e); return false; } }
public bool AddSaveDate(Models.save_date s) { try { using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY()) { data.save_date.Add(s); data.SaveChanges(); return true; } } catch (Exception e) { Debug.WriteLine(e); return false; } }
public List<product> GetAllProduct() { try { using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY()) { var my_product = (data.products.Select(p => p)).ToList(); return my_product; } } catch (Exception e) { Debug.WriteLine(e); return null; } }
public bool AddManufacturer(manufacturer s) { try { using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY()) { data.manufacturers.Add(s); data.SaveChanges(); return true; } } catch (Exception e) { Debug.WriteLine(e); return false; } }
public bool AddProduct(product product) { try { using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY()) { data.products.Add(product); data.SaveChanges(); return true; } } catch (Exception e) { Debug.WriteLine(e); return false; } }
public bool AddImportBill_Detail(import_bill_detail i) { try { using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY()) { data.import_bill_detail.Add(i); data.SaveChanges(); return true; } } catch (Exception e) { Debug.WriteLine(e); return false; } }
public bool AddUser(user user) { try { using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY()) { data.users.Add(user); data.SaveChanges(); return true; } } catch (Exception e) { Debug.WriteLine(e); return false; } }
public manufacturer GetManufacturerByName(string name) { try { using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY()) { var my_data = data.manufacturers.AsNoTracking() .Where(m => m.name == name).FirstOrDefault(); return my_data; } } catch (Exception e) { Debug.WriteLine(e); return null; } }
public bool DeleteSaveDate(int id) { try { using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY()) { var savedate = data.save_date.Single(s => s.id == id); data.save_date.Remove(savedate); data.SaveChanges(); return true; } } catch (Exception e) { Debug.WriteLine(e); return false; } }
public bool CheckUser(string email, string pass) { try { using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY()) { 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 bool UpdateSave(save s) { try { using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY()) { //Test var getItem = data.saves.Single(p => p.id == s.id); //data.Entry(s).State = EntityState.Modified; getItem = s; data.SaveChanges(); return true; } } catch (Exception e) { Debug.WriteLine(e); return false; } }
public bool DeleteImportBill_DetailByIdProduct(int id_product) { try { using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY()) { var li = data.import_bill_detail.Where(i => i.id_product == id_product).ToList(); if (li == null) return true; foreach (var item in li) { data.import_bill_detail.Remove(item); } return true; } } catch (Exception e) { Debug.WriteLine(e); return false; } }
public bool DeleteImportBill(int id) { try { using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY()) { var my_data = data.import_bill.Single(i => i.id == id); var importDetail = data.import_bill_detail.Where(i => i.id_import_bill == id).ToList(); foreach (var item in importDetail) { data.import_bill_detail.Remove(item); } data.import_bill.Remove(my_data); data.SaveChanges(); return true; } } catch (Exception e) { Debug.WriteLine(e); return false; } }
public import_bill_detail GetImportBill_DetailByBothId(int productId, int importBillId) { try { using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY()) { var my_data = data.import_bill_detail.First(s => s.id_product == productId && s.id_import_bill == importBillId); return my_data; } } catch (Exception e) { Debug.WriteLine(e); return null; } }
public bool UpdateImportBill_Detail(import_bill_detail i) { try { using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY()) { data.Entry(i).State = EntityState.Modified; data.SaveChanges(); return true; } } catch (Exception e) { Debug.WriteLine(e); return false; } }
public List<import_bill_detail> GetImportBill_DetailByIdProduct(int productId) { try { using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY()) { var my_data = data.import_bill_detail.AsNoTracking() .Where(s => s.id_product == productId).ToList(); return my_data; } } catch (Exception e) { Debug.WriteLine(e); return null; } }
public bool UpdateUser(user user) { try { using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY()) { //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_ENTITY data = new QLBH_PHONE_ENTITY()) { 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; } }