public RecommendationModel(int p_id, SIEBUEntities db = null)
        {
            if (db == null) db = new SIEBUEntities();
            Product p = db.Products.Where(pr => pr.p_id == p_id).FirstOrDefault();
            id = p.p_id;
            store_id = p.store_id;
            name = p.name;
            status = p.Product_Status.st_id;
            description = p.description;
            short_description = p.short_description;
            cost = p.cost.Value;
            shipping_cost = p.shipping_cost.Value;
            avail_inventory = p.avail_inventory.Value;

            images = new List<ProductImageModel>();
            ProductImageModel pim = new ProductImageModel();
            pim.url = p.Product_Image.Count == 0 ? "/content/no-image" : p.Product_Image.OrderBy(pi => pi.sort).FirstOrDefault().url;
            images.Add(pim);

            if (p.dateadded.HasValue)
                dateadded = String.Format("{0:MMMM d, yyyy}", p.dateadded.Value);
            else dateadded = "N/A";

            store = new StoreModel();
            store.name = p.Store.name;
            store.store_namespace = p.Store.name_space;
        }
        public ProductModel(Product p, Boolean expanded = true, SIEBUEntities db = null)
        {
            if (db == null) db = new SIEBUEntities();
            id = p.p_id;
            sku = (p.sku == null ? p.p_id.ToString() : p.sku);
            store_id = p.store_id;
            name = p.name;
            status = p.status;
            status_caption = p.Product_Status.caption;
            cost = Math.Round(p.cost.Value, 2);
            likes = db.Product_Like.Count(pl => pl.product_id == p.p_id);
            avail_inventory = p.avail_inventory.Value;
            short_description = getSummary(p);
            is_featured = (p.is_featured == true);

            if (p.dateadded.HasValue)
                dateadded = String.Format("{0:MMMM d, yyyy}", p.dateadded.Value);
            else dateadded = "N/A";

            if (p.lastmodified.HasValue)
                lastmodified = String.Format("{0:MMMM d, yyyy}", p.lastmodified.Value);
            else lastmodified = "N/A";

            if (expanded)
            {
                description = p.description;
                shipping_cost = Math.Round(p.shipping_cost.Value, 2);

                images = new List<ProductImageModel>();
                for (int i = 0; i < p.Product_Image.Count(); i++)
                {
                    Product_Image pimage = p.Product_Image.OrderBy(pi => pi.sort).Skip(i).Take(1).FirstOrDefault();
                    ProductImageModel pim = new ProductImageModel();
                    pim.id = pimage.pi_id;
                    pim.url = pimage.url;
                    pim.order = (pimage.sort.HasValue ? pimage.sort.Value : i);
                    images.Add(pim);
                }

                tags = new List<ProductTagModel>();
                foreach (Product_Tag tag in db.Product_Tag.Where(pt => pt.product_id == p.p_id))
                {
                    tags.Add(new ProductTagModel(tag.Tag.caption));
                }
            }
            else
            {
                images = new List<ProductImageModel>();
                Product_Image pimg = p.Product_Image.OrderBy(pi => pi.sort).FirstOrDefault();
                ProductImageModel pim = new ProductImageModel();

                if (pimg != null)
                {
                    pim.id = pimg.pi_id;
                    pim.url = pimg.url;
                    pim.order = (pimg.sort.HasValue ? pimg.sort.Value : 0);
                }
                else
                {
                    pim.id = 0;
                    pim.url = "/content/no-image";
                    pim.order = 0;
                }

                images.Add(pim);
            }
        }