public bool Delete(CoSoEntity coSoEntity)
 {
     try
     {
         this.m_UnitOfWork.CoSoRepository.Delete(coSoEntity);
         return true;
     }
     catch (Exception e)
     {
         System.Console.WriteLine(e.ToString());
         return false;
     }
 }
        /// 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ở"));
            }
        }
        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 bool Create(CoSoEntity coSoEntity)
        {
            using (var scope = new TransactionScope())
            {
                try {
                    var coSo = new CoSos
                    {
                        Id = coSoEntity.Id,
                        Website = coSoEntity.Website,
                        CoSo_CoSo = coSoEntity.CoSo_CoSo,
                        CoSo_LoaiCoSo = coSoEntity.CoSo_LoaiCoSo,
                        DonVi_CoSo = coSoEntity.DonVi_CoSo,
                        Email = coSoEntity.Email,
                        MaQuyDinh = coSoEntity.MaQuyDinh,
                        SoDT = coSoEntity.SoDT,
                        SoLuongDangVien = coSoEntity.SoLuongDangVien,
                        SoLuongDangVienDuBi = coSoEntity.SoLuongDangVien,
                        SoLuongDoanVienCoSo = coSoEntity.SoLuongDoanVienCoSo,
                        SoLuongDoanVienUuTu = coSoEntity.SoLuongDoanVienUuTu,
                        SoLuongDoiTuongDang = coSoEntity.SoLuongDoiTuongDang,
                        ThanhTich = coSoEntity.ThanhTich,
                        TenCoSo = coSoEntity.TenCoSo
                    };

                    m_UnitOfWork.CoSoRepository.Insert(coSo);
                    m_UnitOfWork.Save();
                }
                catch (Exception e)
                {
                    System.Console.WriteLine(e.ToString());
                    return false;
                }
                scope.Complete();
                return true;
            }
        }
        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 List<CoSoEntity> GetAll()
        {
            IEnumerable<CoSos> model = this.m_UnitOfWork.CoSoRepository.GetAll();
            List<CoSoEntity> result = new List<CoSoEntity>();

            foreach (var coSoEntity in model)
            {
                CoSoEntity coSo = new CoSoEntity
                {
                    Id = coSoEntity.Id,
                    Website = coSoEntity.Website,
                    CoSo_CoSo = coSoEntity.CoSo_CoSo,
                    CoSo_LoaiCoSo = coSoEntity.CoSo_LoaiCoSo,
                    DonVi_CoSo = coSoEntity.DonVi_CoSo,
                    Email = coSoEntity.Email,
                    MaQuyDinh = coSoEntity.MaQuyDinh,
                    SoDT = coSoEntity.SoDT,
                    SoLuongDangVien = coSoEntity.SoLuongDangVien,
                    SoLuongDangVienDuBi = coSoEntity.SoLuongDangVien,
                    SoLuongDoanVienCoSo = coSoEntity.SoLuongDoanVienCoSo,
                    SoLuongDoanVienUuTu = coSoEntity.SoLuongDoanVienUuTu,
                    SoLuongDoiTuongDang = coSoEntity.SoLuongDoiTuongDang,
                    ThanhTich = coSoEntity.ThanhTich,
                    TenCoSo = coSoEntity.TenCoSo
                };
                result.Add(coSo);
            }

            return result;
        }
        public bool Update(CoSoEntity coSoEntity)
        {
            var success = false;
            if (coSoEntity != null)
            {
                using (var scope = new TransactionScope())
                {
                    var coSo = m_UnitOfWork.CoSoRepository.GetByID(coSoEntity.Id);
                    if (coSo != null)
                    {
                        coSo.Id = coSoEntity.Id;
                        coSo.Website = coSoEntity.Website;
                        coSo.CoSo_CoSo = coSoEntity.CoSo_CoSo;
                        coSo.CoSo_LoaiCoSo = coSoEntity.CoSo_LoaiCoSo;
                        coSo.DonVi_CoSo = coSoEntity.DonVi_CoSo;
                        coSo.Email = coSoEntity.Email;
                        coSo.MaQuyDinh = coSoEntity.MaQuyDinh;
                        coSo.SoDT = coSoEntity.SoDT;
                        coSo.SoLuongDangVien = coSoEntity.SoLuongDangVien;
                        coSo.SoLuongDangVienDuBi = coSoEntity.SoLuongDangVien;
                        coSo.SoLuongDoanVienCoSo = coSoEntity.SoLuongDoanVienCoSo;
                        coSo.SoLuongDoanVienUuTu = coSoEntity.SoLuongDoanVienUuTu;
                        coSo.SoLuongDoiTuongDang = coSoEntity.SoLuongDoiTuongDang;
                        coSo.ThanhTich = coSoEntity.ThanhTich;
                        coSo.TenCoSo = coSoEntity.TenCoSo;

                        m_UnitOfWork.CoSoRepository.Update(coSo);
                        m_UnitOfWork.Save();
                        scope.Complete();
                        success = true;
                    }
                }
            }
            return success;
        }