public ActionResult Crear(FormCollection collection)
        {
            if (ModelState.IsValid)
            {
                var model = new Producto();
                TryUpdateModel(model, new string[]
                {
                    "Nombre", "Descripcion", "ImagePath",
                    "Visible", "Precio"
                }, collection.ToValueProvider());

                repository.AddProducto(model);

                return RedirectToAction("Index");
            }
            else
            {
                // Error
                ModelState.AddModelError("", "Error goes here");
            }

            return View();
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Productos EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToProductos(Producto producto)
 {
     base.AddObject("Productos", producto);
 }
示例#3
0
 internal void AddProducto(Producto model)
 {
     entity.AddToProductos(model);
     entity.SaveChanges();
 }
 /// <summary>
 /// Create a new Producto object.
 /// </summary>
 /// <param name="productoId">Initial value of the ProductoId property.</param>
 /// <param name="nombre">Initial value of the Nombre property.</param>
 /// <param name="descripcion">Initial value of the Descripcion property.</param>
 /// <param name="precio">Initial value of the Precio property.</param>
 /// <param name="visible">Initial value of the Visible property.</param>
 /// <param name="imagePath">Initial value of the ImagePath property.</param>
 public static Producto CreateProducto(global::System.Int32 productoId, global::System.String nombre, global::System.String descripcion, global::System.Double precio, global::System.Boolean visible, global::System.String imagePath)
 {
     Producto producto = new Producto();
     producto.ProductoId = productoId;
     producto.Nombre = nombre;
     producto.Descripcion = descripcion;
     producto.Precio = precio;
     producto.Visible = visible;
     producto.ImagePath = imagePath;
     return producto;
 }
示例#5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="nombre"></param>
        /// <param name="descripcion"></param>
        /// <param name="precio"></param>
        /// <param name="espcial"></param>
        /// <param name="visible"></param>
        public void AddProducto(string nombre, string descripcion, int precio, bool visible)
        {
            var model = new Producto {
                Nombre = nombre,
                Descripcion = descripcion,
                Precio = precio,
                Visible = visible };

            entity.AddToProductos(model);
            entity.SaveChanges();
        }