Example #1
0
        public ActionResult Create([Bind(Include = "StudentNo,Name,Surname,Email,telNo,mobileNo,isActive")] Student student)
        {
            if (ModelState.IsValid)
            {
                db.Students.Add(student);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(student));
        }
Example #2
0
        public ActionResult RegisterUser(user user)
        {
            if (ModelState.IsValid)
            {
                String hash = md5(user.pass);
                db.User.Add(new user {
                    name = user.name, pass = hash
                });
                db.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }

            return(View(user));
        }
 public bool Insert(Product product)
 {
     IsValid = false;
     using (var db = new DbAccessContext())
     {
         try
         {
             // Insert the new entity
             db.Products.Add(product);
             db.SaveChanges();
         }
         catch (DbEntityValidationException ex)
         {
             ValidationErrorsToMessages(ex);
         }
         catch (Exception ex)
         {
             LastException = ex;
         }
     }
     return(IsValid);
 }
        public bool Delete(int id)
        {
            IsValid = false;
            using (var db = new DbAccessContext())
            {
                try
                {
                    // Get the product
                    Product product = db.Products.Find(id);
                    // Delete the product
                    db.Products.Remove(product);
                    db.SaveChanges();

                    IsValid = true;
                }
                catch (Exception ex)
                {
                    LastException = ex;
                }
            }

            return(IsValid);
        }
        public bool Update(Product product)
        {
            IsValid = false;
            using (var db = new DbAccessContext())
            {
                try
                {
                    // Update the product
                    db.Entry(product).State = EntityState.Modified;
                    db.SaveChanges();
                    IsValid = true;
                }
                catch (DbEntityValidationException ex)
                {
                    ValidationErrorsToMessages(ex);
                }
                catch (Exception ex)
                {
                    LastException = ex;
                }
            }

            return(IsValid);
        }