public ActionResult Create() { ViewBag.StatVars = null; ViewBag.Vars = Repo.HydroData.Fetch<variable>("where var_id in (@0)", Helper.VarsID); var st = new station(); st.Location = new location(); st.River = new river(); st.Operator = new @operator(); var river = Repo._GetRivers(); var operators = Repo.HydroData.Fetch<@operator>(""); ViewBag.river1 = new SelectList(river, "riv_id", "riv_name", st.riv_id); ViewBag.Operator1 = new SelectList(operators, "id", "name", st.operator_id); var max = Repo.HydroData.ExecuteScalar<short>("SELECT max(st_id) from stations"); st.st_id = ++max; return View("Edit", st); }
public ActionResult Create(FormCollection collection, int[] vars, int[] publ) { try { var st = new station(); if (TryUpdateModel(st)) { Repo.InvalidateByPattern("cache_stations"); st.Insert(); Repo.UpdateStationVars(st.st_id, vars, publ); ViewBag.Message = "New station added successfully"; return RedirectToAction("Edit", new { id = st.st_id }); } return RedirectToAction("Index"); } catch { return View(); } }