public ActionResult Details(int?id, string HostingEntityName, string AssociatedType, string defaultview) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (!CustomAuthorizationBeforeDetails(id, HostingEntityName, AssociatedType)) { return(RedirectToAction("Index", "Error")); } T_City t_city = db.T_Citys.Find(id); if (t_city == null) { return(HttpNotFound()); } if (string.IsNullOrEmpty(defaultview)) { defaultview = "Details"; } GetTemplatesForDetails(defaultview); ViewData["AssociatedType"] = AssociatedType; ViewData["HostingEntityName"] = HostingEntityName; LoadViewDataBeforeOnEdit(t_city); if (!string.IsNullOrEmpty(AssociatedType)) { LoadViewDataForCount(t_city, AssociatedType); } ViewBag.T_CityIsHiddenRule = checkHidden("T_City", "OnDetails", false); ViewBag.T_CityIsGroupsHiddenRule = checkHidden("T_City", "OnDetails", true); ViewBag.T_CityIsSetValueUIRule = checkSetValueUIRule("T_City", "OnDetails"); return(View(ViewBag.TemplatesName, t_city)); }
private void T_Adr_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { T_City.Focus(); } }
public ActionResult DeleteConfirmed(T_City t_city, string UrlReferrer) { if (!User.CanDelete("T_City")) { return(RedirectToAction("Index", "Error")); } if (CheckBeforeDelete(t_city)) { bool customdelete_hasissues = false; if (!CustomDelete(t_city, out customdelete_hasissues, "Delete")) { db.Entry(t_city).State = EntityState.Deleted; db.T_Citys.Remove(t_city); db.SaveChanges(); } if (!customdelete_hasissues) { if (!string.IsNullOrEmpty(UrlReferrer)) { return(Redirect(UrlReferrer)); } if (ViewData["T_CityParentUrl"] != null) { string parentUrl = ViewData["T_CityParentUrl"].ToString(); ViewData["T_CityParentUrl"] = null; return(Redirect(parentUrl)); } else { return(RedirectToAction("Index")); } } } return(View(t_city)); }
public ActionResult CreateWizard([Bind(Include = "Id,ConcurrencyKey,T_Name,T_Description,T_CityCountryID,T_CityStateID")] T_City t_city, string UrlReferrer) { CheckBeforeSave(t_city); if (ModelState.IsValid) { bool customcreate_hasissues = false; if (!CustomSaveOnCreate(t_city, out customcreate_hasissues, "Create")) { db.T_Citys.Add(t_city); db.SaveChanges(); } if (!customcreate_hasissues) { RedirectToRouteResult customRedirectAction = CustomRedirectUrl(t_city, "Create", ""); if (customRedirectAction != null) { return(customRedirectAction); } if (!string.IsNullOrEmpty(UrlReferrer)) { return(Redirect(UrlReferrer)); } else { return(RedirectToAction("Index")); } } } LoadViewDataAfterOnCreate(t_city); ViewBag.T_CityIsHiddenRule = checkHidden("T_City", "OnCreate", false); ViewBag.T_CityIsGroupsHiddenRule = checkHidden("T_City", "OnCreate", true); ViewBag.T_CityIsSetValueUIRule = checkSetValueUIRule("T_City", "OnCreate"); return(View(t_city)); }
public ActionResult BulkAssociate(long[] ids, string AssociatedType, string HostingEntity, string HostingEntityID) { var HostingID = Convert.ToInt64(HostingEntityID); if (HostingID == 0) { return(Json("Error", "application/json", System.Text.Encoding.UTF8, JsonRequestBehavior.AllowGet)); } if (HostingEntity == "T_Country" && AssociatedType == "T_CityCountry") { foreach (var id in ids.Where(p => p > 0)) { T_City obj = db.T_Citys.Find(id); db.Entry(obj).State = EntityState.Modified; obj.T_CityCountryID = HostingID; db.SaveChanges(); } } if (HostingEntity == "T_State" && AssociatedType == "T_CityState") { foreach (var id in ids.Where(p => p > 0)) { T_City obj = db.T_Citys.Find(id); db.Entry(obj).State = EntityState.Modified; obj.T_CityStateID = HostingID; db.SaveChanges(); } } return(Json("Success", "application/json", System.Text.Encoding.UTF8, JsonRequestBehavior.AllowGet)); }
public ActionResult DeleteBulk(long[] ids, string UrlReferrer) { if (User != null && (!((CustomPrincipal)User).CanUseVerb("BulkDelete", "T_City", User) || !User.CanDelete("T_City"))) { return(RedirectToAction("Index", "Error")); } bool customdelete_hasissues = false; foreach (var id in ids.Where(p => p > 0)) { customdelete_hasissues = false; T_City t_city = db.T_Citys.Find(id); if (CheckBeforeDelete(t_city)) { if (!CustomDelete(t_city, out customdelete_hasissues, "DeleteBulk")) { db.Entry(t_city).State = EntityState.Deleted; db.T_Citys.Remove(t_city); try { db.SaveChanges(); } catch { } } } } return(Json("Success", "application/json", System.Text.Encoding.UTF8, JsonRequestBehavior.AllowGet)); }
private bool CustomDelete(T_City t_city, out bool customdelete_hasissues, string command = "") { var result = false; customdelete_hasissues = false; return(result); }
private bool CustomSaveOnImport(T_City t_city, out string customerror, int i) { var result = false; customerror = ""; return(result); }
private bool CustomSaveOnEdit(T_City t_city, out bool customsave_hasissues, string command = "") { var result = false; customsave_hasissues = false; return(result); }
public string CheckBeforeSave(T_City t_city, string command = "") { var AlertMsg = ""; // Write your logic here //Make sure to assign AlertMsg with proper message //AlertMsg = "Validation Alert - Before Save !! Information not saved."; //ModelState.AddModelError("CustomError", AlertMsg); //ViewBag.ApplicationError = AlertMsg; return(AlertMsg); }
public ActionResult BulkUpdate([Bind(Include = "Id,ConcurrencyKey,T_Name,T_Description,T_CityCountryID,T_CityStateID")] T_City t_city, FormCollection collection, string UrlReferrer) { var bulkIds = collection["BulkUpdate"].Split(',').ToList(); var chkUpdate = collection["chkUpdate"]; if (!string.IsNullOrEmpty(chkUpdate)) { bool customsave_hasissues = false; foreach (var id in bulkIds.Where(p => p != string.Empty)) { long objId = long.Parse(id); T_City target = db.T_Citys.Find(objId); target.setDateTimeToClientTime(); EntityCopy.CopyValuesForSameObjectType(t_city, target, chkUpdate); customsave_hasissues = false; CheckBeforeSave(target, "BulkUpdate"); if (ValidateModel(target) && !CustomSaveOnEdit(target, out customsave_hasissues, "BulkUpdate")) { db.Entry(target).State = EntityState.Modified; try { if (target.t_citycountry != null) { db.Entry(target.t_citycountry).State = EntityState.Unchanged; } if (target.t_citystate != null) { db.Entry(target.t_citystate).State = EntityState.Unchanged; } db.SaveChanges(); } catch { } } } } RedirectToRouteResult customRedirectAction = CustomRedirectUrl(t_city, "BulkUpdate", ""); if (customRedirectAction != null) { return(customRedirectAction); } if (!string.IsNullOrEmpty(UrlReferrer)) { return(Redirect(UrlReferrer)); } else { return(RedirectToAction("Index")); } }
public bool CheckBeforeDelete(T_City t_city) { var result = true; // Write your logic here if (!result) { var AlertMsg = "Validation Alert - Before Delete !! Information not deleted."; ModelState.AddModelError("CustomError", AlertMsg); ViewBag.ApplicationError = AlertMsg; } return(result); }
public JsonResult Del(string id) { try { T_City city = dc.Set <T_City>().Where(a => a.ID == id).FirstOrDefault(); dc.Set <T_City>().Remove(city); dc.SaveChanges(); return(Json(Result.Success())); } catch (Exception ex) { return(Json(Result.Exception(exmsg: ex.StackTrace))); } }
/// <summary> /// JSONP 返回Object对象 /// 传递方式:GET /// </summary> /// <param name="id"></param> /// <param name="city"></param> /// <returns></returns> public JsonpResult JsonpObject(T_City city, String id) { String sql = "SELECT * FROM [T_City] LIMIT 10";// WHERE City_Id='" + city.City_Id + "' List <T_City> data = db.ExecuteObject <List <T_City> >(sql); //构造返回数据 var result = new IResult { data = data, header = RequestHeader }; return(new JsonpResult(result)); }
public JsonResult Close(string id) { try { T_City city = dc.Set <T_City>().Where(a => a.ID == id).FirstOrDefault(); city.Enable = false; dc.Set <T_City>().AddOrUpdate(city); dc.SaveChanges(); return(Json(Result.Success())); } catch (Exception ex) { return(Json(Result.Exception(exmsg: ex.StackTrace))); } }
public JsonResult Create(T_City city) { try { city.Enable = true; city.IsDefault = false; dc.Set <T_City>().Add(city); dc.SaveChanges(); return(Json(Result.Success())); } catch (Exception ex) { return(Json(Result.Exception(exmsg: ex.StackTrace))); } }
public ContentResult SaveForm(T_City city) { Byte[] b = new Byte[Request.InputStream.Length]; Request.InputStream.Read(b, 0, b.Length); string json = Encoding.UTF8.GetString(b); //StreamReader reader = new StreamReader(Request.InputStream); //string json = reader.ReadToEnd(); //List<T_City> list = SerializerHelper.JsonToObject<List<T_City>>(json); List <T_City> list = JsonConvert.DeserializeObject <List <T_City> >(json); json = JsonConvert.SerializeObject(list); return(Content(json, "application/json")); }
public ActionResult Create([Bind(Include = "Id,ConcurrencyKey,T_Name,T_Description,T_CityCountryID,T_CityStateID")] T_City t_city, string UrlReferrer, bool?IsDDAdd) { string command = Request.Form["hdncommand"]; CheckBeforeSave(t_city, command); if (ModelState.IsValid) { bool customcreate_hasissues = false; if (!CustomSaveOnCreate(t_city, out customcreate_hasissues, command)) { db.T_Citys.Add(t_city); db.SaveChanges(); } if (!customcreate_hasissues) { RedirectToRouteResult customRedirectAction = CustomRedirectUrl(t_city, "Create", command); if (customRedirectAction != null) { return(customRedirectAction); } if (command == "Create & Continue") { return(RedirectToAction("Edit", new { Id = t_city.Id, UrlReferrer = UrlReferrer })); } if (!string.IsNullOrEmpty(UrlReferrer)) { return(Redirect(UrlReferrer)); } else { return(RedirectToAction("Index")); } } } if (IsDDAdd != null) { ViewBag.IsDDAdd = Convert.ToBoolean(IsDDAdd); } LoadViewDataAfterOnCreate(t_city); ViewData["T_CityParentUrl"] = UrlReferrer; ViewBag.T_CityIsHiddenRule = checkHidden("T_City", "OnCreate", false); ViewBag.T_CityIsGroupsHiddenRule = checkHidden("T_City", "OnCreate", true); ViewBag.T_CityIsSetValueUIRule = checkSetValueUIRule("T_City", "OnCreate"); return(View(t_city)); }
public JsonResult Edit(string id, FormCollection form) { try { T_City city = dc.Set <T_City>().Where(a => a.ID == id).FirstOrDefault(); if (TryUpdateModel(city, "", form.AllKeys, new string[] { "Enable", "IsDefault" })) { dc.SaveChanges(); return(Json(Result.Success())); } return(Json(Result.Fail())); } catch (Exception ex) { return(Json(Result.Exception(exmsg: ex.StackTrace))); } }
private void procityareabind(int _id) { tbl_product model1 = new tbl_product(); model1.GetModel(_id); T_Province bll = new T_Province(); DataTable dt = bll.GetList("1=1 order by ProSort").Tables[0]; this.ddlprov.Items.Clear(); this.ddlprov.Items.Add(new ListItem("请选择...", "")); foreach (DataRow dr in dt.Rows) { string Id = dr["ProID"].ToString(); string Title = dr["ProName"].ToString().Trim(); this.ddlprov.Items.Add(new ListItem(Title, Id)); } string proid = model1.province_id.ToString(); T_City bllc = new T_City(); DataTable dtc = bllc.GetList("1=1 and ProID='" + proid + "' order by CitySort").Tables[0]; this.ddlcity.Items.Clear(); this.ddlcity.Items.Add(new ListItem("请选择...", "")); foreach (DataRow dr in dtc.Rows) { string Id = dr["CityID"].ToString(); string Title = dr["CityName"].ToString().Trim(); this.ddlcity.Items.Add(new ListItem(Title, Id)); } string cityid = model1.city_id.ToString(); T_District blld = new T_District(); DataTable dtd = blld.GetList("1=1 and CityID='" + cityid + "' order by DisSort").Tables[0]; this.ddlarea.Items.Clear(); this.ddlarea.Items.Add(new ListItem("请选择...", "")); foreach (DataRow dr in dtd.Rows) { string Id = dr["Id"].ToString(); string Title = dr["DisName"].ToString().Trim(); this.ddlarea.Items.Add(new ListItem(Title, Id)); } }
public ActionResult EditWizard([Bind(Include = "Id,ConcurrencyKey,T_Name,T_Description,T_CityCountryID,T_CityStateID")] T_City t_city, string UrlReferrer) { CheckBeforeSave(t_city); if (ModelState.IsValid) { bool customsave_hasissues = false; if (!CustomSaveOnEdit(t_city, out customsave_hasissues, "Save")) { db.Entry(t_city).State = EntityState.Modified; db.SaveChanges(); } if (!customsave_hasissues) { RedirectToRouteResult customRedirectAction = CustomRedirectUrl(t_city, "Edit", ""); if (customRedirectAction != null) { return(customRedirectAction); } if (!string.IsNullOrEmpty(UrlReferrer)) { var uri = new Uri(UrlReferrer); var query = HttpUtility.ParseQueryString(uri.Query); if (Convert.ToBoolean(query.Get("IsFilter")) == true) { return(RedirectToAction("Index")); } else { return(Redirect(UrlReferrer)); } } else { return(RedirectToAction("Index")); } } } LoadViewDataAfterOnEdit(t_city); ViewBag.T_CityIsHiddenRule = checkHidden("T_City", "OnEdit", false); ViewBag.T_CityIsGroupsHiddenRule = checkHidden("T_City", "OnEdit", true); ViewBag.T_CityIsSetValueUIRule = checkSetValueUIRule("T_City", "OnEdit"); return(View(t_city)); }
//添加城市 public ActionResult AddCity(T_City tpe) { if (tpe.ID <= 0) { if (T_CityService.LoadEntities(x => x.City == tpe.City).FirstOrDefault() == null) { tpe.DelFlag = 0; T_CityService.AddEntity(tpe); return(Json(new { ret = "ok" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { msg = "不可添加重复的城市!~", JsonRequestBehavior.AllowGet })); } } else { return(Json(new { msg = "添加出错,请联系管理员!~", JsonRequestBehavior.AllowGet })); } }
protected void ddlprov_SelectedIndexChanged(object sender, EventArgs e) { string proid = this.ddlprov.SelectedValue; T_City bllc = new T_City(); DataTable dtc = bllc.GetList("1=1 and ProID='" + proid + "' order by CitySort").Tables[0]; this.ddlcity.Items.Clear(); this.ddlcity.Items.Add(new ListItem("请选择...", "")); foreach (DataRow dr in dtc.Rows) { string Id = dr["CityID"].ToString(); string Title = dr["CityName"].ToString().Trim(); this.ddlcity.Items.Add(new ListItem(Title, Id)); } T_District blld = new T_District(); DataTable dtd = blld.GetList("1=1 order by DisSort").Tables[0]; this.ddlarea.Items.Clear(); this.ddlarea.Items.Add(new ListItem("请选择...", "")); }
public ActionResult EditQuick(int?id, string UrlReferrer, string HostingEntityName, string AssociatedType, string viewtype) { if (!User.CanEdit("T_City") || !CustomAuthorizationBeforeEdit(id, HostingEntityName, AssociatedType)) { return(RedirectToAction("Index", "Error")); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (string.IsNullOrEmpty(viewtype)) { viewtype = "EditQuick"; } GetTemplatesForEditQuick(viewtype); T_City t_city = db.T_Citys.Find(id); if (t_city == null) { return(HttpNotFound()); } if (UrlReferrer != null) { ViewData["T_CityParentUrl"] = UrlReferrer; } if (ViewData["T_CityParentUrl"] == null && Request.UrlReferrer != null && !Request.UrlReferrer.AbsolutePath.EndsWith("/T_City") && !Request.UrlReferrer.AbsolutePath.EndsWith("/T_City/Edit/" + t_city.Id + "") && !Request.UrlReferrer.AbsolutePath.EndsWith("/T_City/Create")) { ViewData["T_CityParentUrl"] = Request.UrlReferrer; } ViewData["HostingEntityName"] = HostingEntityName; ViewData["AssociatedType"] = AssociatedType; LoadViewDataBeforeOnEdit(t_city); ViewBag.T_CityIsHiddenRule = checkHidden("T_City", "OnEdit", false); ViewBag.T_CityIsGroupsHiddenRule = checkHidden("T_City", "OnEdit", true); ViewBag.T_CityIsSetValueUIRule = checkSetValueUIRule("T_City", "OnEdit"); var objT_City = new List <T_City>(); ViewBag.T_CityDD = new SelectList(objT_City, "ID", "DisplayValue"); return(View(t_city)); }
public ActionResult EditQuick([Bind(Include = "Id,ConcurrencyKey,T_Name,T_Description,T_CityCountryID,T_CityStateID")] T_City t_city, string UrlReferrer, bool?IsAddPop, string AssociatedEntity) { string command = Request.Form["hdncommand"]; CheckBeforeSave(t_city, command); if (ModelState.IsValid) { bool customsave_hasissues = false; if (!CustomSaveOnEdit(t_city, out customsave_hasissues, command)) { db.Entry(t_city).State = EntityState.Modified; db.SaveChanges(); } var result = new { Result = "Succeed", UrlRefr = UrlReferrer }; if (!customsave_hasissues) { return(Json(result, "application/json", System.Text.Encoding.UTF8, JsonRequestBehavior.AllowGet)); } } else { var errors = ""; foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { errors += error.ErrorMessage + ". "; } } var result = new { Result = "fail", UrlRefr = errors }; return(Json(result, "application/json", System.Text.Encoding.UTF8, JsonRequestBehavior.AllowGet)); } LoadViewDataAfterOnEdit(t_city); ViewBag.T_CityIsHiddenRule = checkHidden("T_City", "OnEdit", false); ViewBag.T_CityIsGroupsHiddenRule = checkHidden("T_City", "OnEdit", true); ViewBag.T_CityIsSetValueUIRule = checkSetValueUIRule("T_City", "OnEdit"); return(View(t_city)); }
// GET: /T_City/Delete/5 public ActionResult Delete(int id) { if (!User.CanDelete("T_City") || !CustomAuthorizationBeforeDelete(id)) { return(RedirectToAction("Index", "Error")); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } T_City t_city = db.T_Citys.Find(id); if (t_city == null) { throw(new Exception("Deleted")); } if (ViewData["T_CityParentUrl"] == null && Request.UrlReferrer != null && !Request.UrlReferrer.AbsolutePath.EndsWith("/T_City")) { ViewData["T_CityParentUrl"] = Request.UrlReferrer; } return(View(t_city)); }
private void procityareabind() { T_Province bll = new T_Province(); DataTable dt = bll.GetList("1=1 order by ProSort").Tables[0]; this.ddlprov.Items.Clear(); this.ddlprov.Items.Add(new ListItem("请选择...", "")); foreach (DataRow dr in dt.Rows) { string Id = dr["ProID"].ToString(); string Title = dr["ProName"].ToString().Trim(); this.ddlprov.Items.Add(new ListItem(Title, Id)); } T_City bllc = new T_City(); DataTable dtc = bllc.GetList("1=1 order by CitySort").Tables[0]; this.ddlcity.Items.Clear(); this.ddlcity.Items.Add(new ListItem("请选择...", "")); //foreach (DataRow dr in dtc.Rows) //{ // string Id = dr["CityID"].ToString(); // string Title = dr["CityName"].ToString().Trim(); // this.ddlcity.Items.Add(new ListItem(Title, Id)); //} T_District blld = new T_District(); DataTable dtd = blld.GetList("1=1 order by DisSort").Tables[0]; this.ddlarea.Items.Clear(); this.ddlarea.Items.Add(new ListItem("请选择...", "")); //foreach (DataRow dr in dtd.Rows) //{ // string Id = dr["Id"].ToString(); // string Title = dr["DisName"].ToString().Trim(); // this.ddlarea.Items.Add(new ListItem(Title, Id)); //} }
public ActionResult CreateQuick([Bind(Include = "Id,ConcurrencyKey,T_Name,T_Description,T_CityCountryID,T_CityStateID")] T_City t_city, string UrlReferrer, bool?IsAddPop, string AssociatedEntity, string HostingEntityName, string HostingEntityID) { CheckBeforeSave(t_city); if (ModelState.IsValid) { bool customcreate_hasissues = false; if (!CustomSaveOnCreate(t_city, out customcreate_hasissues, "Create")) { db.T_Citys.Add(t_city); db.SaveChanges(); } if (!customcreate_hasissues) { return(Json("FROMPOPUP", "application/json", System.Text.Encoding.UTF8, JsonRequestBehavior.AllowGet)); } } else { var errors = ""; foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { errors += error.ErrorMessage + ". "; } } return(Json(errors, "application/json", System.Text.Encoding.UTF8, JsonRequestBehavior.AllowGet)); } LoadViewDataAfterOnCreate(t_city); ViewBag.T_CityIsHiddenRule = checkHidden("T_City", "OnCreate", false); ViewBag.T_CityIsGroupsHiddenRule = checkHidden("T_City", "OnCreate", true); ViewBag.T_CityIsSetValueUIRule = checkSetValueUIRule("T_City", "OnCreate"); if (!string.IsNullOrEmpty(AssociatedEntity)) { LoadViewDataForCount(t_city, AssociatedEntity); } return(View(t_city)); }
public ActionResult Edit(int?id, string UrlReferrer, string HostingEntityName, string AssociatedType, string defaultview) { if (!User.CanEdit("T_City") || !CustomAuthorizationBeforeEdit(id, HostingEntityName, AssociatedType)) { return(RedirectToAction("Index", "Error")); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } T_City t_city = db.T_Citys.Find(id); // NEXT-PREVIOUS DROP DOWN CODE TempData.Keep(); string json = ""; if (TempData["T_Citylist"] == null) { json = Newtonsoft.Json.JsonConvert.SerializeObject(db.T_Citys.Select(z => new { ID = z.Id, DisplayValue = z.DisplayValue }).ToList()); } else { ViewBag.EntityT_CityDisplayValueEdit = TempData["T_Citylist"]; json = Newtonsoft.Json.JsonConvert.SerializeObject(TempData["T_Citylist"]); } Newtonsoft.Json.JsonSerializerSettings serSettings = new Newtonsoft.Json.JsonSerializerSettings(); serSettings.ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver(); var lst = Newtonsoft.Json.JsonConvert.DeserializeObject <IEnumerable <object> >(json, serSettings); ViewBag.EntityT_CityDisplayValueEdit = new SelectList(lst, "ID", "DisplayValue"); // if (t_city == null) { return(HttpNotFound()); } if (string.IsNullOrEmpty(defaultview)) { defaultview = "Edit"; } GetTemplatesForEdit(defaultview); // NEXT-PREVIOUS DROP DOWN CODE SelectList selitm = new SelectList(lst, "ID", "DisplayValue"); List <SelectListItem> newList = selitm.ToList(); if (Request.UrlReferrer != null && Request.UrlReferrer.AbsolutePath.EndsWith("/T_City/Create")) { newList.Insert(0, (new SelectListItem { Text = t_city.DisplayValue, Value = t_city.Id.ToString() })); ViewBag.EntityT_CityDisplayValueEdit = newList; TempData["T_Citylist"] = newList.Select(z => new { ID = z.Value, DisplayValue = z.Text }); } else if (!newList.Exists(p => p.Value == Convert.ToString(t_city.Id))) { if (newList.Count > 0) { newList[0].Text = t_city.DisplayValue; newList[0].Value = t_city.Id.ToString(); } else { newList.Insert(0, (new SelectListItem { Text = t_city.DisplayValue, Value = t_city.Id.ToString() })); } ViewBag.EntityT_CityDisplayValueEdit = newList; TempData["T_Citylist"] = newList.Select(z => new { ID = z.Value, DisplayValue = z.Text }); } // if (UrlReferrer != null) { ViewData["T_CityParentUrl"] = UrlReferrer; } if (ViewData["T_CityParentUrl"] == null && Request.UrlReferrer != null && !Request.UrlReferrer.AbsolutePath.EndsWith("/T_City") && !Request.UrlReferrer.AbsolutePath.EndsWith("/T_City/Edit/" + t_city.Id + "") && !Request.UrlReferrer.AbsolutePath.EndsWith("/T_City/Create")) { ViewData["T_CityParentUrl"] = Request.UrlReferrer; } ViewData["HostingEntityName"] = HostingEntityName; ViewData["AssociatedType"] = AssociatedType; LoadViewDataBeforeOnEdit(t_city); ViewBag.T_CityIsHiddenRule = checkHidden("T_City", "OnEdit", false); ViewBag.T_CityIsGroupsHiddenRule = checkHidden("T_City", "OnEdit", true); ViewBag.T_CityIsSetValueUIRule = checkSetValueUIRule("T_City", "OnEdit"); return(View(t_city)); }
public ActionResult Edit([Bind(Include = "Id,ConcurrencyKey,T_Name,T_Description,T_CityCountryID,T_CityStateID")] T_City t_city, string UrlReferrer) { string command = Request.Form["hdncommand"]; CheckBeforeSave(t_city, command); if (ModelState.IsValid) { bool customsave_hasissues = false; if (!CustomSaveOnEdit(t_city, out customsave_hasissues, command)) { db.Entry(t_city).State = EntityState.Modified; db.SaveChanges(); } if (!customsave_hasissues) { RedirectToRouteResult customRedirectAction = CustomRedirectUrl(t_city, "Edit", command); if (customRedirectAction != null) { return(customRedirectAction); } if (command != "Save") { if (command == "SaveNextPrev") { long NextPreId = Convert.ToInt64(Request.Form["hdnNextPrevId"]); return(RedirectToAction("Edit", new { Id = NextPreId, UrlReferrer = UrlReferrer })); } else { return(RedirectToAction("Edit", new { Id = t_city.Id, UrlReferrer = UrlReferrer })); } } if (!string.IsNullOrEmpty(UrlReferrer)) { var uri = new Uri(UrlReferrer); var query = HttpUtility.ParseQueryString(uri.Query); if (Convert.ToBoolean(query.Get("IsFilter")) == true) { return(RedirectToAction("Index")); } else { return(Redirect(UrlReferrer)); } } else { return(RedirectToAction("Index")); } } } // NEXT-PREVIOUS DROP DOWN CODE TempData.Keep(); string json = ""; if (TempData["T_Citylist"] == null) { json = Newtonsoft.Json.JsonConvert.SerializeObject(db.T_Citys.Select(z => new { ID = z.Id, DisplayValue = z.DisplayValue }).ToList()); } else { ViewBag.EntityT_CityDisplayValueEdit = TempData["T_Citylist"]; json = Newtonsoft.Json.JsonConvert.SerializeObject(TempData["T_Citylist"]); } Newtonsoft.Json.JsonSerializerSettings serSettings = new Newtonsoft.Json.JsonSerializerSettings(); serSettings.ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver(); var lst = Newtonsoft.Json.JsonConvert.DeserializeObject <IEnumerable <object> >(json, serSettings); ViewBag.EntityT_CityDisplayValueEdit = new SelectList(lst, "ID", "DisplayValue"); // LoadViewDataAfterOnEdit(t_city); ViewData["T_CityParentUrl"] = UrlReferrer; ViewBag.T_CityIsHiddenRule = checkHidden("T_City", "OnEdit", false); ViewBag.T_CityIsGroupsHiddenRule = checkHidden("T_City", "OnEdit", true); ViewBag.T_CityIsSetValueUIRule = checkSetValueUIRule("T_City", "OnEdit"); return(View(t_city)); }