public JsonResult GetAllData(int rows, int page)
        {
            CoSoServices service = new CoSoServices();
            List<CoSoEntity> listCoso = new List<CoSoEntity>();

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

            return Json(null);
        }
        /// only return json to client
        public ActionResult Create(CoSoEntity coSoEntity)
        {
            CoSoServices service = new CoSoServices();

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

            if (service.Create(coSoEntity))
            {
                return Json(RenderResult.RequestCompleted(ViewData, "Thêm cơ sở thành công"));
            }
            else
            {

                return Json(RenderResult.RequestCompleted(ViewData, "Lỗi khi thêm cơ sở"));
            }
        }
        // GET: CoSo
        public ActionResult Index()
        {

            CoSoServices service = new CoSoServices();
            List<CoSoEntity> listCoSo = new List<CoSoEntity>();
            string result = null;

            try
            {
                listCoSo = service.GetAll();
                result = JsonConvert.SerializeObject(listCoSo);
                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(CoSoEntity coSoEntity)
        {
            CoSoServices service = new CoSoServices();

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

            try
            {
                if (service.Update(coSoEntity))
                    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 GetAllIdCoSo()
 {
     string result = null;
     CoSoServices service = new CoSoServices();
     List<CoSoEntity> csEntity = new List<CoSoEntity>();
     try
     {
         csEntity = service.GetAll();
         result = JsonConvert.SerializeObject(csEntity);
         return Json(csEntity, JsonRequestBehavior.AllowGet);
     }
     catch (Exception e)
     {
         System.Console.WriteLine(e.ToString());
         return Json(null);
     }
 }
        public JsonResult GetMaQuyDinh()
        {
            CoSoServices service = new CoSoServices();

            try
            {
                return Json(RenderResult.RequestCompleted(ViewData, GenKey.GenIncrementKey("CS", 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(CoSoEntity coSoEntity)
        {
            CoSoServices service = new CoSoServices();

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

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

        }