public JsonResult GetAllData(int rows, int page) { KyLuatServices service = new KyLuatServices(); List<KyLuatEntity> kyluats = new List<KyLuatEntity>(); try { kyluats = service.GetAll(); return Json(PaginationHelper<KyLuatEntity>.Execute(kyluats, page, rows), JsonRequestBehavior.AllowGet); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } return Json(null); }
// GET: KyLuat public ActionResult Index() { KyLuatServices service = new KyLuatServices(); List<KyLuatEntity> kyluats = new List<KyLuatEntity>(); string result = null; try { kyluats = service.GetAll(); result = JsonConvert.SerializeObject(kyluats); RenderResult.RequestCompleted(ViewData, result); } catch (Exception e) { System.Console.WriteLine(e.ToString()); RenderResult.RequestError(ViewData, "Lỗi hệ thống"); } return View(); }
/// only return json to client public ActionResult Create(KyLuatEntity kyluat) { KyLuatServices service = new KyLuatServices(); if (kyluat == null) { RenderResult.RequestError(ViewData, "Lỗi đối số không hợp lệ"); return Json(JsonConvert.SerializeObject(ViewData)); } if (service.Create(kyluat)) { return Json(RenderResult.RequestCompleted(ViewData, "Thêm kỷ luật thành công")); } else { return Json(RenderResult.RequestCompleted(ViewData, "Lỗi khi thêm kỷ luật")); } }
/// only return json to client public ActionResult Edit(KyLuatEntity kyluat) { KyLuatServices service = new KyLuatServices(); if (kyluat == null) { return Json(RenderResult.RequestError(ViewData, "Lỗi đối số không hợp lệ"), JsonRequestBehavior.AllowGet); } try { if (service.Update(kyluat)) 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 GetSo() { KyLuatServices service = new KyLuatServices(); try { return Json(RenderResult.RequestCompleted(ViewData, GenKey.GenIncrementKey("KL", 3, service.GetAll().Count)), JsonRequestBehavior.AllowGet); } catch (Exception e) { System.Console.WriteLine(e.ToString()); return Json(RenderResult.RequestError(ViewData, "Lỗi xảy ra"), JsonRequestBehavior.AllowGet); } }
public ActionResult Delete(KyLuatEntity kyluat) { KyLuatServices service = new KyLuatServices(); try { if (service.Delete(kyluat)) 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")); } }
public ActionResult DeleteWithID(string id) { KyLuatServices service = new KyLuatServices(); 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")); } }