public ActionResult Buy(int id) { var cookie = HelperCookie.GetFromCookie("shop-art", "shop-art-key"); Cart cart = new Cart { CartDate = DateTime.Now, Cookie = cookie, ItemCount = 1, }; this.CheckAuditPattern(cart, true); CartItem item = new CartItem { Price = 100, ProductId = id, Quantity = 1 }; this.CheckAuditPattern(item, true); cart.CartItem = new List <CartItem>() { item }; db.Cart.Add(cart); db.SaveChanges(); return(RedirectToAction("Index", "CartItem")); }
public ActionResult Create([Bind(Include = "Id,ProductId,ObrasId,Price,Quantity,CreatedOn,CreatedBy,ChangedOn,ChangedBy")] CarritoItem carritoItem) { if (ModelState.IsValid) { db.CarritoItem.Add(carritoItem); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CarritoId = new SelectList(db.Carrito, "Id", "Cookie", carritoItem.ProductId); return(View(carritoItem)); }