public ActionResult DeleteTown(long CITY_CD = 0, long DISTRICT_CD = 0, long TOWN_CD = 0) { if (Request.IsAjaxRequest()) { if (ModelState.IsValid && CITY_CD > 0 && DISTRICT_CD > 0 && TOWN_CD > 0) { using (var service = new ManageTownService()) { var deleteResult = service.DeleteTown(CITY_CD, DISTRICT_CD, TOWN_CD); JsonResult result = Json(new { statusCode = deleteResult ? Constant.SUCCESSFUL : Constant.INTERNAL_SERVER_ERROR }, JsonRequestBehavior.AllowGet); return(result); } } else { var errors = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => new { x.Key, x.Value.Errors }).ToArray(); } } return(new EmptyResult()); }
public ActionResult List(DataTableModel dt, TownModel condition) { if (ModelState.IsValid) { using (ManageTownService service = new ManageTownService()) { int total_row = 0; var dataList = service.SearchTownList(dt, condition, out total_row); int order = 1; int totalRowCount = dataList.Count(); int lastItem = dt.iDisplayLength + dt.iDisplayStart; var result = Json( new { sEcho = dt.sEcho, iTotalRecords = total_row, iTotalDisplayRecords = total_row, aaData = (from i in dataList select new object[] { i.CITY_CD, i.DISTRICT_CD, order++, i.CITY_NAME != null ? HttpUtility.HtmlEncode(i.CITY_NAME) : String.Empty, i.DISTRICT_NAME != null ? HttpUtility.HtmlEncode(i.DISTRICT_NAME) : String.Empty, i.TOWN_CD, i.TOWN_NAME != null ? HttpUtility.HtmlEncode(i.TOWN_NAME) : String.Empty, i.STATUS == "1"? "Hiển thị" : "Ẩn", i.DEL_FLG }) }); result.MaxJsonLength = Int32.MaxValue; return(result); } } else { var ErrorMessages = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => new { x.Key, x.Value.Errors }).ToArray(); } return(new EmptyResult()); }
public ActionResult Edit(TownModel model) { try { using (ManageTownService service = new ManageTownService()) { if (ModelState.IsValid) { bool isNew = false; if (model.CITY_CD_HIDDEN == 0 && model.DISTRICT_CD_HIDDEN == 0 && model.TOWN_CD_HIDDEN == 0) { isNew = true; service.InsertTown(model); JsonResult result = Json(new { isNew = isNew }, JsonRequestBehavior.AllowGet); return(result); } else { isNew = false; service.UpdateTown(model); JsonResult result = Json(new { isNew = isNew }, JsonRequestBehavior.AllowGet); return(result); } } else { var ErrorMessages = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => new { x.Key, x.Value.Errors }).ToArray(); } return(new EmptyResult()); } } catch (Exception ex) { Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest; System.Web.HttpContext.Current.Session["ERROR"] = ex; return(new EmptyResult()); } }