public JsonResult GetAllData(int rows, int page)
        {
            NgachCongChucServices service = new NgachCongChucServices();
            List<NgachCongChucEntity> ngachCongChucs = new List<NgachCongChucEntity>();

            try
            {
                ngachCongChucs = service.GetAll();
                return Json(PaginationHelper<NgachCongChucEntity>.Execute(ngachCongChucs, page, rows), JsonRequestBehavior.AllowGet);
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.ToString());
            }

            return Json(null);
        }
        // GET: NgachCongChuc
        public ActionResult Index()
        {
            NgachCongChucServices service = new NgachCongChucServices();
            List<NgachCongChucEntity> ngachCongChucs = new List<NgachCongChucEntity>();
            string result = null;

            try
            {
                ngachCongChucs = service.GetAll();
                result = JsonConvert.SerializeObject(ngachCongChucs);
                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(NgachCongChucEntity ngachCongChuc)
        {
            NgachCongChucServices service = new NgachCongChucServices();

            if (ngachCongChuc == null)
            {
                RenderResult.RequestError(ViewData, "Lỗi đối số không hợp lệ");
                return Json(JsonConvert.SerializeObject(ViewData));
            }

            if (service.Create(ngachCongChuc))
            {
                return Json(RenderResult.RequestCompleted(ViewData, "Thêm đơn vị thành công"));
            }
            else
            {

                return Json(RenderResult.RequestCompleted(ViewData, "Lỗi khi thêm đơn vị"));
            }
        }
        /// only return json to client
        public ActionResult Edit(NgachCongChucEntity ngachCongChuc)
        {
            NgachCongChucServices service = new NgachCongChucServices();

            if (ngachCongChuc == null)
            {
                return Json(RenderResult.RequestError(ViewData, "Lỗi đối số không hợp lệ"), JsonRequestBehavior.AllowGet);
            }
            
            try
            {
                if (service.Update(ngachCongChuc))
                    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 GetAllDataWithoutPagination()
        {
            NgachCongChucServices service = new NgachCongChucServices();
            List<NgachCongChucEntity> entities = new List<NgachCongChucEntity>();
            string result = null;
            try
            {
                entities = service.GetAll();
                result = JsonConvert.SerializeObject(entities);
                return Json(RenderResult.RequestCompleted(ViewData, result), JsonRequestBehavior.AllowGet);
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.ToString());
            }

            return Json(null);
        }
        public JsonResult GetMaQuyDinh()
        {
            NgachCongChucServices service = new NgachCongChucServices();

            try
            {
                return Json(RenderResult.RequestCompleted(ViewData, GenKey.GenIncrementKey("NCC", 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(NgachCongChucEntity ngachCongChuc)
        {
            NgachCongChucServices service = new NgachCongChucServices();

            try
            {
                if (service.Delete(ngachCongChuc))
                    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)
        {
            NgachCongChucServices service = new NgachCongChucServices();

            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"));
            }

        }