コード例 #1
0
 public ActionResult AddProduct(int id, CarroCompra carroCompra)
 {
     if (ModelState.IsValid)
     {
         Producto producto = db.Productoes.Find(id);
         carroCompra.Add(producto);
     }
     else
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     if (User.Identity.IsAuthenticated)
     {
         string loginCliente = User.Identity.Name;
         if (loginCliente == "*****@*****.**")
         {
             return(RedirectToAction("Index", "Productos"));
         }
         else
         {
             return(RedirectToAction("IndexUsers", "Productos"));
         }
     }
     else
     {
         return(RedirectToAction("IndexUsers", "Productos"));
     }
 }
コード例 #2
0
 // GET: Pedidos/Create
 public ActionResult Create(CarroCompra carroCompra)
 {
     if (User.Identity.IsAuthenticated)
     {
         string  loginCliente = User.Identity.Name;
         Cliente cliente      = db.Clientes.First(c => c.Login == loginCliente);
         Pedido  newPedido    = new Pedido();
         newPedido.Id           = generateUniqueToken();
         newPedido.Cliente      = cliente;
         newPedido.ImporteTotal = (float)getImporteTotal(carroCompra);
         newPedido.Fecha        = DateTime.Now;
         db.Pedidoes.Add(newPedido);
         db.SaveChanges();
         foreach (Producto producto in carroCompra)
         {
             INT_ProductoPedido productoPedido = new INT_ProductoPedido();
             productoPedido.FK_INT_Pedido   = newPedido.Id;
             productoPedido.FK_INT_Producto = producto.Id;
             db.INT_ProductoPedido.Add(productoPedido);
         }
         db.SaveChanges();
         this.DecreaseStocks(carroCompra);
         carroCompra.RemoveAll(p => true);
         return(RedirectToAction("List", "Pedidos"));
     }
     else
     {
         return(RedirectToAction("Login", "Account", routeValues: null));
     }
 }
コード例 #3
0
        public ActionResult AddToCart(CarroCompra cc, int id)
        {
            Producto producto = db.Productoes.Find(id);

            cc.Add(producto);
            return(RedirectToAction("Index", "Carro"));
        }
コード例 #4
0
        public Object BindModel(ControllerContext mbctx, System.Web.Mvc.ModelBindingContext bctx)
        {
            CarroCompra carroCompra = (CarroCompra)mbctx.HttpContext.Session[ID_SESSION_CARRO];

            if (carroCompra == null)
            {
                carroCompra = new CarroCompra();
                mbctx.HttpContext.Session[ID_SESSION_CARRO] = carroCompra;
            }
            return(carroCompra);
        }
コード例 #5
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            CarroCompra cc = (CarroCompra)controllerContext.HttpContext.Session[key_cc];

            if (cc == null)
            {
                cc = new CarroCompra();
                controllerContext.HttpContext.Session[key_cc] = cc;
            }
            return(cc);
        }
コード例 #6
0
 //  GET: CarroCompra/Delete/5
 public ActionResult DeleteProduct(int id, CarroCompra carroCompra)
 {
     if (ModelState.IsValid)
     {
         Producto producto = carroCompra.Find(x => x.Id == id);
         carroCompra.Remove(producto);
     }
     else
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     return(RedirectToAction("Index", "CarrosCompra"));
 }
コード例 #7
0
 private void DecreaseStocks(CarroCompra carroCompra)
 {
     if (ModelState.IsValid)
     {
         foreach (Producto producto in carroCompra)
         {
             Producto productoBD = db.Productoes.Find(producto.Id);
             productoBD.Cantidad--;
             db.Entry(productoBD).State = EntityState.Modified;
             db.SaveChanges();
         }
     }
 }
コード例 #8
0
        public ActionResult Buy(CarroCompra cc, int index)
        {
            Producto productInCart = cc.ElementAt(index);
            Producto productInDb   = db.Productoes.Find(productInCart.id);

            if (productInDb.cantidad - 1 < 0)
            {
                return(RedirectToAction("Stock", "Carro", new { id = productInDb.id }));
            }
            else
            {
                cc.RemoveAt(index);
                productInDb.cantidad = productInDb.cantidad - 1;
                Pedido pedido = new Pedido();
                pedido.usuario  = User.Identity.Name;
                pedido.cantidad = 1;
                pedido.Producto = productInDb;
                db.Pedidoes.Add(pedido);
                db.SaveChanges();
                return(RedirectToAction("Index", "Carro"));
            }
        }
コード例 #9
0
 public ActionResult DeleteFromCart(CarroCompra cc, int index)
 {
     cc.RemoveAt(index);
     return(RedirectToAction("Index", "Carro"));
 }
コード例 #10
0
 // GET: Carro
 public ActionResult Index(CarroCompra cc)
 {
     return(View(cc));
 }
コード例 #11
0
 // GET: CarroCompra
 public ActionResult Index(CarroCompra carroCompra)
 {
     ViewData["importeTotal"] = getImporteTotal(carroCompra);
     return(View(carroCompra));
 }
コード例 #12
0
 public ActionResult NumProductosCarroCompra(CarroCompra carroCompra)
 {
     return(PartialView(carroCompra));
 }
コード例 #13
0
        public ActionResult IndexUsers(CarroCompra carroCompra)
        {
            var productoes = db.Productoes;

            return(View(productoes.ToList()));
        }