public async Task <int> PhoPhongDuyet_Chuyen(LuuPhoPhongDuyet99InputDto input)
        {
            try
            {
                if (input.HoSoXuLyId > 0)
                {
                    var hosoxl = await _hoSoXuLyRepos.FirstOrDefaultAsync(input.HoSoXuLyId);

                    if (hosoxl != null && _session.UserId == hosoxl.PhoPhongId)
                    {
                        #region Lưu lịch sử
                        var _history = new XHoSoXuLyHistory();

                        if (hosoxl.HoSoXuLyHistoryId_Active.HasValue)
                        {
                            _history = _hoSoXuLyHistoryRepos.Get(hosoxl.HoSoXuLyHistoryId_Active.Value);
                        }

                        _history.ThuTucId      = hosoxl.ThuTucId;
                        _history.HoSoXuLyId    = hosoxl.Id;
                        _history.HoSoId        = hosoxl.HoSoId;
                        _history.ThuTucId      = hosoxl.ThuTucId;
                        _history.IsHoSoBS      = hosoxl.IsHoSoBS;
                        _history.DonViXuLy     = (int)CommonENum.DON_VI_XU_LY.PHO_PHONG;
                        _history.ActionEnum    = (int)CommonENum.FORM_FUNCTION.PHO_PHONG_DUYET;
                        _history.NoiDungYKien  = input.NoiDungYKien;
                        _history.DonViKeTiep   = input.DonViKeTiep;
                        _history.NguoiXuLyId   = _session.UserId;
                        _history.HoSoIsDat_Pre = hosoxl.HoSoIsDat;
                        _history.HoSoIsDat     = input.HoSoIsDat;
                        _history.TrangThaiCV   = input.TrangThaiCV;
                        _history.IsSuaCV       = input.IsSuaCV;
                        if (input.HoSoIsDat != true && input.IsSuaCV.HasValue && input.IsSuaCV.Value)
                        {
                            _history.NoiDungCV = input.NoiDungCV;
                        }
                        else
                        {
                            _history.NoiDungCV = null;
                        }

                        var _historyId = await _hoSoXuLyHistoryRepos.InsertOrUpdateAndGetIdAsync(_history);

                        hosoxl.HoSoXuLyHistoryId_Active = _historyId;
                        #endregion

                        if (input.HoSoIsDat != true && input.IsSuaCV.HasValue && input.IsSuaCV.Value)
                        {
                            hosoxl.NoiDungCV = input.NoiDungCV;
                        }
                        hosoxl.DonViKeTiep = input.DonViKeTiep;
                        hosoxl.TrangThaiCV = input.TrangThaiCV;

                        if (hosoxl.DonViKeTiep == (int)CommonENum.DON_VI_XU_LY.TRUONG_PHONG)
                        {
                            hosoxl.DonViXuLy   = (int)CommonENum.DON_VI_XU_LY.TRUONG_PHONG;
                            hosoxl.DonViGui    = (int)CommonENum.DON_VI_XU_LY.PHO_PHONG;
                            hosoxl.NguoiXuLyId = hosoxl.TruongPhongId;
                        }
                        else if (hosoxl.DonViKeTiep == (int)CommonENum.DON_VI_XU_LY.CHUYEN_VIEN_THAM_XET_TONG_HOP)
                        {
                            hosoxl.DonViXuLy   = (int)CommonENum.DON_VI_XU_LY.CHUYEN_VIEN_THAM_XET_TONG_HOP;
                            hosoxl.DonViGui    = (int)CommonENum.DON_VI_XU_LY.PHO_PHONG;
                            hosoxl.NguoiXuLyId = hosoxl.ChuyenVienThuLyId;
                        }
                        hosoxl.HoSoXuLyHistoryId_Active = null;
                        hosoxl.NguoiGuiId        = _session.UserId;
                        hosoxl.YKienGui          = _history.NoiDungYKien;
                        hosoxl.PhoPhongDaDuyet   = true;
                        hosoxl.PhoPhongNgayDuyet = DateTime.Now;

                        hosoxl.YKienChung = input.YKienChung;

                        //Lưu hồ sơ
                        hosoxl.NgayGui = DateTime.Now;

                        await _hoSoXuLyRepos.UpdateAsync(hosoxl);
                    }
                }

                return(1);
            }
            catch (Exception ex)
            {
                Logger.Fatal(ex.Message);
                return(0);
            }
        }
        public async Task <int> PhoPhongDuyet_Luu(LuuPhoPhongDuyet99InputDto input)
        {
            try
            {
                if (input.HoSoXuLyId > 0)
                {
                    var hosoxl = await _hoSoXuLyRepos.FirstOrDefaultAsync(input.HoSoXuLyId);

                    if (hosoxl != null && _session.UserId == hosoxl.PhoPhongId)
                    {
                        #region Lưu lịch sử
                        var _history = new XHoSoXuLyHistory();

                        if (hosoxl.HoSoXuLyHistoryId_Active.HasValue)
                        {
                            _history = _hoSoXuLyHistoryRepos.Get(hosoxl.HoSoXuLyHistoryId_Active.Value);
                        }

                        _history.ThuTucId      = hosoxl.ThuTucId;
                        _history.HoSoXuLyId    = hosoxl.Id;
                        _history.HoSoId        = hosoxl.HoSoId;
                        _history.ThuTucId      = hosoxl.ThuTucId;
                        _history.IsHoSoBS      = hosoxl.IsHoSoBS;
                        _history.DonViXuLy     = (int)CommonENum.DON_VI_XU_LY.PHO_PHONG;
                        _history.NoiDungYKien  = input.NoiDungYKien;
                        _history.DonViKeTiep   = input.DonViKeTiep;
                        _history.NguoiXuLyId   = _session.UserId;
                        _history.HoSoIsDat_Pre = hosoxl.HoSoIsDat;
                        _history.HoSoIsDat     = input.HoSoIsDat;
                        _history.TrangThaiCV   = input.TrangThaiCV;
                        _history.IsSuaCV       = input.IsSuaCV;
                        if (input.HoSoIsDat != true && input.IsSuaCV.HasValue && input.IsSuaCV.Value)
                        {
                            _history.NoiDungCV = input.NoiDungCV;
                        }
                        else
                        {
                            _history.NoiDungCV = null;
                        }

                        var _historyId = await _hoSoXuLyHistoryRepos.InsertOrUpdateAndGetIdAsync(_history);

                        hosoxl.HoSoXuLyHistoryId_Active = _historyId;
                        #endregion

                        if (input.HoSoIsDat != true && input.IsSuaCV.HasValue && input.IsSuaCV.Value)
                        {
                            hosoxl.NoiDungCV = input.NoiDungCV;
                        }

                        hosoxl.HoSoIsDat  = input.HoSoIsDat;
                        hosoxl.YKienChung = input.YKienChung;

                        await _hoSoXuLyRepos.UpdateAsync(hosoxl);
                    }
                }

                return(1);
            }
            catch (Exception ex)
            {
                Logger.Fatal(ex.Message);
                return(0);
            }
        }