public void ItShouldSetConstantValues()
        {
            var parameter = new MonthlyParameter <int>();

            parameter.SetConstant(10);
            Assert.AreEqual(10, parameter.Value[Month.January]);
            Assert.AreEqual(10, parameter.Value[Month.December]);
        }
Пример #2
0
        private IMonthlyParameter <int> SetDictionary(string name, int value)
        {
            var result = new MonthlyParameter <int> {
                Name = name
            };

            foreach (Month month in Enum.GetValues(typeof(Month)))
            {
                result.Value[month] = value;
            }
            return(result);
        }
        public static IGlobal <decimal> ToModel(this Parameter parameter)
        {
            var context = new DisneyHCMLatamPlanningEntities();

            var global = new Global <decimal>
            {
                Name          = parameter.Name,
                Description   = parameter.Description,
                Id            = parameter.ParameterId,
                IsModifiable  = parameter.IsModifiable,
                IsAccumulator = parameter.IsAccumulator,
                IsConstant    = parameter.IsConstant,
                ParameterType = (FromDisney.ParameterType)parameter.ParameterTypeId,
                Company       = (context.Companies.FirstOrDefault(p => p.CompanyID == parameter.CompanyId).ToModel()),
                Value         = ForecastDataAccessService.SetDictionaryFromValue(0),
                TableName     = parameter.TableName,
                ColumnName    = parameter.ColumnName,
                FixedValue    = parameter.FixedValue,
            };

            if (parameter.ParameterDataTypeID.HasValue)
            {
                global.ParameterDataTypeId = parameter.ParameterDataTypeID.Value;
            }

            if (global.ParameterType == FromDisney.ParameterType.Constant)
            {
                global.MonthlyParameter = new List <MonthlyParameter <decimal> >();

                var monthlyValues = context.ParameterValues
                                    .Include("ParameterMonthValues.ParameterValue.FiscalYear")
                                    .Where(p => p.ParameterId == parameter.ParameterId)
                                    .ToList();

                monthlyValues.ForEach(x =>
                {
                    var monthlyParameter = new MonthlyParameter <decimal>
                    {
                        FiscalYearId   = x.FiscalYear.FiscalYearID,
                        FiscalYearCode = x.FiscalYear.Code,
                        Value          = new Dictionary <Month, decimal>()
                    };

                    for (int i = 1; i <= 12; i++)
                    {
                        decimal value = 0;

                        var result = x.ParameterMonthValues.FirstOrDefault(y => y.Month == i);
                        //try
                        //{
                        //    value = x.ParameterMonthValues.ToList()[i - 1].Value;
                        //}
                        //catch (Exception)
                        //{
                        //    value = 0;
                        //}

                        monthlyParameter.Value.Add((Month)i, result == null ? 0: result.Value);
                    }

                    global.MonthlyParameter.Add(monthlyParameter);
                });
            }

            return(global);
        }
        public static Concept <decimal> ToModel(this Concept conceptDb)
        {
            var concept = new Concept <decimal>(conceptDb.Operation)
            {
                Id          = conceptDb.ConceptId,
                Description = conceptDb.Description,
                GLAccountId = conceptDb.GLAccountID,
                Title       = conceptDb.Title,
                Sequence    = conceptDb.Sequence
            };

            //var parameters = new List<IMonthlyParameter<decimal>>();

            if (conceptDb.Output1 != null)
            {
                concept.Output1 = new Global <decimal>()
                {
                    Id            = conceptDb.Output1.ParameterId,
                    Name          = conceptDb.Output1.Name,
                    ParameterType = (FromDisney.ParameterType)conceptDb.Output1.ParameterTypeId
                };

                //parameters.Add(concept.Output1);
            }

            if (conceptDb.Output2 != null)
            {
                concept.Output2 = new Global <decimal>()
                {
                    Id            = conceptDb.Output2.ParameterId,
                    Name          = conceptDb.Output2.Name,
                    ParameterType = (FromDisney.ParameterType)conceptDb.Output2.ParameterTypeId
                };
                //parameters.Add(concept.Output2);
            }

            if (conceptDb.Parameter1 != null)
            {
                concept.Parameter1 = new Global <decimal>()
                {
                    Id            = conceptDb.Parameter1.ParameterId,
                    Name          = conceptDb.Parameter1.Name,
                    Description   = conceptDb.Parameter1.Description,
                    ParameterType = (FromDisney.ParameterType)conceptDb.Parameter1.ParameterTypeId
                };
                //parameters.Add(concept.Parameter1);
            }

            if (conceptDb.Parameter2 != null)
            {
                concept.Parameter2 = new Global <decimal>()
                {
                    Id            = conceptDb.Parameter2.ParameterId,
                    Name          = conceptDb.Parameter2.Name,
                    Description   = conceptDb.Parameter2.Description,
                    ParameterType = (FromDisney.ParameterType)conceptDb.Parameter2.ParameterTypeId
                };
                //parameters.Add(concept.Parameter2);
            }

            if (conceptDb.Parameter3 != null)
            {
                concept.Parameter3 = new Global <decimal>()
                {
                    Id            = conceptDb.Parameter3.ParameterId,
                    Name          = conceptDb.Parameter3.Name,
                    Description   = conceptDb.Parameter3.Description,
                    ParameterType = (FromDisney.ParameterType)conceptDb.Parameter3.ParameterTypeId
                };
                //parameters.Add(concept.Parameter3);
            }

            if (conceptDb.Parameter4 != null)
            {
                concept.Parameter4 = new Global <decimal>()
                {
                    Id            = conceptDb.Parameter4.ParameterId,
                    Name          = conceptDb.Parameter4.Name,
                    Description   = conceptDb.Parameter4.Description,
                    ParameterType = (FromDisney.ParameterType)conceptDb.Parameter4.ParameterTypeId
                };
                //parameters.Add(concept.Parameter4);
            }

            if (conceptDb.GLAccount != null)
            {
                concept.GLAccount = new Core.GLAccount
                {
                    Title   = conceptDb.GLAccount.Title,
                    SAPCode = conceptDb.GLAccount.SAPCode,
                };
            }

            if (conceptDb.ExpenseType != null)
            {
                concept.ExpenseType = new Engine.Core.ExpenseType
                {
                    Id          = conceptDb.ExpenseType.ExpenseTypeId,
                    Code        = conceptDb.ExpenseType.Code,
                    Description = conceptDb.ExpenseType.Description,
                    IsActive    = conceptDb.ExpenseType.IsActive
                };

                if (conceptDb.ExpenseType.ExpenseGroup != null)
                {
                    concept.ExpenseType.ExpenseGroup = new Engine.Core.ExpenseGroup
                    {
                        Id          = conceptDb.ExpenseType.ExpenseGroup.ExpenseGroupId,
                        Code        = conceptDb.ExpenseType.ExpenseGroup.Code,
                        Description = conceptDb.ExpenseType.ExpenseGroup.Description,
                        IsActive    = conceptDb.ExpenseType.ExpenseGroup.IsActive
                    };
                }
            }

            var cvm = conceptDb.ConceptsValidMonths.OrderBy(m => m.MonthId).ToList();

            concept.ValidMonths = new Dictionary <Month, bool>
            {
                { Month.January, cvm.Any(m => m.MonthId == (int)Month.January) },
                { Month.February, cvm.Any(m => m.MonthId == (int)Month.February) },
                { Month.March, cvm.Any(m => m.MonthId == (int)Month.March) },
                { Month.April, cvm.Any(m => m.MonthId == (int)Month.April) },
                { Month.May, cvm.Any(m => m.MonthId == (int)Month.May) },
                { Month.June, cvm.Any(m => m.MonthId == (int)Month.June) },
                { Month.July, cvm.Any(m => m.MonthId == (int)Month.July) },
                { Month.August, cvm.Any(m => m.MonthId == (int)Month.August) },
                { Month.September, cvm.Any(m => m.MonthId == (int)Month.September) },
                { Month.October, cvm.Any(m => m.MonthId == (int)Month.October) },
                { Month.November, cvm.Any(m => m.MonthId == (int)Month.November) },
                { Month.December, cvm.Any(m => m.MonthId == (int)Month.December) }
            };


            if (conceptDb.ConceptFilters != null)
            {
                foreach (ConceptFilter cf in conceptDb.ConceptFilters)
                {
                    MonthlyParameter <decimal> parameter1 = null, parameter2 = null;

                    if (cf.Filter.Parameter != null)
                    {
                        parameter1 = new MonthlyParameter <decimal>();

                        parameter1.Id            = cf.Filter.Parameter.ParameterId;
                        parameter1.Name          = cf.Filter.Parameter.Name;
                        parameter1.Description   = cf.Filter.Description;
                        parameter1.FixedValue    = cf.Filter.Parameter.FixedValue;
                        parameter1.ParameterType = (FromDisney.ParameterType)cf.Filter.Parameter.ParameterTypeId;
                    }

                    if (cf.Filter.Parameter1 != null)
                    {
                        parameter2 = new MonthlyParameter <decimal>()
                        {
                            Id            = cf.Filter.Parameter1.ParameterId,
                            Name          = cf.Filter.Parameter1.Name,
                            FixedValue    = cf.Filter.Parameter1.FixedValue,
                            ParameterType = (FromDisney.ParameterType)cf.Filter.Parameter1.ParameterTypeId
                        }
                    }
                    ;

                    if (parameter1 != null && parameter2 != null)
                    {
                        IFIlter <bool> filter = new Filter <decimal, bool>
                        {
                            Operation   = new Operation(cf.Filter.Operation),
                            Description = cf.Filter.Description,
                            Sequence    = cf.Sequence,
                            Connector   = new Operation(cf.Connector),
                            Name        = cf.Filter.Title,
                            Id          = cf.FilterId,
                            Parameter1  = parameter1,
                            Parameter2  = parameter2,
                            FilterType  = cf.Filter.FilterType.FilterTypeId
                        };

                        concept.AddFilter(filter);
                    }
                }
            }

            return(concept);
        }