public ActionResult Create(HOADON model)
        {
            ValidateBill(model);
            if (ModelState.IsValid)
            {
                using (var scope = new TransactionScope())
                {
                    model.NGAY = DateTime.Now;
                    db.HOADONs.Add(model);
                    db.SaveChanges();

                    foreach (var item in ShoppingCart)
                    {
                        db.CHITIETHOADONs.Add(new CHITIETHOADON
                        {
                            MAHOADON = model.MAHOADON,
                            MASACH   = item.SACH.MASACH,
                            GIASACH  = item.SACH.GIASACH,
                            SOLUONG  = item.SOLUONG
                        });
                    }
                    db.SaveChanges();

                    scope.Complete();
                    Session["ShoppingCart"] = null;
                    return(RedirectToAction("Index2", "SACHes"));
                }
            }
            GetShoppingCart();
            ViewBag.Cart = ShoppingCart;
            return(View(model));
        }
Exemple #2
0
        public ActionResult Create(SACH model, HttpPostedFileBase picture)
        {
            ValidateProduct(model);
            if (ModelState.IsValid)
            {
                if (picture != null)
                {
                    using (var scope = new TransactionScope())
                    {
                        db.SACHes.Add(model);
                        db.SaveChanges();

                        // store picture
                        var path = Server.MapPath(PICTURE_PATH);
                        picture.SaveAs(path + model.MASACH);

                        scope.Complete();
                        return(RedirectToAction("Index"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Picture not found!");
                }
            }

            return(View(model));
        }
        public ActionResult Create(string roleId, string userId)
        {
            var role = db.AspNetRoles.Find(roleId);
            var user = db.AspNetUsers.Find(userId);

            role.AspNetUsers.Add(user);
            db.Entry(role).State = EntityState.Modified;
            db.SaveChanges();

            return(RedirectToAction("Index", "AspNetRoles"));
        }
Exemple #4
0
        public ActionResult Create(AspNetRole aspNetRole)
        {
            if (ModelState.IsValid)
            {
                aspNetRole.Id = Guid.NewGuid().ToString();
                db.AspNetRoles.Add(aspNetRole);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(aspNetRole));
        }