Esempio n. 1
0
        public ActionResult Create(Bill model, string email, string phone)
        {
            ValidateBill(model, email, phone);
            CheckLoggedIn(User);
            if (ModelState.IsValid)
            {
                using (var scope = new TransactionScope())
                {
                    model.order_day = DateTime.Now;
                    model.user_id   = User.Identity.GetUserId();
                    db.Bills.Add(model);
                    db.SaveChanges();
                    foreach (var item in ShoppingCart)
                    {
                        db.Bill_Info.Add(new Bill_Info
                        {
                            bill_id    = model.id,
                            product_id = item.Product.id,
                            price      = item.Product.price,
                            number     = item.number
                        });
                    }
                    db.SaveChanges();

                    scope.Complete();
                    Session["ShoppingCart"] = null;
                    return(RedirectToAction("List", "Products"));
                }
            }
            GetShoppingCart();
            TempData["MessageError"] = "You haven't login yet or bill invalid . Please check again .";
            ViewBag.Cart             = ShoppingCart;
            //ViewBag.MessageError = "You haven't login yet or bill invalid . Please check again .";
            return(RedirectToAction("Index", "ShoppingCart"));
        }
Esempio n. 2
0
        public ActionResult Create(Product model, HttpPostedFileBase picture)
        {
            ValidateProduct(model);
            if (ModelState.IsValid)
            {
                if (picture != null)
                {
                    using (var scope = new TransactionScope())
                    {
                        db.Products.Add(model);
                        db.SaveChanges();

                        // store picture
                        var path = Server.MapPath(Picture_PATH);
                        picture.SaveAs(path + model.id);

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

            ViewBag.cate_id = new SelectList(db.Categories, "id", "name", model.cate_id);
            return(View(model));
        }
Esempio n. 3
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));
        }
Esempio n. 4
0
 public ActionResult Create(string roleId, string userId)
 {
     if (ModelState.IsValid)
     {
         var user = db.AspNetUsers.Find(userId);
         var role = db.AspNetRoles.Find(roleId);
         role.AspNetUsers.Add(user);
         db.Entry(role).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index", "AspNetRole"));
     }
     return(RedirectToAction("Create"));
 }