Ejemplo n.º 1
0
        public OptionDB(JArray options)
        {
            this.options = new Dictionary <String, OptionList>();

            foreach (var obj in options)
            {
                var option = new OptionList(
                    name: (String)obj["title"],
                    values: obj["values"].ToObject <IList <String> >()
                    );
                // Will throw exception if already exists
                this.options.Add(option.Name, option);
                Debug.WriteLine($"Loaded optionlist {option.Name}");
            }
        }
Ejemplo n.º 2
0
        public Product(String id, JObject obj, OptionDB db, Category category,
                       FileData fileData, String sourceDir)
        {
            this.Id          = id;
            this.Name        = (string)obj["name"];
            this.SubCategory = (string)obj["subcategory"];
            this.Price       = Decimal.Parse((string)obj["price"]);
            this.Weight      = Decimal.Parse((string)obj["weight"]);
            this.options     = new List <ProductOption>();
            this.extraImages = new List <String>();
            this.Category    = category;
            this.Description = fileData.GetProductDescriptionHTML(sourceDir);
            this.fileData    = fileData;
            this.sourceDir   = sourceDir;

            Trace.Assert(this.Price >= 0);
            Trace.Assert(this.Weight >= 0);
            Trace.Assert(Extensions.GetDecimalPlaces(this.Price) == 2);
            Trace.Assert(Extensions.GetDecimalPlaces(this.Weight) == 2);
            Trace.Assert(!String.IsNullOrWhiteSpace(this.Id));
            Trace.Assert(!String.IsNullOrWhiteSpace(this.Name));
            Trace.Assert(!String.IsNullOrWhiteSpace(this.Description));
            Trace.Assert(this.Category != null);
            //Trace.Assert(!String.IsNullOrWhiteSpace(this.subcategory));

            for (var i = 0; i < 10; i++)
            {
                var label = (string)obj[$"on{i}"];
                if (label != null)
                {
                    var        optionlist_name = (string)obj[$"os{i}"];
                    OptionList ol = null;
                    if (optionlist_name != null)
                    {
                        ol = db.GetOptionList(optionlist_name);
                    }
                    options.Add(new ProductOption(label, ol));
                }
            }

            string images = (string)obj["extra_images"];

            if (images != null)
            {
                var split_images = images.Split(null);
                this.extraImages.AddRange(split_images);
            }
        }
Ejemplo n.º 3
0
 public ProductOption(String label, OptionList optionList)
 {
     Trace.Assert(!String.IsNullOrWhiteSpace(label));
     this.Label      = label;
     this.OptionList = optionList;
 }