public ActionResult EditRestaurante([Bind(Include = "IdRestaurante,Nombre,Telefono,Logo,Tipo")] Restaurante restaurante)
 {
     if (ModelState.IsValid)
     {
         db.Entry(restaurante).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(restaurante));
 }
Beispiel #2
0
        public void AddToCart(ComboRestaurante combo)
        {
            // Get the matching cart and album instances
            var cartItem = db.Carts.SingleOrDefault(
                c => c.CartId == ShoppingCartId &&
                c.IdComboRestaurante == combo.IdComboRestaurante);

            if (cartItem == null)
            {
                // Create a new cart item if no cart item exists
                cartItem = new Cart
                {
                    IdComboRestaurante = combo.IdComboRestaurante,
                    CartId             = ShoppingCartId,
                    Cantidad           = 1,
                    FechaCreacion      = DateTime.Now
                                         //,RecordId = null
                };
                db.Carts.Add(cartItem);
            }
            else
            {
                // If the item does exist in the cart,
                // then add one to the quantity
                cartItem.Cantidad++;
            }



            try
            {
                // Your code...
                // Could also be before try if you know the exception occurs in SaveChanges


                // Save changes
                db.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
        }
        public ActionResult Create([Bind(Include = "IdComboRestaurante,IdRestaurante,Nombre,Descripcion,Precio,Imagen")] ComboRestaurante comboRestaurante)
        {
            if (ModelState.IsValid)
            {
                db.ComboRestaurantes.Add(comboRestaurante);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.IdRestaurante = new SelectList(db.Restaurantes, "IdRestaurante", "Nombre", comboRestaurante.IdRestaurante);
            return(View(comboRestaurante));
        }
Beispiel #4
0
        public ActionResult Create([Bind(Include = "IdUsuario,Nombre,Password,IdRestaurante,IsAdmin")] Usuario usuario)
        {
            if (ModelState.IsValid)
            {
                db.Usuarios.Add(usuario);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.IdRestaurante = new SelectList(db.Restaurantes, "IdRestaurante", "Nombre", usuario.IdRestaurante);
            return(View(usuario));
        }
Beispiel #5
0
        // GET: Checkout/Confirmar
        public ActionResult Confirmar()
        {
            string ip     = null;
            var    pedido = new Pedido();

            ip = HttpContext.Request.ServerVariables["REMOTE_ADDR"];

            ip = ip.Remove(0, 7);

            pedido.IdCliente = ip; //HttpContext.Request.UserHostAddress;
            pedido.Fecha     = DateTime.Now;

            db.Pedidos.Add(pedido);
            db.SaveChanges();

            var cart = ShoppingCart.GetCart(this.HttpContext);

            cart.CreateOrder(pedido);

            return(RedirectToAction("Completado", new { id = pedido.IdPedido }));
        }
 public void Save()
 {
     context.SaveChanges();
 }