public JsonResult GetAllData(int rows, int page) { ChuyenMonService service = new ChuyenMonService(); List<ChuyenMonEntity> chuyenmons= new List<ChuyenMonEntity>(); try { chuyenmons= service.GetAll(); return Json(PaginationHelper<ChuyenMonEntity>.Execute(chuyenmons, page, rows), JsonRequestBehavior.AllowGet); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } return Json(null); }
/// only return json to client public ActionResult Create(ChuyenMonEntity chuyenmon) { ChuyenMonService service = new ChuyenMonService(); if (chuyenmon == null) { RenderResult.RequestError(ViewData, "Lỗi đối số không hợp lệ"); return Json(JsonConvert.SerializeObject(ViewData)); } if (service.Create(chuyenmon)) { return Json(RenderResult.RequestCompleted(ViewData, "Thêm chuyên môn thành công")); } else { return Json(RenderResult.RequestCompleted(ViewData, "Lỗi khi thêm chuyên môn")); } }
// GET: ChuyenMon public ActionResult Index() { ChuyenMonService service = new ChuyenMonService(); List<ChuyenMonEntity> chuyenmons= new List<ChuyenMonEntity>(); string result = null; try { chuyenmons= service.GetAll(); result = JsonConvert.SerializeObject(chuyenmons); RenderResult.RequestCompleted(ViewData, result); } catch (Exception e) { System.Console.WriteLine(e.ToString()); RenderResult.RequestError(ViewData, "Lỗi hệ thống"); } return View(); }
public ActionResult Edit(ChuyenMonEntity chuyenmon) { ChuyenMonService service = new ChuyenMonService(); if (chuyenmon == null) { return Json(RenderResult.RequestError(ViewData, "Lỗi đối số không hợp lệ"), JsonRequestBehavior.AllowGet); } try { if (service.Update(chuyenmon)) 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 GetMaQuyDinh() { ChuyenMonService service = new ChuyenMonService(); try { return Json(RenderResult.RequestCompleted(ViewData, GenKey.GenIncrementKey("CM", 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(ChuyenMonEntity chuyenmon) { ChuyenMonService service = new ChuyenMonService(); try { if (service.Delete(chuyenmon)) 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) { ChuyenMonService service = new ChuyenMonService(); 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")); } }