Beispiel #1
0
        private static ParametricModel MapProductParametric(ProductParametric p, ParametricInfo pi)
        {
            var parametric = new ParametricModel
            {
                Id          = p.Id,
                Name        = p.Name,
                Description = p.Description,
                Uom         = p.Uom,
                IsPrimary   = p.IsPrimary,
                GroupId     = p.GroupId,
                Group       = p.GroupName,
                ValueType   = pi.ValueType,
                Code        = pi.Code,
                Values      = new List <ParametricValueModel>()
            };

            return(parametric);
        }
        private void MapParametrics(ICollection <ParametricModel> parametrics, IEnumerable <IdValue> allParametrics)
        {
            foreach (var p in allParametrics)
            {
                ParametricModel parametricModel;
                var             pi = dictionary.ParametricInfo(p.Id, StormContext.CultureCode);
                if (pi == null)
                {
                    continue;
                }
                var existing = parametrics.SingleOrDefault(x => x.Id == pi.Id);
                if (pi.Type == ParametricType.ListValue || pi.Type == ParametricType.MultiValue)
                {
                    var pv = dictionary.ParametricValue(pi.Type, int.Parse(p.Value), StormContext.CultureCode);
                    if (pv == null)
                    {
                        continue;
                    }
                    var value = new ParametricValueModel
                    {
                        Id          = pv.Id,
                        Name        = pv.Name,
                        Description = pv.Description,
                        Code        = pv.Code,
                        ImageUrl    = GetImageUrl(pv.ImageKey),
                        Value       = pv.Name,
                        SortOrder   = pv.SortOrder
                    };

                    if (existing != null)
                    {
                        if (!existing.Values.Exists(v => v.Id == value.Id))
                        {
                            existing.Values.Add(value);
                        }
                    }
                    else
                    {
                        parametricModel = new ParametricModel
                        {
                            Id          = pi.Id,
                            Name        = pi.Name,
                            Description = pi.Description,
                            Uom         = pi.Uom,
                            ValueType   = pi.ValueType,
                            Code        = pi.Code,
                            Values      = new List <ParametricValueModel> {
                                value
                            }
                        };
                        parametrics.Add(parametricModel);
                    }
                }
                else
                {
                    if (existing != null)
                    {
                        if (!existing.Values.Exists(v => v.Value == p.Value))
                        {
                            existing.Values.Add(new ParametricValueModel {
                                Value = p.Value
                            });
                        }
                    }
                    else
                    {
                        parametricModel = new ParametricModel
                        {
                            Id          = pi.Id,
                            Name        = pi.Name,
                            Description = pi.Description,
                            Uom         = pi.Uom,
                            ValueType   = pi.ValueType,
                            Code        = pi.Code,
                            Values      = new List <ParametricValueModel> {
                                new ParametricValueModel {
                                    Value = p.Value
                                }
                            }
                        };
                        parametrics.Add(parametricModel);
                    }
                }
            }

            parametrics.ForEach(p => p.Values.Sort((p1, p2) => p1.SortOrder.CompareTo(p2.SortOrder)));
        }