public ActionResult registrarPlan(VmRegistrarPlan vmRegistrarPlan, HttpPostedFileBase file) { try { Planes obj = null; if (vmRegistrarPlan.planID.HasValue) { obj = context.Planes.FirstOrDefault(x => x.PlanID == vmRegistrarPlan.planID); if (file != null && file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/Content/img"), fileName); file.SaveAs(path); obj.imagen = fileName; } //else //{ // obj.imagen = "portfolio5.jpg"; //} } else { obj = new Planes(); context.Planes.Add(obj); if (file != null && file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/Content/img"), fileName); file.SaveAs(path); obj.imagen = fileName; } else { obj.imagen = "portfolio5.jpg"; } } obj.Nombre = vmRegistrarPlan.nombre; obj.Descripcion = vmRegistrarPlan.descripcion; obj.Costo = vmRegistrarPlan.costo; obj.EstablecimientoID = ((Asociado)Session["objUsuario"]).EstablecimientoID; obj.categoriaID = vmRegistrarPlan.categoria; context.SaveChanges(); return(RedirectToAction("dashboard")); } catch (Exception) { vmRegistrarPlan.Fill(context, null); TryUpdateModel(vmRegistrarPlan); return(View(vmRegistrarPlan)); } }
public ActionResult registrarPlan(int?planId) { GYMEntities context = new GYMEntities(); VmRegistrarPlan vmRegistrar = new VmRegistrarPlan(); vmRegistrar.Fill(context, planId); //GYMEntities context = new GYMEntities(); //vmRegistrar.lista = context.Categoria.ToList(); //Session["establecimiento"] = ((Asociado)Session["objUsuario"]).Establecimiento; //ViewData["categoria"] = new SelectList(lst,"CategoriaID","Nombre"); return(View(vmRegistrar)); }