public ActionResult SetPreference(int key, string strCityName) { cityDetail cityDetail = new cityDetail(); AppDBEntities ctx = new AppDBEntities(); var itemToRemove = ctx.cityDetails.SingleOrDefault(x => x.Citykey == key); //returns a single item. if (itemToRemove != null) { ctx.cityDetails.Remove(itemToRemove); ctx.SaveChanges(); } cityDetail.CityNAME = strCityName; cityDetail.Citykey = key; ctx.Database.Log = s => System.Diagnostics.Debug.WriteLine(s); ctx.cityDetails.Add(cityDetail); ctx.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Preference() { int key; string strCityName; CityPreference ctx = new CityPreference(); string sqlString = "SELECT VALUE ct FROM CityPreference.cityDetails " + "AS ct"; var objctx = (ctx as IObjectContextAdapter).ObjectContext; ObjectQuery <cityDetail> city = objctx.CreateQuery <cityDetail>(sqlString); cityDetail citypre = city.First <cityDetail>(); key = citypre.Citykey; strCityName = citypre.CityNAME; return(RedirectToAction("CitySelected", new { @key = key, @strCityName = strCityName })); }
public ActionResult SetPreference(int key, string strCityName) { cityDetail cityDetail = new cityDetail(); CityPreference ctx = new CityPreference(); var itemToRemove = ctx.cityDetails.SingleOrDefault(x => x.Citykey == key); //returns a single item. if (itemToRemove != null) { ctx.cityDetails.Remove(itemToRemove); ctx.SaveChanges(); } cityDetail.CityNAME = strCityName; cityDetail.Citykey = key; //Call the function to save the CityPreference dbcontext = new CityPreference(); dbcontext.SaveChanges(); dbcontext.cityDetails.Add(cityDetail); dbcontext.SaveChanges(); return(RedirectToAction("Index")); //return View("Index"); }