Beispiel #1
0
        public static ProductToken AsToken(this Product product)
        {
            string[] sizes = product.size.Split('x');

            var token = new ProductToken
            {
                id                = product.id,
                sku               = product.sku,
                seller_id         = product.seller_id,
                category          = product.category,
                name              = product.name,
                short_description = product.short_description,
                description       = product.description,
                retail_price      = product.retail_price / 100F,
                length            = double.Parse(sizes[0]),
                width             = double.Parse(sizes[1]),
                height            = double.Parse(sizes[2]),
                weight            = product.weight,
                likes_count       = product.likes_count,
                comments          = product.comments == null?Enumerable.Empty <CommentToken>() : product.comments.Reverse().Take(5).Select(c => c.AsToken())
            };

            List <int> indexes = new List <int>();

            for (int i = 0; product.images != null && i < Math.Min(5, product.images.Length); i++)
            {
                if (!string.IsNullOrWhiteSpace(product.images[i]))
                {
                    indexes.Add(i);
                }
            }
            token.image_indexes = indexes.ToArray();

            return(token);
        }
Beispiel #2
0
 public static Product AsProduct(this ProductToken product)
 {
     return(new Product
     {
         id = product.id,
         sku = product.sku,
         seller_id = product.seller_id,
         name = product.name,
         category = product.category,
         short_description = product.short_description,
         description = product.description,
         retail_price = (int)Math.Floor(product.retail_price * 100F),
         size = string.Join("x", product.length, product.width, product.height),
         weight = product.weight,
         is_draft = product.is_draft
     });
 }
Beispiel #3
0
        public static ProductToken AsSimpleToken(this Product product)
        {
            var token = new ProductToken
            {
                id                = product.id,
                name              = product.name,
                category          = product.category,
                short_description = product.short_description,
                sale_id           = product.sale_id
            };

            List <int> indexes = new List <int>();

            for (int i = 0; product.images != null && i < Math.Min(5, product.images.Length); i++)
            {
                if (!string.IsNullOrWhiteSpace(product.images[i]))
                {
                    indexes.Add(i);
                }
            }
            token.image_indexes = indexes.ToArray();

            return(token);
        }