Exemple #1
0
        // GET: Admin/Extras/Create
        public ActionResult Create(int id)
        {
            var subtema = db.SubTemas.Include(s => s.Tema).SingleOrDefault(s => s.SubTemaId == id);

            if (subtema == null)
            {
                return(HttpNotFound());
            }
            ExtraCreateViewModel viewModel = new ExtraCreateViewModel();

            viewModel.Subtema = subtema;
            viewModel.InicializarDesplegables();
            viewModel.CargarClienteSeleccionado(db);
            return(View(viewModel));
        }
Exemple #2
0
        public ActionResult Create(ExtraCreateViewModel viewModel)
        {
            //fichero pdf
            //"~/media/upload/extras_puntos/"

            if (ModelState.IsValid)
            {
                viewModel.Extra.SubTemaId = viewModel.Subtema.SubTemaId;

                viewModel.Extra.Orden = db.Extras.Count(extra => extra.CategoriaExtraId == viewModel.Extra.CategoriaExtraId && extra.SubTemaId == viewModel.Extra.SubTemaId) + 1;
                db.Extras.Add(viewModel.Extra);
                db.SaveChanges();
                if (viewModel.AudioFile != null)
                {
                    viewModel.Extra.Audio = viewModel.Extra.ExtraId + ".mp3";

                    string nameAndLocation = "~/media/upload/extras_audios/" + viewModel.Extra.Audio;
                    viewModel.AudioFile.SaveAs(Server.MapPath(nameAndLocation));

                    db.Entry(viewModel.Extra).State = EntityState.Modified;
                    db.SaveChanges();
                }
                if (viewModel.ImageFile != null)
                {
                    viewModel.Extra.Foto = viewModel.Extra.ExtraId + ".jpg";

                    string nameAndLocation = "~/media/upload/extras_imagenes/" + viewModel.Extra.Foto;
                    viewModel.ImageFile.SaveAs(Server.MapPath(nameAndLocation));

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

                AccesoClientesHelper.AnyadirExtraConHijos(viewModel.Extra.ExtraId, viewModel.Clientes.Where(cli => cli.Selected)
                                                          .Select(cli => Convert.ToInt32(cli.Value)).ToList());
                return(RedirectToAction("Index", "Bloques", new { id = viewModel.Extra.SubTemaId, pestanya = (int)PestanyasBloques.Extras }));
            }
            var subtema = db.SubTemas.Include(s => s.Tema).SingleOrDefault(s => s.SubTemaId == viewModel.Subtema.SubTemaId);

            viewModel.Subtema = subtema;
            viewModel.InicializarDesplegables();
            return(View(viewModel));
        }