コード例 #1
0
        public ActionResult Create(MatchThePictureCreateViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                viewModel.MatchThePicture.Descripcion = viewModel.MatchThePicture.PalabraImagen;

                db.MatchThePictures.Add(viewModel.MatchThePicture);
                db.SaveChanges();



                viewModel.MatchThePicture.UrlImagen = viewModel.MatchThePicture.Id + ".jpg";

                string nameAndLocation = "~/media/upload/MatchThePicture/" + viewModel.MatchThePicture.UrlImagen;
                viewModel.ImageFile.SaveAs(Server.MapPath(nameAndLocation));

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


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


            viewModel.Inicializar(viewModel.MatchThePicture.BloqueId);
            return(View(viewModel));
        }
コード例 #2
0
        // GET: Admin/MatchThePictures/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());
            }
            MatchThePictureCreateViewModel viewModel = new MatchThePictureCreateViewModel();

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