public ActionResult EditDistrict(District ds) { int id = ds.Id; using (restaurants_dbEntities rdb = new restaurants_dbEntities()) { try { var district = rdb.districts.Where(s => s.Id == id).FirstOrDefault(); district.District = ds.Name; rdb.Entry(district).State = System.Data.Entity.EntityState.Modified; rdb.SaveChanges(); string message = "Successfully Saved!"; if (Request.IsAjaxRequest()) { return new JsonResult { Data = message, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; } else { return null; } //return Content(Boolean.TrueString); } catch {//TODO: Log error return Json(false); //return Content(Boolean.FalseString); } } }
public ActionResult CreateDistrict(District ds) { string message = ""; using (restaurants_dbEntities rdb = new restaurants_dbEntities()) { try { rdb.districts.Add(new districts { District = ds.Name, CityId = ds.CityId }); rdb.SaveChanges(); var id = rdb.districts.Where(s => s.District.Equals(ds.Name)).Select(s => s.Id); message = "Successfully Saved!" + id.ToString(); } catch { message = "Error! Please try again!"; } if (Request.IsAjaxRequest()) { return new JsonResult { Data = message, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; } else { return PartialView(); } } }