コード例 #1
0
        public ActionResult RegistrarProducto(HttpPostedFileBase imagen, String nombre, int cantidadStock, int precio, String descripcion, String tipo)
        {
            String imagenNombre = Path.GetFileName(imagen.FileName);

            try
            {
                string path = Server.MapPath("~/img/");

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                imagen.SaveAs(path + Path.GetFileName(imagen.FileName));
            }
            catch (Exception e) { }

            Producto producto = new Producto();

            producto.Nombre        = nombre;
            producto.CantidadStock = cantidadStock;
            producto.Precio        = precio;
            producto.Descripcion   = descripcion;
            producto.Tipo          = int.Parse(tipo);
            producto.Imagen        = imagenNombre;

            DataProducto dataProducto = new DataProducto();

            dataProducto.insertarProducto(producto);
            return(View());
        }