/// <summary>
        /// تغییر مشخصات سازمانی
        /// </summary>
        /// <param name="personList">لیست پرسنل</param>
        /// <param name="infoProxy">پروکسی مشخصات سازمانی</param>
        /// <param name="errorList">خروجی لیست خطاها</param>
        /// <returns>وضعیت انجام عملیات</returns>
        private bool ChangeInfo(IList <Person> personList, OrganicInfoProxy infoProxy, out IList <ChangeInfoErrorProxy> errorList)
        {
            IList <PersonRuleCatAssignment>  ruleAssgnList      = new List <PersonRuleCatAssignment>();
            IList <PersonRangeAssignment>    rangeAssgnList     = new List <PersonRangeAssignment>();
            IList <AssignWorkGroup>          workGroupAssgnList = new List <AssignWorkGroup>();
            IList <PersonContractAssignment> contractAssgnList  = new List <PersonContractAssignment>();


            #region Validate
            DateTime workGroupFromDate, ruleGroupFromDate, ruleGroupToDate, DateRangeFromDate, contractFromDate, contractToDate;
            if (BLanguage.CurrentSystemLanguage == LanguagesName.Parsi)
            {
                workGroupFromDate = Utility.ToMildiDate(infoProxy.WorkGroupFromDate);
                ruleGroupFromDate = Utility.ToMildiDate(infoProxy.RuleGroupFromDate);
                ruleGroupToDate   = Utility.ToMildiDate(infoProxy.RuleGroupToDate);
                DateRangeFromDate = Utility.ToMildiDate(infoProxy.DateRangeFromDate);
                contractFromDate  = Utility.ToMildiDate(infoProxy.ContractFromDate);
                contractToDate    = Utility.ToMildiDate(infoProxy.ContractToDate);
            }
            else
            {
                workGroupFromDate = Utility.ToMildiDateTime(infoProxy.WorkGroupFromDate);
                ruleGroupFromDate = Utility.ToMildiDateTime(infoProxy.RuleGroupFromDate);
                ruleGroupToDate   = Utility.ToMildiDateTime(infoProxy.RuleGroupToDate);
                DateRangeFromDate = Utility.ToMildiDateTime(infoProxy.DateRangeFromDate);
                contractFromDate  = Utility.ToMildiDateTime(infoProxy.ContractFromDate);
                contractToDate    = Utility.ToMildiDateTime(infoProxy.ContractToDate);
            }


            errorList = new List <ChangeInfoErrorProxy>();
            foreach (Person prs in personList)
            {
                string errorMessage = "";
                if (infoProxy.WorkGroupID > 0)
                {
                    workGroupAssgnList = new BAssignWorkGroup(BLanguage.CurrentSystemLanguage).GetAllByWorkGroupId(infoProxy.WorkGroupID);
                    ValidateWorkGroupAssignment(prs, workGroupFromDate, ref errorMessage);
                }
                if (infoProxy.RuleGroupID > 0)
                {
                    ruleAssgnList = new BAssignRule(BLanguage.CurrentSystemLanguage).GetAllByRuleGroupId(infoProxy.RuleGroupID);
                    ValidateRuleGroupAssignment(prs, ruleGroupFromDate, ruleGroupToDate, ref errorMessage);
                }
                if (infoProxy.DateRangeID > 0)
                {
                    rangeAssgnList = new BAssignDateRange(BLanguage.CurrentSystemLanguage).GetAllByRangeId(infoProxy.DateRangeID);
                    ValidateDateRangeAssignment(prs, DateRangeFromDate, ref errorMessage);
                }
                if (infoProxy.ContractID > 0)
                {
                    contractAssgnList = new BPersonContractAssignment(BLanguage.CurrentSystemLanguage).GetAllByContractId(infoProxy.ContractID);
                    ValidateContractAssignment(prs, contractFromDate, contractToDate, ref errorMessage);
                }
                if (!Utility.IsEmpty(errorMessage))
                {
                    errorList.Add(new ChangeInfoErrorProxy()
                    {
                        ErrorMessage = errorMessage, PersonCode = prs.PersonCode, PersonName = prs.Name
                    });
                    if (errorList.Count > 50)
                    {
                        break;
                    }
                }
            }
            if (errorList.Count > 0)
            {
                return(false);
            }
            #endregion

            using (NHibernateSessionManager.Instance.BeginTransactionOn())
            {
                try
                {
                    UnderManagmentRepository         underMngRep                = new UnderManagmentRepository(false);
                    List <decimal>                   personIdList               = new List <decimal>();
                    IList <OrganizationFeatureProxy> organizationFeatureList    = new List <OrganizationFeatureProxy>();
                    IList <FlowPersonsProxy>         flowPersonList             = new List <FlowPersonsProxy>();
                    List <decimal>                   PersonnelsDepartmentChange = new List <decimal>();
                    bool     cfpUpdateRequierd = false;
                    DateTime minDate           = DateTime.Now;
                    int      counter           = 0;
                    foreach (Person prs in personList)
                    {
                        counter++;
                        bool updatePrs = false;
                        personIdList.Add(prs.ID);
                        IList <OrganizationFeatureProxy> organizationFeatureExist = new List <OrganizationFeatureProxy>();
                        UnderManagment underMng = new UnderManagment();

                        #region Department
                        if (infoProxy.DepartmentID > 0)
                        {
                            if (prs.Department.ID != infoProxy.DepartmentID)
                            {
                                PersonnelsDepartmentChange.Add(prs.ID);
                            }
                            if (organizationFeatureList.Count != 0)
                            {
                                organizationFeatureExist = organizationFeatureList.Where(x => x.DepartmentId == prs.Department.ID).ToList();
                            }

                            if (organizationFeatureExist.Count == 0)
                            {
                                IList <decimal> FlowIds = underMngRep.GetDepartmentFlows(prs.Department.ID);
                                foreach (decimal flowId in FlowIds)
                                {
                                    OrganizationFeatureProxy orgFeatureProxy = new OrganizationFeatureProxy();
                                    FlowPersonsProxy         flowPerson      = new FlowPersonsProxy();
                                    orgFeatureProxy.FlowId       = flowId;
                                    orgFeatureProxy.DepartmentId = prs.Department.ID;
                                    organizationFeatureList.Add(orgFeatureProxy);
                                    flowPerson.FlowId   = flowId;
                                    flowPerson.PersonId = prs.ID;
                                    flowPersonList.Add(flowPerson);
                                }
                            }
                            else
                            {
                                IList <decimal> FlowIds = organizationFeatureExist.Select(x => x.FlowId)
                                                          .ToList <decimal>();
                                foreach (decimal flowId in FlowIds)
                                {
                                    FlowPersonsProxy flowPerson = new FlowPersonsProxy();
                                    flowPerson.FlowId   = flowId;
                                    flowPerson.PersonId = prs.ID;
                                    flowPersonList.Add(flowPerson);
                                }
                            }
                            prs.Department = new GTS.Clock.Model.Charts.Department()
                            {
                                ID = infoProxy.DepartmentID
                            };
                            updatePrs = true;
                        }
                        #endregion

                        #region Employment Type
                        if (infoProxy.EmploymentTypeID > 0)
                        {
                            prs.EmploymentType = new GTS.Clock.Model.BaseInformation.EmploymentType()
                            {
                                ID = infoProxy.EmploymentTypeID
                            };
                            updatePrs = true;
                        }
                        #endregion

                        if (updatePrs)
                        {
                            prsRepository.WithoutTransactUpdate(prs);
                        }

                        #region Rule Category
                        if (infoProxy.RuleGroupID > 0)
                        {
                            cfpUpdateRequierd = true;
                            PersonRuleCatAssignment ruleAssign  = new PersonRuleCatAssignment();
                            BAssignRule             ruleAsgnBus = new BAssignRule();
                            ruleAssgnList = ruleAsgnBus.GetAll(prs.ID);
                            IList <PersonRuleCatAssignment> confilictList =
                                ruleAssgnList.Where(x => ((Utility.ToMildiDateTime(x.FromDate) <= ruleGroupToDate && Utility.ToMildiDateTime(x.ToDate) >= ruleGroupToDate))
                                                    ||
                                                    ((Utility.ToMildiDateTime(x.FromDate) <= ruleGroupFromDate && Utility.ToMildiDateTime(x.ToDate) >= ruleGroupFromDate))
                                                    ||
                                                    ((Utility.ToMildiDateTime(x.FromDate) >= ruleGroupFromDate && Utility.ToMildiDateTime(x.FromDate) <= ruleGroupToDate))
                                                    ).ToList();
                            if (confilictList != null && confilictList.Count > 0)
                            {
                                Range range = new Range()
                                {
                                    From = ruleGroupFromDate, To = ruleGroupToDate, AditionalField = 0
                                };
                                var confilictRanges = from o in confilictList
                                                      select new Range()
                                {
                                    From = Utility.ToMildiDateTime(o.FromDate), To = Utility.ToMildiDateTime(o.ToDate), AditionalField = o.RuleCategory.ID
                                };
                                IList <Range> breakedList = Utility.Differance(confilictRanges.ToList(), range);

                                #region Delete
                                //foreach (PersonRuleCatAssignment asgn in ruleAssgnList)
                                //{
                                //    ruleAsgnBus.SaveChanges(asgn, UIActionType.DELETE);
                                //}
                                foreach (PersonRuleCatAssignment asgn in confilictList)
                                {
                                    ruleAsgnBus.SaveChanges(asgn, UIActionType.DELETE);
                                }
                                #endregion

                                #region add first
                                ruleAssign.FromDate     = Utility.ToString(ruleGroupFromDate);
                                ruleAssign.ToDate       = Utility.ToString(ruleGroupToDate);
                                ruleAssign.Person       = prs;
                                ruleAssign.RuleCategory = new RuleCategory()
                                {
                                    ID = infoProxy.RuleGroupID
                                };
                                busRule.InsertWithoutTransaction(ruleAssign);
                                #endregion

                                #region add breaked List
                                foreach (Range r in breakedList)
                                {
                                    if (r.From == range.To)
                                    {
                                        r.From = r.From.AddDays(1);
                                    }
                                    if (r.To == range.From)
                                    {
                                        r.To = r.To.AddDays(-1);
                                    }
                                    ruleAssign              = new PersonRuleCatAssignment();
                                    ruleAssign.FromDate     = Utility.ToString(r.From);
                                    ruleAssign.ToDate       = Utility.ToString(r.To);
                                    ruleAssign.Person       = prs;
                                    ruleAssign.RuleCategory = new RuleCategory()
                                    {
                                        ID = r.AditionalField
                                    };
                                    busRule.InsertWithoutTransaction(ruleAssign);
                                }
                                #endregion
                            }
                            else
                            {
                                ruleAssign.FromDate     = Utility.ToString(ruleGroupFromDate);
                                ruleAssign.ToDate       = Utility.ToString(ruleGroupToDate);
                                ruleAssign.Person       = prs;
                                ruleAssign.RuleCategory = new RuleCategory()
                                {
                                    ID = infoProxy.RuleGroupID
                                };
                                busRule.InsertWithoutTransaction(ruleAssign);
                            }
                            if (minDate > ruleGroupFromDate)
                            {
                                minDate = ruleGroupFromDate;
                            }
                        }
                        #endregion
                        #region Contract
                        if (infoProxy.ContractID > 0)
                        {
                            cfpUpdateRequierd = true;
                            PersonContractAssignment contractAssign = new PersonContractAssignment();
                            contractAssign.Person   = prs;
                            contractAssign.Contract = new Contract()
                            {
                                ID = infoProxy.ContractID
                            };
                            contractAssign.FromDate = contractFromDate;
                            contractAssign.ToDate   = contractToDate;
                            BPersonContractAssignment contractAsgnBus = new BPersonContractAssignment();
                            contractAssgnList = contractAsgnBus.GetAll(prs.ID);
                            PersonContractAssignment PersonContractAssignmentAlias = null;
                            Person PersonAlias = null;
                            IList <PersonContractAssignment> personContractAssignmentList = NHSession.QueryOver <PersonContractAssignment>(() => PersonContractAssignmentAlias)
                                                                                            .JoinAlias(() => PersonContractAssignmentAlias.Person, () => PersonAlias)
                                                                                            .Where(() => !PersonContractAssignmentAlias.IsDeleted &&
                                                                                                   PersonAlias.ID == prs.ID
                                                                                                   )
                                                                                            .List <PersonContractAssignment>();
                            if (personContractAssignmentList != null && personContractAssignmentList.Count > 0)
                            {
                                personContractAssignmentList.ToList()
                                .ForEach(x =>
                                {
                                    if (x.ToDate == Utility.GTSMinStandardDateTime)
                                    {
                                        x.ToDate = DateTime.MaxValue.Date;
                                    }
                                }
                                         );
                            }

                            if (contractAssign.ToDate == Utility.GTSMinStandardDateTime)
                            {
                                contractAssign.ToDate = DateTime.MaxValue.Date;
                            }
                            if (contractAsgnBus.CheckPersonContractAssignmentConfilct(personContractAssignmentList.ToList(), contractAssign))
                            {
                                errorList.Add(new ChangeInfoErrorProxy()
                                {
                                    ErrorMessage = "تاریخ انتساب قرارداد با تاریخ های قبلی همپوشانی دارد", PersonCode = prs.PersonCode, PersonName = prs.Name
                                });
                            }
                            else
                            {
                                if (prs != null && prs.ID != 0 && contractAssign.FromDate < prs.EmploymentDate)
                                {
                                    errorList.Add(new ChangeInfoErrorProxy()
                                    {
                                        ErrorMessage = "تاریخ انتساب ابتدای قرارداد نباید از تاریخ استخدام کوچکتر باشد", PersonCode = prs.PersonCode, PersonName = prs.Name
                                    });
                                }
                                else
                                {
                                    if (contractAssign.ToDate == DateTime.MaxValue.Date)
                                    {
                                        contractAssign.ToDate = Utility.GTSMinStandardDateTime;
                                    }
                                    busAssignContract.InsertWithoutTransaction(contractAssign);
                                    if (minDate > contractFromDate)
                                    {
                                        minDate = contractFromDate;
                                    }
                                }
                            }
                        }
                        #endregion

                        #region Date Range
                        if (infoProxy.DateRangeID > 0)
                        {
                            cfpUpdateRequierd = true;
                            PersonRangeAssignment prsRangeAssignment = new PersonRangeAssignment();
                            rangeAssgnList     = new BAssignDateRange(BLanguage.CurrentSystemLanguage).GetAll(prs.ID);
                            prsRangeAssignment = rangeAssgnList.Where(x => x.FromDate == DateRangeFromDate).FirstOrDefault();
                            if (prsRangeAssignment != null)
                            {
                                prsRangeAssignment.FromDate           = DateRangeFromDate;
                                prsRangeAssignment.CalcDateRangeGroup = new CalculationRangeGroup()
                                {
                                    ID = infoProxy.DateRangeID
                                };
                            }
                            else
                            {
                                prsRangeAssignment                    = new PersonRangeAssignment();
                                prsRangeAssignment.Person             = prs;
                                prsRangeAssignment.FromDate           = DateRangeFromDate;
                                prsRangeAssignment.CalcDateRangeGroup = new CalculationRangeGroup()
                                {
                                    ID = infoProxy.DateRangeID
                                };
                            }
                            bussDateRange.InsertWithoutTransaction(prsRangeAssignment);

                            if (minDate > DateRangeFromDate)
                            {
                                minDate = DateRangeFromDate;
                            }
                        }
                        #endregion

                        #region Work Group
                        if (infoProxy.WorkGroupID > 0)
                        {
                            cfpUpdateRequierd = true;
                            AssignWorkGroup prsWorkGroupAssignment = new AssignWorkGroup();
                            workGroupAssgnList     = new BAssignWorkGroup(BLanguage.CurrentSystemLanguage).GetAll(prs.ID);
                            prsWorkGroupAssignment = workGroupAssgnList.Where(x => x.FromDate == workGroupFromDate).FirstOrDefault();

                            if (prsWorkGroupAssignment != null)
                            {
                                prsWorkGroupAssignment.Person    = prs;
                                prsWorkGroupAssignment.FromDate  = workGroupFromDate;
                                prsWorkGroupAssignment.WorkGroup = new WorkGroup()
                                {
                                    ID = infoProxy.WorkGroupID
                                };
                            }
                            else
                            {
                                prsWorkGroupAssignment           = new AssignWorkGroup();
                                prsWorkGroupAssignment.Person    = prs;
                                prsWorkGroupAssignment.FromDate  = workGroupFromDate;
                                prsWorkGroupAssignment.WorkGroup = new WorkGroup()
                                {
                                    ID = infoProxy.WorkGroupID
                                };
                            }
                            busWorkGroup.InsertWithoutTransaction(prsWorkGroupAssignment);
                            if (minDate > workGroupFromDate)
                            {
                                minDate = workGroupFromDate;
                            }
                        }
                        #endregion
                    }
                    if (infoProxy.DepartmentID > 0)
                    {
                        IList <decimal> FlowIDs = organizationFeatureList.Select(x => x.FlowId).Distinct().ToList <decimal>();
                        if (FlowIDs.Count != 0)
                        {
                            IList <UnderManagment> UnderManagmentList = underMngRep.GetAllPersonelparticularFlows(FlowIDs);
                            foreach (decimal flowid in FlowIDs)
                            {
                                IList <decimal> PersonIds = flowPersonList.Where(x => x.FlowId == flowid &&
                                                                                 !UnderManagmentList.Where(y => y.Flow.ID == flowid).Select(y => y.Person.ID).ToList <decimal>().Contains(x.PersonId)
                                                                                 ).Select(x => x.PersonId).ToList <decimal>();
                                if (PersonIds.Count != 0)
                                {
                                    underMngRep.DeleteUnderManagmentPersonsWithOrganicInfo(flowid, PersonIds);
                                }
                            }
                        }
                        IList <decimal> NewDepertmentFlowsList = underMngRep.GetDepartmentFlows(personList[0].Department.ID);
                        if (NewDepertmentFlowsList.Count != 0)
                        {
                            underMngRep.InsertUnderManagmentPersons(personIdList, NewDepertmentFlowsList);
                        }

                        BRequestSubstitute rSubstitute = new BRequestSubstitute();
                        if (PersonnelsDepartmentChange.Count != 0)
                        {
                            rSubstitute.UpdateRequestSubstituteOfOrganicInfo(PersonnelsDepartmentChange);
                        }
                    }
                    if (cfpUpdateRequierd)
                    {
                        this.UpdateCFP(personList, minDate);
                    }

                    NHibernateSessionManager.Instance.CommitTransactionOn();
                }
                catch (Exception ex)
                {
                    BaseBusiness <Entity> .LogException(ex, "BChangeOrganicInfo", "ChangeInfo");

                    NHibernateSessionManager.Instance.RollbackTransactionOn();
                    throw ex;
                }
            }


            return(true);
        }
Exemple #2
0
        private bool ChangeInfo(IList <Person> personList, OrganicInfoProxy infoProxy, out IList <ChangeInfoErrorProxy> errorList)
        {
            IList <PersonRuleCatAssignment> ruleAssgnList      = new List <PersonRuleCatAssignment>();
            IList <PersonRangeAssignment>   rangeAssgnList     = new List <PersonRangeAssignment>();
            IList <AssignWorkGroup>         workGroupAssgnList = new List <AssignWorkGroup>();



            #region Validate
            DateTime workGroupFromDate, ruleGroupFromDate, ruleGroupToDate, DateRangeFromDate;
            if (BLanguage.CurrentSystemLanguage == LanguagesName.Parsi)
            {
                workGroupFromDate = Utility.ToMildiDate(infoProxy.WorkGroupFromDate);
                ruleGroupFromDate = Utility.ToMildiDate(infoProxy.RuleGroupFromDate);
                ruleGroupToDate   = Utility.ToMildiDate(infoProxy.RuleGroupToDate);
                DateRangeFromDate = Utility.ToMildiDate(infoProxy.DateRangeFromDate);
            }
            else
            {
                workGroupFromDate = Utility.ToMildiDateTime(infoProxy.WorkGroupFromDate);
                ruleGroupFromDate = Utility.ToMildiDateTime(infoProxy.RuleGroupFromDate);
                ruleGroupToDate   = Utility.ToMildiDateTime(infoProxy.RuleGroupToDate);
                DateRangeFromDate = Utility.ToMildiDateTime(infoProxy.DateRangeFromDate);
            }


            errorList = new List <ChangeInfoErrorProxy>();
            foreach (Person prs in personList)
            {
                string errorMessage = "";
                if (infoProxy.WorkGroupID > 0)
                {
                    workGroupAssgnList = new BAssignWorkGroup(BLanguage.CurrentSystemLanguage).GetAllByWorkGroupId(infoProxy.WorkGroupID);
                    ValidateWorkGroupAssignment(prs, workGroupFromDate, ref errorMessage);
                }
                if (infoProxy.RuleGroupID > 0)
                {
                    ruleAssgnList = new BAssignRule(BLanguage.CurrentSystemLanguage).GetAllByRuleGroupId(infoProxy.RuleGroupID);
                    ValidateRuleGroupAssignment(prs, ruleGroupFromDate, ruleGroupToDate, ref errorMessage);
                }
                if (infoProxy.DateRangeID > 0)
                {
                    rangeAssgnList = new BAssignDateRange(BLanguage.CurrentSystemLanguage).GetAllByRangeId(infoProxy.DateRangeID);
                    ValidateDateRangeAssignment(prs, DateRangeFromDate, ref errorMessage);
                }
                if (!Utility.IsEmpty(errorMessage))
                {
                    errorList.Add(new ChangeInfoErrorProxy()
                    {
                        ErrorMessage = errorMessage, PersonCode = prs.PersonCode, PersonName = prs.Name
                    });
                    if (errorList.Count > 50)
                    {
                        break;
                    }
                }
            }
            if (errorList.Count > 0)
            {
                return(false);
            }
            #endregion

            using (NHibernateSessionManager.Instance.BeginTransactionOn())
            {
                try
                {
                    bool     cfpUpdateRequierd = false;
                    DateTime minDate           = DateTime.Now;
                    int      counter           = 0;
                    foreach (Person prs in personList)
                    {
                        counter++;
                        bool updatePrs = false;

                        #region Department
                        if (infoProxy.DepartmentID > 0)
                        {
                            prs.Department = new GTS.Clock.Model.Charts.Department()
                            {
                                ID = infoProxy.DepartmentID
                            };
                            updatePrs = true;
                        }
                        #endregion

                        #region Employment Type
                        if (infoProxy.EmploymentTypeID > 0)
                        {
                            prs.EmploymentType = new GTS.Clock.Model.BaseInformation.EmploymentType()
                            {
                                ID = infoProxy.EmploymentTypeID
                            };
                            updatePrs = true;
                        }
                        #endregion

                        if (updatePrs)
                        {
                            prsRepository.WithoutTransactUpdate(prs);
                        }

                        #region Rule Category
                        if (infoProxy.RuleGroupID > 0)
                        {
                            cfpUpdateRequierd = true;
                            PersonRuleCatAssignment ruleAssign  = new PersonRuleCatAssignment();
                            BAssignRule             ruleAsgnBus = new BAssignRule();
                            ruleAssgnList = ruleAsgnBus.GetAll(prs.ID);
                            IList <PersonRuleCatAssignment> confilictList =
                                ruleAssgnList.Where(x => ((Utility.ToMildiDateTime(x.FromDate) <= ruleGroupToDate && Utility.ToMildiDateTime(x.ToDate) >= ruleGroupToDate))
                                                    ||
                                                    ((Utility.ToMildiDateTime(x.FromDate) <= ruleGroupFromDate && Utility.ToMildiDateTime(x.ToDate) >= ruleGroupFromDate))
                                                    ||
                                                    ((Utility.ToMildiDateTime(x.FromDate) >= ruleGroupFromDate && Utility.ToMildiDateTime(x.FromDate) <= ruleGroupToDate))
                                                    ).ToList();
                            if (confilictList != null && confilictList.Count > 0)
                            {
                                Range range = new Range()
                                {
                                    From = ruleGroupFromDate, To = ruleGroupToDate, AditionalField = 0
                                };
                                var confilictRanges = from o in confilictList
                                                      select new Range()
                                {
                                    From = Utility.ToMildiDateTime(o.FromDate), To = Utility.ToMildiDateTime(o.ToDate), AditionalField = o.RuleCategory.ID
                                };
                                IList <Range> breakedList = Utility.Differance(confilictRanges.ToList(), range);

                                #region Delete
                                foreach (PersonRuleCatAssignment asgn in ruleAssgnList)
                                {
                                    ruleAsgnBus.SaveChanges(asgn, UIActionType.DELETE);
                                }
                                #endregion

                                #region add first
                                ruleAssign.FromDate     = Utility.ToString(ruleGroupFromDate);
                                ruleAssign.ToDate       = Utility.ToString(ruleGroupToDate);
                                ruleAssign.Person       = prs;
                                ruleAssign.RuleCategory = new RuleCategory()
                                {
                                    ID = infoProxy.RuleGroupID
                                };
                                busRule.InsertWithoutTransaction(ruleAssign);
                                #endregion

                                #region add breaked List
                                foreach (Range r in breakedList)
                                {
                                    if (r.From == range.To)
                                    {
                                        r.From = r.From.AddDays(1);
                                    }
                                    if (r.To == range.From)
                                    {
                                        r.To = r.To.AddDays(-1);
                                    }
                                    ruleAssign              = new PersonRuleCatAssignment();
                                    ruleAssign.FromDate     = Utility.ToString(r.From);
                                    ruleAssign.ToDate       = Utility.ToString(r.To);
                                    ruleAssign.Person       = prs;
                                    ruleAssign.RuleCategory = new RuleCategory()
                                    {
                                        ID = r.AditionalField
                                    };
                                    busRule.InsertWithoutTransaction(ruleAssign);
                                }
                                #endregion
                            }
                            else
                            {
                                ruleAssign.FromDate     = Utility.ToString(ruleGroupFromDate);
                                ruleAssign.ToDate       = Utility.ToString(ruleGroupToDate);
                                ruleAssign.Person       = prs;
                                ruleAssign.RuleCategory = new RuleCategory()
                                {
                                    ID = infoProxy.RuleGroupID
                                };
                                busRule.InsertWithoutTransaction(ruleAssign);
                            }
                            if (minDate > ruleGroupFromDate)
                            {
                                minDate = ruleGroupFromDate;
                            }
                        }
                        #endregion

                        #region Date Range
                        if (infoProxy.DateRangeID > 0)
                        {
                            cfpUpdateRequierd = true;
                            PersonRangeAssignment prsRangeAssignment = new PersonRangeAssignment();
                            rangeAssgnList     = new BAssignDateRange(BLanguage.CurrentSystemLanguage).GetAll(prs.ID);
                            prsRangeAssignment = rangeAssgnList.Where(x => x.FromDate == DateRangeFromDate).FirstOrDefault();
                            if (prsRangeAssignment != null)
                            {
                                prsRangeAssignment.FromDate           = DateRangeFromDate;
                                prsRangeAssignment.CalcDateRangeGroup = new CalculationRangeGroup()
                                {
                                    ID = infoProxy.DateRangeID
                                };
                            }
                            else
                            {
                                prsRangeAssignment                    = new PersonRangeAssignment();
                                prsRangeAssignment.Person             = prs;
                                prsRangeAssignment.FromDate           = DateRangeFromDate;
                                prsRangeAssignment.CalcDateRangeGroup = new CalculationRangeGroup()
                                {
                                    ID = infoProxy.DateRangeID
                                };
                            }
                            bussDateRange.InsertWithoutTransaction(prsRangeAssignment);

                            if (minDate > DateRangeFromDate)
                            {
                                minDate = DateRangeFromDate;
                            }
                        }
                        #endregion

                        #region Work Group
                        if (infoProxy.WorkGroupID > 0)
                        {
                            cfpUpdateRequierd = true;
                            AssignWorkGroup prsWorkGroupAssignment = new AssignWorkGroup();
                            workGroupAssgnList     = new BAssignWorkGroup(BLanguage.CurrentSystemLanguage).GetAll(prs.ID);
                            prsWorkGroupAssignment = workGroupAssgnList.Where(x => x.FromDate == workGroupFromDate).FirstOrDefault();

                            if (prsWorkGroupAssignment != null)
                            {
                                prsWorkGroupAssignment.Person    = prs;
                                prsWorkGroupAssignment.FromDate  = workGroupFromDate;
                                prsWorkGroupAssignment.WorkGroup = new WorkGroup()
                                {
                                    ID = infoProxy.WorkGroupID
                                };
                            }
                            else
                            {
                                prsWorkGroupAssignment           = new AssignWorkGroup();
                                prsWorkGroupAssignment.Person    = prs;
                                prsWorkGroupAssignment.FromDate  = workGroupFromDate;
                                prsWorkGroupAssignment.WorkGroup = new WorkGroup()
                                {
                                    ID = infoProxy.WorkGroupID
                                };
                            }
                            busWorkGroup.InsertWithoutTransaction(prsWorkGroupAssignment);
                            if (minDate > workGroupFromDate)
                            {
                                minDate = workGroupFromDate;
                            }
                        }
                        #endregion
                    }
                    if (cfpUpdateRequierd)
                    {
                        this.UpdateCFP(personList, minDate);
                    }

                    NHibernateSessionManager.Instance.CommitTransactionOn();
                }
                catch (Exception ex)
                {
                    BaseBusiness <Entity> .LogException(ex, "BChangeOrganicInfo", "ChangeInfo");

                    NHibernateSessionManager.Instance.RollbackTransactionOn();
                    throw ex;
                }
            }


            return(true);
        }