Beispiel #1
0
        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);
            }
        }
Beispiel #2
0
 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);
     }
 }
Beispiel #3
0
 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);
     }
 }
Beispiel #4
0
 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);
     }
 }
Beispiel #5
0
 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);
     }
 }
Beispiel #6
0
 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);
     }
 }
Beispiel #7
0
 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);
     }
 }
Beispiel #8
0
 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);
     }
 }
Beispiel #9
0
 public List <product> GetProductByNameManu(string nameManu)
 {
     try
     {
         using (QLBH_PHONE_Entities data = new QLBH_PHONE_Entities())
         {
             var my_product = data.products.AsNoTracking().Where(p => p.manufacturer.name == nameManu).ToList();
             return(my_product);
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine(e);
         return(null);
     }
 }
Beispiel #10
0
 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);
     }
 }
Beispiel #11
0
 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);
     }
 }
Beispiel #12
0
 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);
     }
 }
Beispiel #13
0
 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);
     }
 }
Beispiel #14
0
 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);
     }
 }
Beispiel #15
0
 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);
     }
 }
Beispiel #16
0
 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);
     }
 }
Beispiel #17
0
 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);
     }
 }
Beispiel #18
0
        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);
            }
        }
Beispiel #19
0
 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);
     }
 }
Beispiel #20
0
 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);
     }
 }
Beispiel #21
0
 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);
     }
 }
Beispiel #22
0
 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);
     }
 }