Ejemplo n.º 1
0
        // GET: Admin/Frases/Copy
        public ActionResult Copy(int id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var frase = db.Frases.Find(id);

            if (frase == null)
            {
                return(HttpNotFound());
            }

            FrasesCopyViewModel viewModel = new FrasesCopyViewModel();

            viewModel.Frase = frase;
            viewModel.InicializarDesplegables();

            var gramatica = db.Gramaticas.Include(s => s.SubTema.Tema).SingleOrDefault(s => s.GramaticaId == frase.GramaticaId);

            viewModel.GramaticaId     = gramatica.GramaticaId;
            viewModel.GramaticaTitulo = gramatica.Titulo;
            viewModel.SubTema         = gramatica.SubTema;

            return(View(viewModel));
        }
Ejemplo n.º 2
0
        public ActionResult Copy(FrasesCopyViewModel viewModel)
        {
            int id    = viewModel.Frase.FraseId;
            var frase = db.Frases.Find(id);

            viewModel.Frase = frase;
            var gramatica = db.Gramaticas.Include(s => s.SubTema.Tema).SingleOrDefault(s => s.GramaticaId == frase.GramaticaId);

            viewModel.GramaticaId     = gramatica.GramaticaId;
            viewModel.GramaticaTitulo = gramatica.Titulo;
            viewModel.SubTema         = gramatica.SubTema;
            if (ModelState.IsValid)
            {
                viewModel.Frase.GramaticaId = viewModel.GramaticaCopiarId;

                db.Frases.Add(viewModel.Frase);
                db.SaveChanges();


                if (!string.IsNullOrEmpty(viewModel.Frase.FicheroAudio_en))
                {
                    string oldPathAndName = "~/media/upload/frases_mp3/" + viewModel.Frase.FicheroAudio_en;
                    string newPathAndName = "~/media/upload/frases_mp3/" + viewModel.Frase.FraseId + "_en.mp3";

                    System.IO.File.Copy(Server.MapPath(oldPathAndName), Server.MapPath(newPathAndName));

                    viewModel.Frase.FicheroAudio_en = viewModel.Frase.FraseId + "_en.mp3";
                    db.Entry(viewModel.Frase).State = EntityState.Modified;
                    db.SaveChanges();
                }
                if (!string.IsNullOrEmpty(viewModel.Frase.FicheroAudio_es))
                {
                    string oldPathAndName = "~/media/upload/frases_mp3/" + viewModel.Frase.FicheroAudio_es;
                    string newPathAndName = "~/media/upload/frases_mp3/" + viewModel.Frase.FraseId + "_es.mp3";

                    System.IO.File.Copy(Server.MapPath(oldPathAndName), Server.MapPath(newPathAndName));

                    viewModel.Frase.FicheroAudio_es = viewModel.Frase.FraseId + "_es.mp3";
                    db.Entry(viewModel.Frase).State = EntityState.Modified;
                    db.SaveChanges();
                }

                return(RedirectToAction("Index", "Frases", new { id = viewModel.Frase.GramaticaId }));
            }

            viewModel.InicializarDesplegables();
            return(View(viewModel));
        }