public void NUnit_Contract_Domain_Edit()
        {
            Cat_OrgStructureServices service = new Cat_OrgStructureServices();
            var model = new Cat_OrgStructure
            {
                Id = 5,
                OrgStructureName = "Update Phòng Ban ",
                Code             = "Update Mã ",
                IsRoot           = true,
                Description      = "Update Mô Tả ",
                TypeID           = 1,
                ParentID         = 1,
                OrderNumber      = 321
            };
            bool result = service.UpdateCatOrgStructure(model);

            NUnit.Framework.Assert.IsTrue(result);
            if (result == true)
            {
                Console.WriteLine("Process Success >>> Update >>> " + model.Id
                                  + " | " + model.OrgStructureName
                                  + " | " + model.Code
                                  + " | " + model.IsRoot
                                  + " | " + model.Description
                                  + " | " + model.TypeID
                                  + " | " + model.ParentID
                                  + " | " + model.OrderNumber
                                  );
            }
        }
Beispiel #2
0
        public Hre_WorkHistoryModel Post([Bind] Hre_WorkHistoryModel model)
        {
            #region Validate
            BaseService BaseService   = new BaseService();
            string      status        = string.Empty;
            string      message       = string.Empty;
            var         checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData <Hre_WorkHistoryModel>(model, "Hre_WorkHistory", ref message);
            if (!checkValidate)
            {
                model.ActionStatus = message;
                return(model);
            }
            #endregion
            var WorkHistoryServices  = new Hre_WorkHistoryServices();
            var SalaryClassServices  = new Cat_SalaryClassServices();
            var OrgStructureServices = new Cat_OrgStructureServices();
            var JobTitleServices     = new Cat_JobTitleServices();
            var PositionServices     = new Cat_PositionServices();
            var WorkHistoryOld       = BaseService.GetData <Hre_WorkHistoryEntity>(Common.DotNetToOracle(model.ProfileID.ToString()), ConstantSql.hrm_hr_sp_get_WorkHistoryByProfileId, UserLogin, ref status).OrderByDescending(s => s.DateEffective).FirstOrDefault();
            if (WorkHistoryOld != null)
            {
                model.SalaryClassNameOld = WorkHistoryOld.SalaryClassName;
                model.JobTitleOld        = WorkHistoryOld.JobTitleName;
                model.PositionOld        = WorkHistoryOld.PositionName;
                model.OrgStructureOldID  = WorkHistoryOld.OrganizationStructureID;
                model.WorkLocationOld    = WorkHistoryOld.WorkLocation;
            }

            if (model.SalaryClassID != null)
            {
                var abilityTitleBySalaryClass = BaseService.GetData <Cat_AbilityTileEntity>(Common.DotNetToOracle(model.SalaryClassID.ToString()), ConstantSql.hrm_cat_sp_get_AbilityTileBySalaryClassId, UserLogin, ref status).FirstOrDefault();
                if (abilityTitleBySalaryClass != null)
                {
                    model.AbilityTileID = abilityTitleBySalaryClass.ID;
                }
            }
            // Son.Vo - 20140107 - Xử lý cập nhật ngược lại bảng profile
            if (model.Status == WorkHistoryStatus.E_APPROVED.ToString() && model.DateEffective != null && model.DateEffective <= DateTime.Now.Date)
            {
                Hre_ProfileServices profileServices = new Hre_ProfileServices();
                Hre_ProfileEntity   profile         = BaseService.GetData <Hre_ProfileEntity>(Common.DotNetToOracle(model.ProfileID.ToString()), ConstantSql.hrm_hr_sp_get_ProfileById, UserLogin, ref status).FirstOrDefault();
                if (profile != null)
                {
                    profile.OrgStructureID = model.OrganizationStructureID;
                    profile.JobTitleID     = model.JobTitleID;
                    profile.PositionID     = model.PositionID;
                    profile.DateOfEffect   = model.DateEffective;
                    profile.LaborType      = model.LaborType;
                    profile.CostCentreID   = model.CostCentreID;
                    profile.FormType       = model.FormType;
                    profile.EmpTypeID      = model.EmployeeTypeID;
                    profile.WorkingPlace   = model.WorkLocation;
                    profile.AbilityTileID  = model.AbilityTileID;
                    profileServices.Edit(profile);
                }
            }

            ActionService service = new ActionService(UserLogin);
            return(service.UpdateOrCreate <Hre_WorkHistoryEntity, Hre_WorkHistoryModel>(model));
        }
Beispiel #3
0
        public CatOrgStructureModel Post([Bind] CatOrgStructureModel model)
        {
            #region Validate
            string message       = string.Empty;
            var    checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData <CatOrgStructureModel>(model, "Cat_OrgStructure", ref message);
            if (!checkValidate)
            {
                model.ActionStatus = message;
                return(model);
            }
            #endregion
            ActionService service = new ActionService(UserLogin);
            //Xóa cache lưu lại của cây phòng ban
            HttpContext.Current.Cache.Remove("List_OrgStructureTreeView");
            HttpContext.Current.Cache.Remove("List_OrgStructureTreeViewSumProfile");

            #region Get max Order Number of Orgstructure
            if (model != null && model.ID == Guid.Empty)
            {
                Cat_OrgStructureServices orgService = new Cat_OrgStructureServices();
                model.OrderNumber = orgService.GetMaxOrgstructureOrder();
            }
            #endregion

            return(service.UpdateOrCreate <Cat_OrgStructureEntity, CatOrgStructureModel>(model));
        }
        public void NUnit_Contract_Domain_Get()
        {
            Cat_OrgStructureServices      service = new Cat_OrgStructureServices();
            IQueryable <Cat_OrgStructure> repo    = service.GetCatOrgStructure();

            Console.Write("Total Record: " + repo.Count());
        }
Beispiel #5
0
        public Hre_DisciplineModel Post([Bind] Hre_DisciplineModel model)
        {
            #region Validate

            string message       = string.Empty;
            var    checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData <Hre_DisciplineModel>(model, "Hre_Discipline", ref message);
            if (!checkValidate)
            {
                model.ActionStatus = message;
                return(model);
            }

            #endregion

            #region cột DepartmentName = phòng ban hiện tại của NV
            string status          = string.Empty;
            var    orgServices     = new Cat_OrgStructureServices();
            var    profileServices = new Hre_ProfileServices();
            var    lstObjOrg       = new List <object>();
            lstObjOrg.Add(null);
            lstObjOrg.Add(null);
            lstObjOrg.Add(null);
            lstObjOrg.Add(1);
            lstObjOrg.Add(int.MaxValue - 1);
            var lstOrg = orgServices.GetData <Cat_OrgStructureEntity>(lstObjOrg, ConstantSql.hrm_cat_sp_get_OrgStructure, UserLogin, ref status).ToList();

            var orgTypeService = new Cat_OrgStructureTypeServices();
            var lstObjOrgType  = new List <object>();
            lstObjOrgType.Add(null);
            lstObjOrgType.Add(null);
            lstObjOrgType.Add(1);
            lstObjOrgType.Add(int.MaxValue - 1);
            var lstOrgType = orgTypeService.GetData <Cat_OrgStructureTypeEntity>(lstObjOrgType, ConstantSql.hrm_cat_sp_get_OrgStructureType, UserLogin, ref status).ToList();

            string orgstructureNameByProfile = string.Empty;
            if (model.ProfileID != null)
            {
                var profilebydis = profileServices.GetData <Hre_ProfileEntity>(Common.DotNetToOracle(model.ProfileID.ToString()), ConstantSql.hrm_hr_sp_get_ProfileById, UserLogin, ref status).FirstOrDefault();
                if (profilebydis != null)
                {
                    Guid?orgId      = profilebydis.OrgStructureID;
                    var  org        = lstOrg.FirstOrDefault(s => s.ID == profilebydis.OrgStructureID);
                    var  department = LibraryService.GetNearestParentEntity(orgId, OrgUnit.E_DEPARTMENT, lstOrg, lstOrgType);
                    orgstructureNameByProfile = department != null ? department.OrgStructureName : string.Empty;
                }
            }
            model.DepartmentName = orgstructureNameByProfile;
            #endregion
            ActionService service = new ActionService(UserLogin);
            return(service.UpdateOrCreate <Hre_DisciplineEntity, Hre_DisciplineModel>(model));
        }
Beispiel #6
0
        // GET api/<controller>/5
        public Sys_LockObjectModel Get(Guid id)
        {
            string        status        = string.Empty;
            var           model         = new Sys_LockObjectModel();
            ActionService service       = new ActionService(UserLogin);
            var           cutOfServices = new Att_CutOffDurationServices();
            var           orgServices   = new Cat_OrgStructureServices();
            var           entity        = service.GetByIdUseStore <Sys_LockObjectEntity>(id, ConstantSql.hrm_sys_sp_get_LockObjectByID, ref status);

            List <object> listModel = new List <object>();

            listModel.AddRange(new object[3]);
            listModel[1] = 1;
            listModel[2] = Int32.MaxValue - 1;
            List <Att_CutOffDurationEntity> listCutoffduration_All = cutOfServices.GetData <Att_CutOffDurationEntity>(listModel, ConstantSql.hrm_att_sp_get_CutOffDurations, UserLogin, ref status).ToList();

            var objOrg = new List <object>();

            objOrg.Add(null);
            objOrg.Add(null);
            objOrg.Add(null);
            objOrg.Add(1);
            objOrg.Add(int.MaxValue - 1);
            var lstOrg = orgServices.GetData <Cat_OrgStructureEntity>(objOrg, ConstantSql.hrm_cat_sp_get_OrgStructure, UserLogin, ref status).ToList();

            if (entity != null)
            {
                model = entity.CopyData <Sys_LockObjectModel>();

                if (model.PayrollGroups != null)
                {
                    model.lstPayrollGroupID = Common.GetListNumbersFromBinary(model.PayrollGroups);
                    model.PayrollGroupID    = string.Join(",", model.lstPayrollGroupID);
                }
                if (model.OrgStructures != null)
                {
                    model.lstOrgStructureID = Common.GetListNumbersFromBinary(model.OrgStructures);
                    var lstOrgName = lstOrg.Where(s => model.lstOrgStructureID.Contains(s.OrderNumber)).Select(s => s.OrgStructureName).ToList();
                    model.OrgStructureID   = string.Join(",", model.lstOrgStructureID);
                    model.OrgStructureName = string.Join(",", lstOrgName);
                }
                var cutOfDurationEntity = listCutoffduration_All.Where(s => s.DateEnd == model.DateEnd && s.DateStart == model.DateStart).FirstOrDefault();
                if (cutOfDurationEntity != null)
                {
                    model.CutOffDurationID   = cutOfDurationEntity.ID;
                    model.CutOffDurationName = cutOfDurationEntity.CutOffDurationName;
                }
            }
            model.ActionStatus = status;
            return(model);
        }
        public void NUnit_Contract_Domain_Remove()
        {
            Cat_OrgStructureServices service = new Cat_OrgStructureServices();
            int rs    = 0;
            var model = new Cat_OrgStructure {
                Id = 3
            };
            bool result = service.DeleteCatOrgStructure(model.Id);

            NUnit.Framework.Assert.IsTrue(result);
            if (result == true)
            {
                rs += 1;
                Console.WriteLine("Process Success >>> Remove >>> " + model.Id);
            }
        }
        public void NUnit_Contract_Domain_GetById()
        {
            Cat_OrgStructureServices service = new Cat_OrgStructureServices();
            var model = new Cat_OrgStructure {
                Id = 3
            };
            var result = service.GetByIdCatOrgStructure(model.Id) as Cat_OrgStructure;

            NUnit.Framework.Assert.IsNotNull(result);
            Console.Write("SearchResult: " + result.Id
                          + " | " + result.OrgStructureName
                          + " | " + result.Code
                          + " | " + result.IsRoot
                          + " | " + result.Description
                          + " | " + result.TypeID
                          + " | " + result.ParentID
                          + " | " + result.OrderNumber
                          );
        }
        public void NUnit_Contract_Domain_Add()
        {
            Cat_OrgStructureServices service = new Cat_OrgStructureServices();
            bool result  = true;
            int  countSC = 0;

            for (int i = 1; i <= 10; i++)
            {
                var model = new Cat_OrgStructure
                {
                    OrgStructureName = "Phong Ban " + i,
                    Code             = "Add Mã " + i,
                    IsRoot           = true,
                    Description      = "Mô Tả " + i,
                    TypeID           = 1,
                    ParentID         = 1,
                    OrderNumber      = i
                };
                result = service.AddCatOrgStructure(model);
                NUnit.Framework.Assert.IsTrue(result);
                if (result == true)
                {
                    countSC += 1;
                    Console.WriteLine("Process Success >>> Create >>> " + model.Id
                                      + " | " + model.OrgStructureName
                                      + " | " + model.Code
                                      + " | " + model.IsRoot
                                      + " | " + model.Description
                                      + " | " + model.TypeID
                                      + " | " + model.ParentID
                                      + " | " + model.OrderNumber
                                      );
                }
            }
            Console.WriteLine("Total success record: " + countSC);
        }
Beispiel #10
0
        public Hre_ProfileModel Post([Bind] Hre_ProfileModel model)
        {
            string status = string.Empty;

            if (model != null)
            {
                ActionService service     = new ActionService(UserLogin);
                BaseService   BaseService = new BaseService();

                if (!string.IsNullOrWhiteSpace(model.CodeAttendance))
                {
                    model.CodeAttendance = model.CodeAttendance.TrimAll();
                }

                #region Validate

                string message = string.Empty;

                var checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData <Hre_ProfileModel>(model, "Hre_Profile", ref message);
                if (!checkValidate)
                {
                    model.ActionStatus = message;
                    return(model);
                }
                if (model.DateOfEffectOld != null)
                {
                    checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData <Hre_ProfileModel>(model, "Hre_ProfileCheckDateOfEffect", ref message);
                    if (!checkValidate)
                    {
                        model.ActionStatus = message;
                        return(model);
                    }
                }
                #endregion

                #region Xử lý cập nhật AbilityTitle khi chọn rank

                if (model.SalaryClassID != null)
                {
                    var abilityTitleBySalaryClass = BaseService.GetData <Cat_AbilityTileEntity>(Common.DotNetToOracle(model.SalaryClassID.ToString()), ConstantSql.hrm_cat_sp_get_AbilityTileBySalaryClassId, UserLogin, ref status).FirstOrDefault();
                    if (abilityTitleBySalaryClass != null)
                    {
                        model.AbilityTileID = abilityTitleBySalaryClass.ID;
                    }
                }

                #endregion

                #region Xử Lý Lưu field DateOfBirth
                var dateOfBirth = string.Empty;
                if (model.DayOfBirth == 00 && model.MonthOfBirth == 00)
                {
                    model.ActionStatus = "ErrorDateOfBirth";
                    return(model);
                }
                if (model.DayOfBirth == null && model.MonthOfBirth == null && model.YearOfBirth == null)
                {
                    dateOfBirth = string.Empty;
                }
                else
                {
                    if (model.DayOfBirth == null)
                    {
                        model.DayOfBirth = DateTime.Now.Day;
                    }
                    if (model.MonthOfBirth == null)
                    {
                        model.MonthOfBirth = DateTime.Now.Month;
                    }
                    if (model.YearOfBirth == null)
                    {
                        model.ActionStatus = "ErrorDateOfBirth";
                        return(model);
                    }
                }


                if (model.DayOfBirth >= 0 || model.MonthOfBirth >= 0 || model.YearOfBirth >= 0)
                {
                    if (model.DayOfBirth == 30 && model.MonthOfBirth == 2)
                    {
                        model.ActionStatus = "ErrorDateOfBirth";
                        return(model);
                    }
                    if (model.DayOfBirth == 31 && model.MonthOfBirth == 2)
                    {
                        model.ActionStatus = "ErrorDateOfBirth";
                        return(model);
                    }
                    if (model.DayOfBirth > 31 || model.MonthOfBirth > 12)
                    {
                        model.ActionStatus = "ErrorDateOfBirth";
                        return(model);
                    }
                    dateOfBirth = model.MonthOfBirth + "/" + model.DayOfBirth + "/" + model.YearOfBirth;
                }

                model.DateOfBirth = string.IsNullOrEmpty(dateOfBirth) ? (DateTime?)null : DateTime.Parse(dateOfBirth);
                #endregion
                Hre_ProfileModel HreProfile = new Hre_ProfileModel();
                if (model.ID != Guid.Empty)
                {
                    HreProfile = GetById(model.ID);
                }
                if (HreProfile != null && (model.ID == HreProfile.ID) && model.ActionStatus != "1")
                {
                    string[] listFieldName = new[] { "JobTitleID", "PositionID", "EmpTypeID", "DateOfEffect", "CostCentreID", "OrgStructureID", "WorkPlaceID", "SupervisorID" };
                    foreach (var item in listFieldName)
                    {
                        var value1 = model.GetPropertyValue(item);
                        var value2 = HreProfile.GetPropertyValue(item);
                        if ((value1 != null && value2 != null) && (value1.ToString() != value2.ToString()))
                        {
                            model.SetPropertyValue(Constant.ActionStatus, NotificationType.Change.ToString());
                            return(model);
                        }
                    }
                    if (HreProfile.ProfileName != model.ProfileName)
                    {
                        if (model.ProfileName.Contains(' '))
                        {
                            model.FirstName  = model.ProfileName.Substring(model.ProfileName.LastIndexOf(' ') + 1);
                            model.NameFamily = model.ProfileName.Substring(0, model.ProfileName.LastIndexOf(' '));
                        }
                        else
                        {
                            model.FirstName = model.ProfileName;
                        }
                    }
                }
                if (model.ActionStatus == "1" || model.ActionStatus == "Success" || string.IsNullOrEmpty(model.ActionStatus))
                {
                    var serviceAddress = new Hre_AddressServices();
                    var serviceProfile = new Hre_ProfileServices();
                    var profileEntity  = new Hre_ProfileEntity();
                    if (model.ID != Guid.Empty)
                    {
                        profileEntity = serviceProfile.GetData <Hre_ProfileEntity>(Common.DotNetToOracle(model.ID.ToString()), ConstantSql.hrm_hr_sp_get_ProfileById, UserLogin, ref status).FirstOrDefault();
                    }

                    #region Xử lý lưu CardCode
                    Hre_CardHistoryServices cardservices        = new Hre_CardHistoryServices();
                    Hre_WorkHistoryServices workHistoryservices = new Hre_WorkHistoryServices();

                    if (profileEntity != null && model.CodeAttendance != null && model.DateApplyAttendanceCode != null && (model.CodeAttendance != profileEntity.CodeAttendance ||
                                                                                                                           model.DateApplyAttendanceCode != profileEntity.DateApplyAttendanceCode))
                    {
                        // Chỉ thay đổi mã chấm công
                        if (model.DateApplyAttendanceCode == profileEntity.DateApplyAttendanceCode && model.CodeAttendance != profileEntity.CodeAttendance)
                        {
                            Hre_CardHistoryEntity history = cardservices.GetData <Hre_CardHistoryEntity>(Common.DotNetToOracle(model.ID.ToString()), ConstantSql.hrm_hr_sp_get_CardHistoryByProfileId, UserLogin, ref status).OrderByDescending(s => s.DateEffect).FirstOrDefault();
                            if (history != null)
                            {
                                history.CardCode = model.CodeAttendance;
                                cardservices.Edit(history);
                            }
                            else
                            {
                                history            = new Hre_CardHistoryEntity();
                                history.ProfileID  = model.ID;
                                history.CardCode   = model.CodeAttendance;
                                history.DateEffect = model.DateApplyAttendanceCode;
                                cardservices.Add(history);
                            }
                        }
                        // Chỉ thay đổi Ngày áp dụng mã chấm công

                        else if (model.CodeAttendance == profileEntity.CodeAttendance && model.DateApplyAttendanceCode != profileEntity.DateApplyAttendanceCode)
                        {
                            if (model.DateApplyAttendanceCode < profileEntity.DateApplyAttendanceCode)
                            {
                                model.StatusVerify = "Invalid";
                                return(model);
                            }
                            Hre_CardHistoryEntity history = cardservices.GetData <Hre_CardHistoryEntity>(Common.DotNetToOracle(model.ID.ToString()), ConstantSql.hrm_hr_sp_get_CardHistoryByProfileId, UserLogin, ref status).OrderByDescending(s => s.DateEffect).FirstOrDefault();
                            if (history != null)
                            {
                                history.DateEffect = model.DateApplyAttendanceCode;
                                cardservices.Edit(history);
                            }
                            else
                            {
                                history            = new Hre_CardHistoryEntity();
                                history.ProfileID  = model.ID;
                                history.CardCode   = model.CodeAttendance;
                                history.DateEffect = model.DateApplyAttendanceCode;
                                cardservices.Add(history);
                            }
                        }
                    }
                    // Tạo mới NV hoặc thay đổi cả 2( mã chấm công + ngày hiệu lực)
                    Hre_CardHistoryEntity cardhistory = null;
                    if (model != null && model.ID == Guid.Empty || (model != null && profileEntity != null && model.CodeAttendance != profileEntity.CodeAttendance &&
                                                                    model.DateApplyAttendanceCode != profileEntity.DateApplyAttendanceCode))
                    {
                        cardhistory            = new Hre_CardHistoryEntity();
                        cardhistory.ProfileID  = model.ID;
                        cardhistory.CardCode   = model.CodeAttendance;
                        cardhistory.DateEffect = model.DateApplyAttendanceCode;
                    }
                    #endregion

                    #region Xử lý lưu quá trình công tác
                    Hre_WorkHistoryEntity workHistory = null;
                    if (model != null && (model.JobTitleID != profileEntity.JobTitleID || model.PositionID != profileEntity.PositionID || model.EmpTypeID != profileEntity.EmpTypeID ||
                                          (model.DateOfEffect != null && profileEntity.DateOfEffect != null &&
                                           model.DateOfEffect.Value.ToString() != profileEntity.DateOfEffect.Value.ToString()) ||
                                          model.CostCentreID != profileEntity.CostCentreID || model.SupervisorID != profileEntity.SupervisorID ||
                                          model.OrgStructureID != profileEntity.OrgStructureID || model.WorkPlaceID != profileEntity.WorkPlaceID))
                    {
                        workHistory = new Hre_WorkHistoryEntity();
                        var orgService       = new Cat_OrgStructureServices();
                        var jobtitleService  = new Cat_JobTitleServices();
                        var postitionService = new Cat_PositionServices();
                        var workPlaceService = new Cat_WorkPlaceServices();

                        workHistory.CostCentreID            = model.CostCentreID;
                        workHistory.OrganizationStructureID = model.OrgStructureID;
                        workHistory.PositionID    = model.PositionID;
                        workHistory.JobTitleID    = model.JobTitleID;
                        workHistory.SalaryClassID = model.SalaryClassID;
                        workHistory.CostSourceID  = model.CostSourceID;
                        workHistory.AbilityTileID = model.AbilityTileID;
                        if (profileEntity != null)
                        {
                            var orgStructureOld = new Cat_OrgStructureEntity();
                            if (profileEntity.OrgStructureID != null && profileEntity.OrgStructureID != Guid.Empty)
                            {
                                orgStructureOld = orgService.GetData <Cat_OrgStructureEntity>(profileEntity.OrgStructureID, ConstantSql.hrm_cat_sp_get_OrgStructureById, UserLogin, ref status).FirstOrDefault();
                            }
                            var jobtitleOld = new Cat_JobTitleEntity();
                            if (profileEntity.JobTitleID != null && profileEntity.JobTitleID != Guid.Empty)
                            {
                                jobtitleOld = jobtitleService.GetData <Cat_JobTitleEntity>(profileEntity.JobTitleID, ConstantSql.hrm_cat_sp_get_HDTJobTypeById, UserLogin, ref status).FirstOrDefault();
                            }
                            var postitionOld = new Cat_PositionEntity();
                            if (profileEntity.PositionID != null && profileEntity.PositionID != Guid.Empty)
                            {
                                postitionOld = postitionService.GetData <Cat_PositionEntity>(profileEntity.PositionID, ConstantSql.hrm_cat_sp_get_PositionById, UserLogin, ref status).FirstOrDefault();
                            }
                            var workPlace = new Cat_WorkPlaceEntity();
                            if (model.WorkPlaceID != null && model.WorkPlaceID != Guid.Empty)
                            {
                                workPlace = workPlaceService.GetData <Cat_WorkPlaceEntity>(model.WorkPlaceID, ConstantSql.hrm_cat_sp_get_WorkPlaceById, UserLogin, ref status).FirstOrDefault();
                            }
                            var workPlaceOld = new Cat_WorkPlaceEntity();
                            if (profileEntity.WorkPlaceID != null && profileEntity.WorkPlaceID != Guid.Empty)
                            {
                                workPlaceOld = workPlaceService.GetData <Cat_WorkPlaceEntity>(profileEntity.WorkPlaceID, ConstantSql.hrm_cat_sp_get_WorkPlaceById, UserLogin, ref status).FirstOrDefault();
                            }
                            workHistory.OrgOld          = orgStructureOld != null ? orgStructureOld.OrgStructureName : "";
                            workHistory.JobTitleOld     = jobtitleOld != null ? jobtitleOld.JobTitleName : "";
                            workHistory.PositionOld     = postitionOld != null ? postitionOld.PositionName : "";
                            workHistory.WorkLocation    = workPlace != null ? workPlace.WorkPlaceName : "";
                            workHistory.WorkLocationOld = workPlaceOld != null ? workPlaceOld.WorkPlaceName : "";
                        }
                        if (workHistory.ID == Guid.Empty)
                        {
                            if (model.DateOfEffect != null)
                            {
                                workHistory.DateEffective = model.DateOfEffect.Value;
                            }
                            else
                            {
                                workHistory.DateEffective = DateTime.Now;
                            }
                        }

                        if (model.DateQuit != null && (profileEntity == null || profileEntity.DateQuit != model.DateQuit))
                        {
                            workHistory.DateEffective = model.DateQuit.Value;
                        }
                    }

                    #region Ngày hiệu lực phải <= ngày hiện tại thì mới cập nhật lại quá trình công tác
                    if (model.DateOfEffect > DateTime.Now && profileEntity != null && profileEntity.DateOfEffect != null)
                    {
                        model.DateOfEffect     = profileEntity.DateOfEffect;
                        model.OrgStructureID   = profileEntity.OrgStructureID;
                        model.ShopID           = profileEntity.ShopID;
                        model.JobTitleID       = profileEntity.JobTitleID;
                        model.PositionID       = profileEntity.PositionID;
                        model.SupervisorID     = profileEntity.SupervisorID;
                        model.HighSupervisorID = profileEntity.HighSupervisorID;
                        model.IsHeadDept       = profileEntity.IsHeadDept;
                        model.EmpTypeID        = profileEntity.EmpTypeID;
                        model.LaborType        = profileEntity.LaborType;
                        model.SikillLevel      = profileEntity.SikillLevel;
                        model.PayrollGroupID   = profileEntity.PayrollGroupID;
                        model.SalaryClassID    = profileEntity.SalaryClassID;
                        model.CostCentreID     = profileEntity.CostCentreID;
                        model.LocationCode     = profileEntity.LocationCode;
                        model.WorkPlaceID      = profileEntity.WorkPlaceID;
                    }
                    #endregion

                    #endregion

                    var profileModel = service.UpdateOrCreate <Hre_ProfileEntity, Hre_ProfileModel>(model);

                    if (cardhistory != null && profileModel != null)
                    {
                        cardhistory.ProfileID = profileModel.ID;
                        cardservices.Add(cardhistory);
                    }

                    if (workHistory != null && profileModel != null)
                    {
                        workHistory.EmployeeTypeID = profileModel.EmpTypeID;
                        workHistory.ProfileID      = profileModel.ID;
                        workHistoryservices.Add(workHistory);
                    }
                }
            }

            //Xóa cache lưu lại của cây phòng ban
            HttpContext.Current.Cache.Remove("List_OrgStructureTreeView");
            HttpContext.Current.Cache.Remove("List_OrgStructureTreeViewSumProfile");

            return(model);
        }