//Eliminar producto del carrito public ActionResult RemoveFromCartProducto(int id) { // Get the cart var cart = CarritoCompras.GetCart(HttpContext); cart.RemoveFromCartProducto(id); // Go back to the main store page for more shopping return(RedirectToAction("Index")); }
//Eliminar todos los productos del carrito public ActionResult VaciarCarrito() { // Get the cart var cart = CarritoCompras.GetCart(HttpContext); cart.EmptyCart(); // Go back to the main store page for more shopping return(RedirectToAction("Index")); }
public ActionResult AddToCart(int id) { var addedItem = storeDB.Items .Single(item => item.ItemId == id); var carrito = CarritoCompras.GetCart(this.HttpContext); carrito.AddToCart(addedItem); return(RedirectToAction("Index")); }
// GET: CarritoCompras public ActionResult Index() { var carrito = CarritoCompras.GetCart(this.HttpContext); var viewModel = new CarritoComprasModel { ItemCarrito = carrito.GetCartItems(), CarritoTotal = carrito.GetTotal() }; return(View(viewModel)); }
// GET: /Store/AddToCart/5 public ActionResult AddToCart(int id) { // Retrieve the album from the database var addedItem = carroDB.Productos .Single(Producto => Producto.ProductoID == id); // Add it to the shopping cart var cart = CarritoCompras.GetCart(HttpContext); cart.AddToCart(addedItem); // Go back to the main store page for more shopping return(RedirectToAction("Index")); }
// GET: CarritoCompras public ActionResult Index() { var cart = CarritoCompras.GetCart(HttpContext); // Set up our ViewModel var viewModel = new CarritoComprasViewModels { CartItems = cart.GetCartItems(), CartTotal = cart.GetTotal() }; // Return the view return(View(viewModel)); }
public ActionResult Compra(Compra compra) { TryUpdateModel(compra); var userid = User.Identity.GetUserId(); RepoDapper EmpRepo = new RepoDapper(); ViewBag.TarjetaId2 = new SelectList(EmpRepo.GetTarjetas(userid), "id", "Numero"); if (compra.TarjetaId == 0) { return(RedirectToAction("AddTarjeta", "Manage")); } ViewBag.DireccionID = new SelectList(EmpRepo.GetDirecciones(userid), "id", "Direccion"); ViewBag.PaqueteriaID = new SelectList(EmpRepo.GetEnvios(), "id", "Nombre", compra.PaqueteriaId); PaqueteriasContext paqueteriasDB = new PaqueteriasContext(); int _PaqueteriasId = paqueteriasDB.Paquete.Where(x => x.Id == compra.PaqueteriaId).Select(x => x.PaqueteriasId).FirstOrDefault(); int _precioEnvio = (int)paqueteriasDB.Paquete.Where(x => x.Id == compra.PaqueteriaId).Select(x => x.Precio).FirstOrDefault(); compra.UserId = userid; compra.FechaCompra = DateTime.Now; compra.PaqueteriaId = _PaqueteriasId; var cart = CarritoCompras.GetCart(this.HttpContext); int _subtotal = (int)cart.GetTotal(); int _total = _precioEnvio + _subtotal; compra.Total = _total; try { carroDB.Compras.Add(compra); carroDB.SaveChanges(); cart.CreateOrder(compra, _precioEnvio); return(RedirectToAction("Index", "Compras")); } catch { return(View(compra)); } }
public ActionResult RemoverCarrito(int id) { var carrito = CarritoCompras.GetCart(this.HttpContext); string itemName = storeDB.Carrito .Single(Item => Item.RegistroId == id).Item.Titulo; int itemCount = carrito.RemoveFromCart(id); var results = new EliminarCarritoCompraModel { Mensaje = Server.HtmlEncode(itemName) + " se ha removido del carrito de compras.", CarritoTotal = carrito.GetTotal(), CartCount = carrito.GetCount(), ItemCount = itemCount, DeleteId = id }; return(Json(results)); }