internal Product GetProductByID(int id)
 {
     using (db = new ShoppingExampleDbEntities2())
     {
         return(db.Product.Find(id));
     }
 }
 public List <Product> GetProudcts()
 {
     using (db = new ShoppingExampleDbEntities2())
     {
         return(db.Product.Include(m => m.Category).ToList());
     }
 }
Exemple #3
0
 public Category GetProductCategoryById(int?id)
 {
     using (db = new ShoppingExampleDbEntities2())
     {
         return(db.Category.FirstOrDefault(m => m.CategoryID == id));
     }
 }
Exemple #4
0
 public List <Category> GetProudctCategories()
 {
     using (db = new ShoppingExampleDbEntities2())
     {
         return(db.Category.ToList());
     }
 }
 public List <Product> GetProductsByCategoryId(int?id)
 {
     using (db = new ShoppingExampleDbEntities2())
     {
         var products = db.Product.Include(m => m.Category).Where(m => m.ProductCategoryID == id).ToList();
         return(products);
     }
 }
 public User GetUserByEmail(string inputEmail)
 {
     using (db = new ShoppingExampleDbEntities2())
     {
         var user = db.User.FirstOrDefault(m => m.UserEmail == inputEmail);
         return(user);
     }
 }
 public bool IsUserLogin(string inputEmail, string inputPassword)
 {
     using (db = new ShoppingExampleDbEntities2())
     {
         if (db.User.Any(u => u.UserEmail == inputEmail))
         {
             if (db.User.FirstOrDefault(u => u.UserEmail == inputEmail).UserPassword == inputPassword)
             {
                 return(true);
             }
         }
         return(false);
     }
 }
 public bool CreateProduct(Product product)
 {
     using (db = new ShoppingExampleDbEntities2())
     {
         db.Product.Add(product);
         var save = db.SaveChanges();
         if (save > 0)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
 //public List<Product> GetProductByID(int? id)
 //{
 //    using (db=new ShoppingExampleDbEntities())
 //    {
 //        var product = db.Product.Include(m=>m.Category).Where(m => m.ProductID == id).ToList();
 //        return product;
 //    }
 //}
 public bool DeleteProductByID(int?id)
 {
     using (db = new ShoppingExampleDbEntities2())
     {
         var product = db.Product.FirstOrDefault(m => m.ProductID == id);
         db.Product.Remove(product);
         var save = db.SaveChanges();
         if (save > 0)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
 public bool Register(User user)
 {
     using (db = new ShoppingExampleDbEntities2())
     {
         db.User.Add(new User()
         {
             UserName     = user.UserName,
             UserLastName = user.UserLastName,
             UserEmail    = user.UserEmail,
             UserPassword = user.UserPassword
         });
         var save = db.SaveChanges();
         if (save > 0)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }