public ActionResult Delete(ThongTin2CEntity entity) { ThongTin2CServices service = new ThongTin2CServices(); try { if (service.Delete(entity)) return Json(RenderResult.RequestCompleted(ViewData, "Xóa thành công")); return Json(RenderResult.RequestCompleted(ViewData, "Xóa không thành công")); } catch (Exception e) { System.Console.WriteLine(e.ToString()); return Json(RenderResult.RequestError(ViewData, "Lỗi xảy ra")); } }
/// only return json to client public ActionResult Create(ThongTin2CEntity entity) { ThongTin2CServices service = new ThongTin2CServices(); if (entity == null) { RenderResult.RequestError(ViewData, "Lỗi đối số không hợp lệ"); return Json(JsonConvert.SerializeObject(ViewData)); } if (service.Create(entity)) { return Json(RenderResult.RequestCompleted(ViewData, "Thêm thông tin 2c thành công")); } else { return Json(RenderResult.RequestCompleted(ViewData, "Lỗi khi thêm thông tin 2c")); } }
// GET: ThongTin2C public ActionResult Index() { ThongTin2CServices service = new ThongTin2CServices(); List<ThongTin2CEntity> entities = new List<ThongTin2CEntity>(); string result = null; try { entities = service.GetAll(); result = JsonConvert.SerializeObject(entities); RenderResult.RequestCompleted(ViewData, result); } catch (Exception e) { System.Console.WriteLine(e.ToString()); RenderResult.RequestError(ViewData, "Lỗi hệ thống"); } return View(); }
public ActionResult DeleteWithID(string id) { ThongTin2CServices service = new ThongTin2CServices(); if (id == null) return Json(RenderResult.RequestError(ViewData, "Đối số không hợp lệ")); List<int> ids = StringUtility.SplitIdEntity(id); try { for (int i = 0; i < ids.Count; ++i) { service.Delete(ids[i]); } return Json(RenderResult.RequestCompleted(ViewData, "Xóa thành công")); } catch (Exception e) { System.Console.WriteLine(e.ToString()); return Json(RenderResult.RequestError(ViewData, "Lỗi xảy ra")); } }
public JsonResult GetAllDataWithId(int Id) { ThongTin2CServices service = new ThongTin2CServices(); ThongTin2CEntity entity = null; string result = null; try { entity = service.GetWithId(Id); if (entity == null) { result = "Không có kết quả"; return Json(RenderResult.RequestCompleted(ViewData, "Không có kết quả"), JsonRequestBehavior.AllowGet); } result = JsonConvert.SerializeObject(entity); return Json(RenderResult.RequestCompleted(ViewData, result), JsonRequestBehavior.AllowGet); } catch (Exception e) { System.Console.WriteLine(e.ToString()); return Json(RenderResult.RequestCompleted(ViewData, "Lỗi xảy ra"), JsonRequestBehavior.AllowGet); } }
public JsonResult GetAllData(int rows, int page) { ThongTin2CServices service = new ThongTin2CServices(); List<ThongTin2CEntity> entities = new List<ThongTin2CEntity>(); try { entities = service.GetAll(); return Json(PaginationHelper<ThongTin2CEntity>.Execute(entities, page, rows), JsonRequestBehavior.AllowGet); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } return Json(null); }
public ActionResult Edit(ThongTin2CEntity entity) { ThongTin2CServices service = new ThongTin2CServices(); if (entity == null) { return Json(RenderResult.RequestError(ViewData, "Lỗi đối số không hợp lệ"), JsonRequestBehavior.AllowGet); } try { if (service.Update(entity)) return Json(RenderResult.RequestCompleted(ViewData, "Chỉnh sửa thành công")); return Json(RenderResult.RequestCompleted(ViewData, "Chỉnh sửa không thành công")); } catch (Exception e) { System.Console.WriteLine(e.ToString()); return Json(RenderResult.RequestError(ViewData, "Lỗi xảy ra")); } }
public JsonResult GetAllIdThongTin() { string result = null; ThongTin2CServices service = new ThongTin2CServices(); List<ThongTin2CEntity> ttServices = new List<ThongTin2CEntity>(); try { ttServices = service.GetAll(); result = JsonConvert.SerializeObject(ttServices); return Json(ttServices, JsonRequestBehavior.AllowGet); } catch (Exception e) { System.Console.WriteLine(e.ToString()); return Json(null); } }