public bool Delete(ChucVuEntity chucVuEntity)
 {
     try
     {
         this.m_UnitOfWork.ChucVuRepository.Delete(chucVuEntity);
         return true;
     }
     catch (Exception e)
     {
         System.Console.WriteLine(e.ToString());
         return false;
     }
 }
 public bool Create(ChucVuEntity chucVuEntity)
 {
     using (var scope = new TransactionScope())
     {
         var chucVu = new ChucVus
         {
             Id = chucVuEntity.Id,
             MaQuyDinh = chucVuEntity.MaQuyDinh,
             BTV_BTK = chucVuEntity.BTV_BTK,
             LoaiCoSo_ChucVu = chucVuEntity.LoaiCoSo_ChucVu,
             TenChucVu = chucVuEntity.TenChucVu,
             ThuongTruc = chucVuEntity.ThuongTruc
         };
         m_UnitOfWork.ChucVuRepository.Insert(chucVu);
         m_UnitOfWork.Save();
         scope.Complete();
         return true;
     }
 }
        /// only return json to client
        public ActionResult Create(ChucVuEntity chucVuEntity)
        {
            ChucVuServices service = new ChucVuServices();

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

            if (service.Create(chucVuEntity))
            {
                return Json(RenderResult.RequestCompleted(ViewData, "Thêm chức vụ thành công"));
            }
            else
            {

                return Json(RenderResult.RequestCompleted(ViewData, "Lỗi khi thêm chức vụ"));
            }
        }
        public ActionResult Edit(ChucVuEntity chucVuEntity)
        {
            ChucVuServices service = new ChucVuServices();

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

            try
            {
                if (service.Update(chucVuEntity))
                    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 bool Update(ChucVuEntity chucVuEntity)
        {
            var success = false;
            if (chucVuEntity != null)
            {
                using (var scope = new TransactionScope())
                {
                    var chucVu = m_UnitOfWork.ChucVuRepository.GetByID(chucVuEntity.Id);
                    if (chucVu != null)
                    {
                        chucVu.Id = chucVuEntity.Id;
                        chucVu.MaQuyDinh = chucVuEntity.MaQuyDinh;
                        chucVu.BTV_BTK = chucVuEntity.BTV_BTK;
                        chucVu.LoaiCoSo_ChucVu = chucVuEntity.LoaiCoSo_ChucVu;
                        chucVu.TenChucVu = chucVuEntity.TenChucVu;
                        chucVu.ThuongTruc = chucVuEntity.ThuongTruc;

                        m_UnitOfWork.ChucVuRepository.Update(chucVu);
                        m_UnitOfWork.Save();
                        scope.Complete();
                        success = true;
                    }
                }
            }
            return success;
        }
        public List<ChucVuEntity> GetAll()
        {
            IEnumerable<ChucVus> model = this.m_UnitOfWork.ChucVuRepository.GetAll();
            List<ChucVuEntity> result = new List<ChucVuEntity>();

            foreach (var item in model)
            {
                ChucVuEntity chucVu = new ChucVuEntity
                {
                    Id = item.Id,
                    MaQuyDinh = item.MaQuyDinh,
                    BTV_BTK = item.BTV_BTK,
                    LoaiCoSo_ChucVu = item.LoaiCoSo_ChucVu,
                    TenChucVu = item.TenChucVu,
                    ThuongTruc = item.ThuongTruc
                };
                result.Add(chucVu);
            }

            return result;
        }
        public ActionResult Delete(ChucVuEntity chucVuEntity)
        {
            ChucVuServices service = new ChucVuServices();

            try
            {
                if (service.Delete(chucVuEntity))
                    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"));
            }

        }