public JsonResult GetAllData(int rows, int page)
        {
            LoaiCoSoService service = new LoaiCoSoService();
            List<LoaiCoSoEntity> loaicosos= new List<LoaiCoSoEntity>();

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

            return Json(null);
        }
        /// only return json to client
        public ActionResult Create(LoaiCoSoEntity loaicoso)
        {
            LoaiCoSoService service = new LoaiCoSoService();

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

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

                return Json(RenderResult.RequestCompleted(ViewData, "Lỗi khi thêm loại cơ sở"));
            }
        }
        // GET: LoaiCoSo
        public ActionResult Index()
        {
            LoaiCoSoService service = new LoaiCoSoService();
            List<LoaiCoSoEntity> loaicosos= new List<LoaiCoSoEntity>();
            string result = null;

            try
            {
                loaicosos= service.GetAll();
                result = JsonConvert.SerializeObject(loaicosos);
                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(LoaiCoSoEntity loaicoso)
        {
            LoaiCoSoService service = new LoaiCoSoService();

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

            try
            {
                if (service.Update(loaicoso))
                    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 string GetAllLoaiCoSoChucVu()
 {
     string result = "<select>";
     LoaiCoSoService lcsService = new LoaiCoSoService();
     List<LoaiCoSoEntity> listTT = lcsService.GetAll();
     int ttSize = listTT.Count;
     for (int i = 0; i < ttSize; i++)
     {
         result += "<option value =\'" + listTT[i].Id.ToString() + "\'>" + listTT[i].TenLoai + "</option>\n";
     }
     result += "</select>";
     return result;
 }
 public JsonResult GetAllIdLoaiCoSo()
 {
     string result = null;
     LoaiCoSoService service = new LoaiCoSoService();
     List<LoaiCoSoEntity> lcsEntity = new List<LoaiCoSoEntity>();
     try
     {
         lcsEntity = service.GetAll();
         result = JsonConvert.SerializeObject(lcsEntity);
         return Json(lcsEntity, JsonRequestBehavior.AllowGet);
     }
     catch (Exception e)
     {
         System.Console.WriteLine(e.ToString());
         return Json(null);
     }
 }
        public JsonResult GetMaQuyDinh()
        {
            LoaiCoSoService service = new LoaiCoSoService();

            try
            {
                return Json(RenderResult.RequestCompleted(ViewData, GenKey.GenIncrementKey("LCS", 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(LoaiCoSoEntity loaicoso)
        {
            LoaiCoSoService service = new LoaiCoSoService();

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

            if (id == null)
                return Json(RenderResult.RequestError(ViewData, "Đối số không hợp lệ"));

            

            try
            {
                List<int> ids = StringUtility.SplitIdEntity(id);

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

        }