public ActionResult Create(FormCollection formCollection) { List <SelectListItem> selectlistitems = new List <SelectListItem>(); List <SelectListItem> countryselectlistitems = new List <SelectListItem>(); stateBusinessLayer StateBusinessLayer = new stateBusinessLayer(); CountryBusinessLayer countryBusinessLayer = new CountryBusinessLayer(); foreach (state State in StateBusinessLayer.States.Where(x => x.CountryId == Convert.ToInt64(formCollection["countries"]))) { SelectListItem selectListItem = new SelectListItem { Text = State.State, Value = State.Id.ToString(), }; selectlistitems.Add(selectListItem); } foreach (Country country in countryBusinessLayer.countries) { SelectListItem selectListItem1 = new SelectListItem { Text = country.CountryName, Value = country.Id.ToString(), Selected = (country.Id == Convert.ToInt64(formCollection["countries"]) ? true : false) }; countryselectlistitems.Add(selectListItem1); } //ViewBag.countries = new SelectList(countryBusinessLayer.countries.ToList(), "Id", "CountryName", formCollection["countries"]); ViewBag.States = new SelectList(selectlistitems, "Value", "Text"); return(View()); }
// GET: state public ActionResult Index() { stateBusinessLayer StateBusinessLayer = new stateBusinessLayer(); List <state> State = new List <state>(); State = StateBusinessLayer.States.ToList(); return(View(State)); }
public ActionResult Delete(Int64 id) { stateBusinessLayer StateBusinessLayer = new stateBusinessLayer(); state State = StateBusinessLayer.States.Single(x => x.Id == id); ConfigurationManager.AppSettings["EditId"] = id.ToString(); CountryBusinessLayer countryBusinessLayer = new CountryBusinessLayer(); Country country = countryBusinessLayer.countries.Single(x => x.Id == State.CountryId); State.CountryName = country.CountryName; return(View(State)); }
public ActionResult Create(FormCollection formCollection) { state State = new state(); State.State = formCollection["State"]; State.CountryId = Convert.ToInt64(formCollection["countries"]); stateBusinessLayer StateBusinessLayer = new stateBusinessLayer(); int rv = StateBusinessLayer.AddState(State); if (rv != 0 && rv != -1) { return(RedirectToAction("Index")); } return(View()); }
public ActionResult Delete(FormCollection formCollection) { stateBusinessLayer StateBusinessLayer = new stateBusinessLayer(); state State = new state(); State.State = formCollection["State"]; State.CountryId = Convert.ToInt64(formCollection["CountryId"]); State.Id = Convert.ToInt64(ConfigurationManager.AppSettings["EditId"].ToString()); int rv = StateBusinessLayer.DeleteState(State); if (rv != 0 && rv != -1) { return(RedirectToAction("Index")); } return(View()); }
public ActionResult Edit(Int64 id) { stateBusinessLayer StateBusinessLayer = new stateBusinessLayer(); state State = StateBusinessLayer.States.Single(x => x.Id == id); ConfigurationManager.AppSettings["EditId"] = id.ToString(); CountryBusinessLayer countryBusinessLayer = new CountryBusinessLayer(); List <SelectListItem> selectlistitems = new List <SelectListItem>(); foreach (Country country in countryBusinessLayer.countries) { SelectListItem selectListItem = new SelectListItem { Text = country.CountryName, Value = country.Id.ToString(), Selected = country.Id == State.CountryId ? true : false }; selectlistitems.Add(selectListItem); } ViewBag.countries = selectlistitems; return(View(State)); }