public void PruebaConsultaFicherosBinarios()
        {
            var f = new Ficheros()
            {
                Datos = "",
                DatosB = new byte[] {},
                Nombre = "Borrar",
                TipoFichero = 1,
                Tipo = "azure"
            };

            int n = 0;

            db.Ficheros.Add(f);

            try
            {
                n = db.SaveChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            Assert.IsFalse(n==0);
        }
        public ActionResult Subida(Ficheros model, HttpPostedFileBase fichero)
        {
            if (model.Tipo == "interno")
            {
                var n = GestionarFicheros.GuardarFicheroDisco(fichero, Server);

                if (n != null)
                {
                    model.Datos = n;
                    model.DatosB = new byte[] {1};
                    db.Ficheros.Add(model);

                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }
                }
            }
            else if (model.Tipo == "base64")
            {
                var data = GestionarFicheros.ToBinario(fichero);
                if (data != null)
                {
                    model.Datos = Convert.ToBase64String(data);
                    model.DatosB = new byte[] {1};
                    model.Nombre = fichero.FileName;
                    db.Ficheros.Add(model);
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }
                }
            }
            else if (model.Tipo == "binario")
            {
                var datab = GestionarFicheros.ToBinario(fichero);
                if (datab != null)
                {
                    model.Datos = "";
                    model.DatosB = datab;
                    model.Nombre = fichero.FileName;
                    db.Ficheros.Add(model);
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }
                }
            }
            else if (model.Tipo == "azure")
            {
                var cuenta = ConfigurationManager.AppSettings["CuentaAS"];
                var clave = ConfigurationManager.AppSettings["ClaveAS"];
                var contenedor = ConfigurationManager.AppSettings["ContenedorAS"];

                var az = new AzureStorageUtils(cuenta, clave, contenedor);

                var n = Guid.NewGuid();
                var ext = fichero.FileName.Substring(fichero.FileName.LastIndexOf("."));

                az.SubirFichero(fichero.InputStream, n + ext);

                model.Datos = n+ext;
                model.Nombre = fichero.FileName;

                db.Ficheros.Add(model);
                db.SaveChanges();
            }

            return RedirectToAction("Index");
        }