public ActionResult Edit(string local) { if (local != null) { int id = int.Parse(local); ViewBag.id = id; TempData["codigol"] = id; Local lo = db.Local.Find(id); LocalModel lo1 = new LocalModel(); Session["local"] = lo; int idl = (int)lo.idRegion; lo1.idRegion = (int)lo.idRegion; lo1.idProv = (int)lo.idProvincia; List<Region> listaDep = db.Region.Where(c => c.idRegPadre == null).ToList(); List<Region> listProv = db.Region.Where(c => c.idRegPadre == idl).ToList(); ViewBag.DepID = new SelectList(listaDep, "idRegion", "nombre", lo1.idRegion); ViewBag.ProvID = new SelectList(listProv, "idRegion", "nombre", lo1.idProv); } return View("Edit"); }
public ActionResult RegisterLocal(LocalModel model) { if (ModelState.IsValid) { Local local = new Local(); //Local localL = db.Local.ToList().Last(); //local.codLocal = localL.codLocal + 1; local.descripcion = model.descripcion; local.ubicacion = model.ubicacion; local.estaActivo = true; local.idProvincia = model.idProv; local.idRegion = model.idRegion; db.Local.Add(local); db.SaveChanges(); return RedirectToAction("Index", "Local"); } List<Region> listaDep = db.Region.Where(c => c.idRegPadre == null).ToList(); List<Region> listProv = new List<Region>(); ViewBag.DepID = new SelectList(listaDep, "idRegion", "nombre"); ViewBag.ProvID = new SelectList(listProv, "idProv", "nombre"); return View("Index"); }