Beispiel #1
0
        private void AddParametrics(FilterMultiItem filterItem)
        {
            var id = int.Parse(filterItem.Id);
            var pi = dictionary.ParametricInfo(id, StormContext.CultureCode);

            var type   = MapParametricType(pi);
            var filter = new FilterModel(id, type, pi.ValueType, pi.Name, pi.Description, pi.Uom);

            filters.Add(filter);

            foreach (FilterItem item in filterItem.Items)
            {
                var pid   = int.Parse(item.Id);
                var pv    = dictionary.ParametricValue(pi.Type, pid, StormContext.CultureCode);
                var value = new FilterValueModel <int>
                {
                    Id          = pv.Id,
                    Value       = pv.Id,
                    Name        = pv.Name,
                    Description = pv.Description,
                    Code        = pv.Code,
                    SortOrder   = pv.SortOrder,
                    ImageUrl    = GetImageUrl(pv.ImageKey),
                    Count       = item.Count
                };
                filter.Values.Add(value);
            }
        }
        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)));
        }
Beispiel #3
0
        private ParametricModel MapParametric(ProductParametric p)
        {
            var parametricInfo = dictionary.ParametricInfo(p.Id, StormContext.CultureCode);

            if (parametricInfo.Type == ParametricType.ListValue)
            {
                if (p.ValueId == null)
                {
                    return(null);
                }

                var parametric      = MapProductParametric(p, parametricInfo);
                var parametricValue = dictionary.ParametricValue(parametricInfo.Type, p.ValueId.Value, StormContext.CultureCode);
                if (parametricValue == null)
                {
                    return(parametric);
                }
                var value = MapProductParametricValue(parametricValue);
                parametric.Values.Add(value);
                return(parametric);
            }

            if (parametricInfo.Type == ParametricType.MultiValue)
            {
                if (string.IsNullOrWhiteSpace(p.ValueIdSeed))
                {
                    return(null);
                }
                var parametric = MapProductParametric(p, parametricInfo);
                foreach (var v in p.ValueIdSeed.Split(','))
                {
                    int id;
                    if (!int.TryParse(v, out id))
                    {
                        return(null);
                    }
                    var parametricValue = dictionary.ParametricValue(parametricInfo.Type, id, StormContext.CultureCode);
                    if (parametricValue == null)
                    {
                        continue;
                    }
                    var value = MapProductParametricValue(parametricValue);
                    parametric.Values.Add(value);
                }
                return(parametric);
            }

            if (p.ValueId.HasValue)
            {
                var value = new ParametricValueModel {
                    Id = p.ValueId.Value, Value = p.Value2 ?? "",
                };
                var parametric = MapProductParametric(p, parametricInfo);
                parametric.Values.Add(value);
                return(parametric);
            }
            else
            {
                var value = new ParametricValueModel {
                    Value = p.Value2 ?? ""
                };
                var parametric = MapProductParametric(p, parametricInfo);
                parametric.Values.Add(value);
                return(parametric);
            }
        }