Exemplo n.º 1
0
        public ActionResult Create([Bind(Include = "id,name,content,created_at")] category category)
        {
            if (ModelState.IsValid)
            {
                db.categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
Exemplo n.º 2
0
        public ActionResult Create([Bind(Include = "id,name,email,password,phone,address,create_at")] user user)
        {
            if (ModelState.IsValid)
            {
                db.users.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user));
        }
Exemplo n.º 3
0
        public ActionResult Create([Bind(Include = "id,user_id,status,node,total,created_at")] order order)
        {
            if (ModelState.IsValid)
            {
                db.orders.Add(order);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.user_id = new SelectList(db.users, "id", "name", order.user_id);
            return(View(order));
        }
Exemplo n.º 4
0
        public ActionResult Create([Bind(Include = "id,name,category_id,image,unitPrice,created_at")] product product)
        {
            if (ModelState.IsValid)
            {
                db.products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.category_id = new SelectList(db.categories, "id", "name", product.category_id);
            ViewBag.id          = new SelectList(db.orderDetails, "product_id", "product_id", product.id);
            return(View(product));
        }
Exemplo n.º 5
0
        public ActionResult Create([Bind(Include = "product_id,order_id,price,quantity,created_at")] orderDetail orderDetail)
        {
            if (ModelState.IsValid)
            {
                db.orderDetails.Add(orderDetail);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.order_id   = new SelectList(db.orders, "id", "status", orderDetail.order_id);
            ViewBag.product_id = new SelectList(db.products, "id", "name", orderDetail.product_id);
            return(View(orderDetail));
        }
Exemplo n.º 6
0
 public ActionResult Register(user _user)
 {
     if (ModelState.IsValid)
     {
         var checkEmail = db.users.FirstOrDefault(m => m.email == _user.email); //m = model, kiểm tra xem email có trong database hay chưa
         if (checkEmail == null)                                                // check email
         {
             _user.password = GETMD5(_user.password);                           //mã hóa password người dùng nhập
             db.Configuration.ValidateOnSaveEnabled = false;
             db.users.Add(_user);
             db.SaveChanges();
             return(RedirectToAction("Login"));// đăng kí thành công trả về trang login
         }
         else
         {
             ViewBag.EmailError = " Email đã tồn tại ";
             return(RedirectToAction("Register"));
         }
     }
     return(View());
 }