public ActionResult Edit(ExtraEditViewModel viewModel) { if (ModelState.IsValid) { if (viewModel.AudioFile != null) { string fullPath = Request.MapPath("~/media/upload/extras_audios/" + viewModel.Extra.Audio); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } viewModel.Extra.Audio = viewModel.Extra.ExtraId + ".mp3"; string nameAndLocation = "~/media/upload/extras_audios/" + viewModel.Extra.Audio; viewModel.AudioFile.SaveAs(Server.MapPath(nameAndLocation)); } if (viewModel.ImageFile != null) { string fullPath = Request.MapPath("~/media/upload/extras_imagenes/" + viewModel.Extra.Foto); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } 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()); recalcularOrden(viewModel.Extra.CategoriaExtraId, viewModel.Extra.SubTemaId.GetValueOrDefault()); return(RedirectToAction("Index", "Bloques", new { id = viewModel.Extra.SubTemaId, pestanya = (int)PestanyasBloques.Extras })); } viewModel.InicializarDesplegables(); return(View(viewModel)); }
// GET: Admin/Extras/Edit/5 public ActionResult Edit(int id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Extra Extra = db.Extras.Include(e => e.SubTema.Tema).FirstOrDefault(a => a.ExtraId == id); if (Extra == null) { return(HttpNotFound()); } ExtraEditViewModel viewModel = new ExtraEditViewModel(); viewModel.InicializarDesplegables(); viewModel.Extra = Extra; viewModel.CargarClienteSeleccionado(db); return(View(viewModel)); }