Ejemplo n.º 1
0
        private RuleResult addPreviousEmployeePointsToCalculationData(CalculationData calculationData, IEnumerable <SummaryCalculationPoint> calculationPoints)
        {
            var points = calculationData.CalculationPoints;
            var res    = new RuleResult();

            if (points == null || !points.Any())
            {
                return(res);
            }

            res.CalculationPoints = points.Where(p => p is SummaryCalculationPoint).Select(p => new RulePoint
            {
                Name  = p.Name,
                Value = p.Value,
                Final = p.IsFinal
            }).ToList();

            res.Results = points.Where(p => p is SummaryEmployeePoint).Select(p => new RulePoint
            {
                Name  = p.Name,
                Value = p.Value,
                Final = p.IsFinal
            }).ToList();
            foreach (var jobPositionData in calculationData.JobPositions)
            {
                var jobPosition       = jobPositionData.Key;
                var jobPositionResult = new JobPositionResult
                {
                    Results = points.Where(
                        p =>
                        p is SummaryJobPositionPoint &&
                        (p as SummaryJobPositionPoint).JobPositionId == jobPosition.Id).Select(p => new RulePoint
                    {
                        Name  = p.Name,
                        Value = p.Value,
                        Final = p.IsFinal
                    }).ToList()
                };
                foreach (var jobIndex in jobPositionData.Value.Indices)
                {
                    jobPositionResult.IndexResults.Add(jobIndex.Key.DictionaryName, points.Where(
                                                           p =>
                                                           p is JobIndexPoint &&
                                                           (p as JobIndexPoint).JobPositionId == jobPosition.Id && (p as JobIndexPoint).JobIndexId == jobIndex.Key.Id).Select(p => new RulePoint
                    {
                        Name  = p.Name,
                        Value = p.Value,
                        Final = p.IsFinal
                    }).ToList());
                }
                res.JobResults.Add(jobPosition.DictionaryName, jobPositionResult);
            }
            return(res);
        }
Ejemplo n.º 2
0
        public RuleContracts.CalculationData Provide(Employee emp, out CalculationData calculationData, Calculation calculation, bool withCalculationPoint, CalculatorSession calculationSession)
        {
            //empRep.Attach(employee);
            var employee = empRep.GetBy(emp.Id);

            calculationData = empRep.ProvideDataForRule(employee, calculation.Id, withCalculationPoint);
            if (calculationSession.CalculationPoints != null && calculationSession.CalculationPoints.Any())
            {
                calculationData.CalculationPoints.AddRange(calculationSession.CalculationPoints);
            }
            var res = new MITD.PMS.RuleContracts.CalculationData
            {
                Employee = new PMS.RuleContracts.Employee
                {
                    FirstName  = calculationData.employee.FirstName,
                    LastName   = calculationData.employee.LastName,
                    EmployeeNo = calculationData.employee.Id.EmployeeNo
                },
                CustomFields =
                    (from k in
                     pmsAdminService.GetSharedEmployeeCustomField(
                         employee.CustomFieldValues.Select(m => m.Key).ToList())
                     join l in employee.CustomFieldValues on k.Id equals l.Key
                     select new { k, l }).ToDictionary(j => j.k.DictionaryName, j => j.l.Value),
                JobPositions = calculationData.JobPositions.Select(jobPositionAndData => new JobPosition
                {
                    Name           = jobPositionAndData.Key.Name,
                    DictionaryName = jobPositionAndData.Key.DictionaryName,

                    Job =
                        new Job
                    {
                        Name           = jobPositionAndData.Value.Job.Name,
                        DictionaryName = jobPositionAndData.Value.Job.DictionaryName
                    },
                    Unit = new Unit
                    {
                        Id       = jobPositionAndData.Value.Unit.Id.SharedUnitId.Id,
                        ParentId =
                            jobPositionAndData.Value.Unit.Parent != null
                                ? jobPositionAndData.Value.Unit.Parent.Id.SharedUnitId.Id
                                : 0,
                        Name           = jobPositionAndData.Value.Unit.Name,
                        DictionaryName = jobPositionAndData.Value.Unit.DictionaryName,
                        Indices        = jobPositionAndData.Value.UnitIndices.ToDictionary(
                            j => new UnitIndex
                        {
                            Name           = j.Key.Name,
                            DictionaryName = j.Key.DictionaryName,
                            IsInquireable  = j.Key.IsInquireable,
                            //Group =
                            //    new JobIndexGroup { Name = j.Key.Group.Name, DictionaryName = j.Key.Group.DictionaryName },
                            CustomFields =
                                (from k in
                                 pmsAdminService.GetSharedCutomFieldListForUnitIndex(j.Key.SharedUnitIndexId,
                                                                                     j.Key.CustomFieldValues.Select(m => m.Key).ToList())
                                 join l in j.Key.CustomFieldValues on k.Id equals l.Key
                                 select new { k, l }).ToDictionary(m => m.k.DictionaryName, m => m.l.Value)
                        },
                            j => (j.Value != null
                                ? new Tuple <PMS.RuleContracts.Employee, string>(new RuleContracts.Employee()
                        {
                            EmployeeNo = j.Value.Item1.Id.EmployeeNo,
                            FirstName = j.Value.Item1.FirstName,
                            LastName = j.Value.Item1.LastName
                        }, j.Value.Item2)
                                  //j.Value.ToDictionary(
                                  //    k => new PMS.RuleContracts.Employee
                                  //    {
                                  //        FirstName = k.Key.FirstName,
                                  //        LastName = k.Key.LastName,
                                  //        EmployeeNo = k.Key.Id.EmployeeNo
                                  //    },
                                  //    k => k.Value.Select(f =>
                                  //        new Inquiry
                                  //        {
                                  //            JobPosition =
                                  //                new InquirerJobPosition
                                  //                {
                                  //                    Name = f.JobPosition.Name,
                                  //                    DictionaryName = f.JobPosition.DictionaryName,
                                  //                    JobPositionLevel = (int)jobPositionAndData.Key.ConfigurationItemList.Single(cil => cil.Id == f.Point.ConfigurationItemId).InquirerJobPositionLevel


                                  //                },
                                  //            Value = f.Point.JobIndexValue
                                  //        }).ToList())
                                : null))
                    },
                    CustomFields =
                        (from k in
                         pmsAdminService.GetSharedCutomFieldListForJob(jobPositionAndData.Value.Job.SharedJob.Id,
                                                                       jobPositionAndData.Value.CustomFields.Select(
                                                                           m => m.JobCustomFieldId.SharedJobCustomFieldId).ToList())
                         join l in jobPositionAndData.Value.CustomFields on k.Id equals
                         l.JobCustomFieldId.SharedJobCustomFieldId
                         select new { k, l }).ToDictionary(j => j.k.DictionaryName, j => j.l.JobCustomFieldValue),
                    Indices = jobPositionAndData.Value.Indices.ToDictionary(
                        j => new JobIndex
                    {
                        Name           = j.Key.Name,
                        DictionaryName = j.Key.DictionaryName,
                        IsInquireable  = j.Key.IsInquireable,
                        Group          =
                            new JobIndexGroup {
                            Name = j.Key.Group.Name, DictionaryName = j.Key.Group.DictionaryName
                        },
                        CustomFields =
                            (from k in
                             pmsAdminService.GetSharedCutomFieldListForJobIndex(j.Key.SharedJobIndexId,
                                                                                j.Key.CustomFieldValues.Select(m => m.Key).ToList())
                             join l in j.Key.CustomFieldValues on k.Id equals l.Key
                             select new { k, l }).ToDictionary(m => m.k.DictionaryName, m => m.l.Value)
                    },
                        j => (j.Value != null
                            ? j.Value.ToDictionary(
                                  k => new PMS.RuleContracts.Employee
                    {
                        FirstName = k.Key.FirstName,
                        LastName = k.Key.LastName,
                        EmployeeNo = k.Key.Id.EmployeeNo
                    },
                                  k => k.Value.Select(f =>
                                                      new Inquiry
                    {
                        JobPosition =
                            new InquirerJobPosition
                        {
                            Name = f.JobPosition.Name,
                            DictionaryName = f.JobPosition.DictionaryName,
                            JobPositionLevel =
                                (int)
                                jobPositionAndData.Key.ConfigurationItemList.Single(
                                    cil =>
                                    cil.Id == f.Point.ConfigurationItemId &&
                                    cil.Id.InquirerJobPositionId.SharedJobPositionId ==
                                    f.JobPosition.Id).InquirerJobPositionLevel
                        },
                        Value = f.Point.JobIndexValue
                    }).ToList())
                            : null))
                }).ToList()
            };

            var ruleResult = addPreviousEmployeePointsToCalculationData(calculationData, calculationSession.CalculationPoints);

            res.Points = ruleResult;
            res.PathNo = calculationSession.PathNo;
            return(res);
        }