Beispiel #1
0
        public ActionResult Create(AudioSentenceExerciseCreateViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                viewModel.AudioSentenceExercise.Descripcion = viewModel.AudioSentenceExercise.Enunciado.Replace("#", "______");

                db.AudioSentenceExercises.Add(viewModel.AudioSentenceExercise);
                db.SaveChanges();


                if (viewModel.AudioFile != null)
                {
                    viewModel.AudioSentenceExercise.FicheroAudio = viewModel.AudioSentenceExercise.Id + ".mp3";

                    string nameAndLocation = "~/media/upload/audio_ejercicio/" + viewModel.AudioSentenceExercise.FicheroAudio;
                    viewModel.AudioFile.SaveAs(Server.MapPath(nameAndLocation));

                    db.Entry(viewModel.AudioSentenceExercise).State = EntityState.Modified;
                    db.SaveChanges();
                }

                return(RedirectToAction("Create", "AudioSentenceExercises", new { id = viewModel.AudioSentenceExercise.BloqueId }));
            }


            viewModel.Inicializar(viewModel.AudioSentenceExercise.BloqueId);
            return(View(viewModel));
        }
Beispiel #2
0
        // GET: Admin/AudioSentenceExercises/Create
        public ActionResult Create(int id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Bloque bloque = db.Bloques.SingleOrDefault(bl => bl.BloqueId == id);

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

            AudioSentenceExerciseCreateViewModel viewModel = new AudioSentenceExerciseCreateViewModel();

            viewModel.Inicializar(id);

            viewModel.AudioSentenceExercise = new AudioSentenceExercise();
            viewModel.AudioSentenceExercise.TipoEjercicioId = (int)TiposDeEjerciciosId.AudioSentenceExercise;
            viewModel.AudioSentenceExercise.BloqueId        = id;
            viewModel.AudioSentenceExercise.SubTemaId       = bloque.SubTemaId;
            viewModel.AudioSentenceExercise.AreaId          = viewModel.bloque.AreaId;
            return(View(viewModel));
        }