Пример #1
0
        public void updateProduct(Product p)
        {
            using (DBcontextclasses cx = new DBcontextclasses())
            {
                var x = cx.Products.Find(p.Id);
                x.name  = p.name;
                x.type  = p.type;
                x.price = p.price;
                try
                {
                    // Your code...
                    // Could also be before try if you know the exception occurs in SaveChanges

                    cx.SaveChanges();
                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Debug.Print("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                    eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Debug.Print("- Property: \"{0}\", Error: \"{1}\"",
                                        ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                    throw;
                }
            }
        }
Пример #2
0
        public Product Update(int p)
        {
            using (DBcontextclasses cx = new DBcontextclasses()){
                var x = cx.Products.Find(p);

                return(x);
            }
        }
Пример #3
0
 public void adduser(user s)
 {
     using (DBcontextclasses cx = new DBcontextclasses())
     {
         s.type = "Customer";
         cx.users.Add(s);
         cx.SaveChanges();
     }
 }
Пример #4
0
        public bool checkValidEmail(String email)
        {
            using (DBcontextclasses cx = new DBcontextclasses())
            {
                bool flag = false;
                var  z    = cx.users.Where(x => x.email == email);
                if (z != null)
                {
                    flag = false;
                }
                else
                {
                    flag = true;
                }


                return(flag);
            }
        }
Пример #5
0
        public void DeleteProduct(int p)
        {
            using (DBcontextclasses cx = new DBcontextclasses()){
                var x = cx.Products.Find(p);

                cx.Products.Remove(x);

                try
                {
                    // Your code...
                    // Could also be before try if you know the exception occurs in SaveChanges

                    cx.SaveChanges();
                }
                catch (Exception e)
                {
                }
            }
        }
Пример #6
0
        public void AddnewProduct(Product p, HttpPostedFileBase file)
        {
            using (DBcontextclasses cx = new DBcontextclasses())
            {
                string   filename = null;
                string[] str      = file.FileName.Split('\\');

                filename = str[str.Length - 1];
                filename.Remove(0, 1);

                var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "Content\\images\\", (filename));

                p.path = "~/Content/images/" + filename;

                p.rating = 0;

                file.SaveAs(path);
                cx.Products.Add(p);

                try
                {
                    // Your code...
                    // Could also be before try if you know the exception occurs in SaveChanges

                    cx.SaveChanges();
                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Debug.Print("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                    eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Debug.Print("- Property: \"{0}\", Error: \"{1}\"",
                                        ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                    throw;
                }
            }
        }
Пример #7
0
 public user login(user u)
 {
     using (DBcontextclasses cx = new DBcontextclasses())
     {
         string em = u.email;
         cx.Database.Connection.Open();
         var usr = cx.users.First(x => x.email == u.email);//
         if (usr == null)
         {
             return(null);
         }
         else
         {
             if (usr.passwd != u.passwd)
             {
                 return(null);
             }
             return(usr);
         }
     }
 }