Example #1
0
        private static SlottingLimit MapToSlottingLimit(SlottingLimitModel command)
        {
            var slottingLimit = new SlottingLimit()
            {
                MinimumEfficiency = command.MinimumEfficiency,
                BandingTolerance  = command.BandingTolerance,
                Demographs        = command.Demographs,
                MaximumEfficiency = command.MaximumEfficiency
            };

            return(slottingLimit);
        }
Example #2
0
        public static void ApplyToPass(Pass pass, PassModel command, IMapper mapper)
        {
            if (pass != null && command != null)
            {
                pass.Id   = command.Id > 0 ? command.Id : pass.Id;
                pass.Name = command.Name;

                List <General> oldGenerals = new List <General>();
                pass.General.ForEach(item => oldGenerals.Add(item));
                pass.General.Clear();
                foreach (GeneralModel generalModel in command.General)
                {
                    General oldGeneral = oldGenerals.Find(item => item.RuleId == generalModel.RuleId);
                    if (oldGeneral == null)
                    {
                        General general = MapToGeneral(generalModel);
                        pass.General.Add(general);
                    }
                    else
                    {
                        ApplyToGeneral(oldGeneral, generalModel);
                        pass.General.Add(oldGeneral);
                    }
                }

                List <PassRule> oldRules = new List <PassRule>();
                pass.Rules.ForEach(item => oldRules.Add(item));
                pass.Rules.Clear();
                foreach (PassRuleModel ruleModel in command.Rules)
                {
                    PassRule oldRule = oldRules.Find(item => item.RuleId == ruleModel.RuleId);
                    if (oldRule == null)        // New rule
                    {
                        PassRule rule = MapToRule(ruleModel);
                        pass.Rules.Add(rule);
                    }
                    else
                    {
                        ApplyToRule(oldRule, ruleModel);
                        pass.Rules.Add(oldRule);
                    }
                }

                #region pass.Tolerances

                List <Tolerance> oldTolerances = new List <Tolerance>();
                pass.Tolerances.ForEach(item => oldTolerances.Add(item));
                pass.Tolerances.Clear();
                foreach (ToleranceModel toleranceModel in command.Tolerances)
                {
                    Tolerance oldTolerance = oldTolerances.Find(item => item.RuleId == toleranceModel.RuleId);
                    if (oldTolerance == null)        // New rule
                    {
                        Tolerance tolerance = MapToTolerance(toleranceModel);
                        pass.Tolerances.Add(tolerance);
                    }
                    else
                    {
                        ApplyToTolerance(oldTolerance, toleranceModel);
                        pass.Tolerances.Add(oldTolerance);
                    }
                }

                #endregion pass.Tolerances

                #region pass.RatingPoints

                pass.RatingPoints = command.RatingPoints.Select(x => mapper.Map <RatingPoint>(x)).ToList();

                #endregion pass.RatingPoints

                #region pass.Weightings

                List <Weighting> oldWeightings = new List <Weighting>();
                pass.Weightings.ForEach(item => oldWeightings.Add(item));
                pass.Weightings.Clear();
                foreach (WeightingModel weightingMode in command.Weightings)
                {
                    Weighting oldWeighting = oldWeightings.Find(item => item.RuleId == weightingMode.RuleId);
                    if (oldWeighting == null)        // New rule
                    {
                        Weighting weighting = MapToWeighting(weightingMode);
                        pass.Weightings.Add(weighting);
                    }
                    else
                    {
                        ApplyToWeighting(oldWeighting, weightingMode);
                        pass.Weightings.Add(oldWeighting);
                    }
                }

                #endregion pass.Weightings

                #region pass.ProgrammeRepetitions

                pass.ProgrammeRepetitions.Clear();
                foreach (ProgrammeRepetitionModel programmeRepetitionMode in command.ProgrammeRepetitions)
                {
                    ProgrammeRepetition programmeRepetition = MapToProgrammeRepetition(programmeRepetitionMode);
                    pass.ProgrammeRepetitions.Add(programmeRepetition);
                }

                #endregion pass.ProgrammeRepetitions

                #region pass.BreakExclusions

                pass.BreakExclusions.Clear();
                foreach (BreakExclusionModel breakExclusionMode in command.BreakExclusions)
                {
                    BreakExclusion breakExclusion = MapToBreakExclusion(breakExclusionMode);
                    pass.BreakExclusions.Add(breakExclusion);
                }

                #endregion pass.BreakExclusions

                #region pass.SlottingLimits

                pass.SlottingLimits.Clear();
                foreach (SlottingLimitModel slottingLimitMode in command.SlottingLimits)
                {
                    SlottingLimit slottingLimit = MapToSlottingLimit(slottingLimitMode);
                    pass.SlottingLimits.Add(slottingLimit);
                }

                #endregion pass.SlottingLimits

                #region pass.PassSalesAreaPriorities

                pass.PassSalesAreaPriorities = MapToPassSalesAreaPriorities(command.PassSalesAreaPriorities);

                #endregion pass.PassSalesAreaPriorities
            }
        }