// GET: Store/Details/5
        public ActionResult Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Item item = db.Items.Find(id);
            if (item == null)
            {
                return HttpNotFound();
            }

            var StockEnum = item.Stocks.AsEnumerable();

            InventoryDetailGenerator InventoryGenerator = new InventoryDetailGenerator();
            List<InventoryDetail> inventoryDetails = InventoryGenerator.GetInventoryDetails(item);
            List<SelectListItem> sizeSelections = new List<SelectListItem>();

            foreach (InventoryDetail detail in inventoryDetails)
            {
                IEnumerable<string[]> sizes = detail.GetSizes(); // 1 for W, 1 for L
                string selectText = "";
                if (sizes.Count() > 1)
                {
                    foreach (string[] size in sizes)
                    {
                        selectText += size[0] + ": " + size[1] + " ";
                    }
                }
                else
                {
                    string[] value = sizes.ElementAt(0);
                    selectText += value[1] + " ";
                }
                selectText += "(" + detail.Qty + " Available)";
                sizeSelections.Add(new SelectListItem {
                    Text = selectText,
                    Value = detail.InventoryItemID.ToString()
                    }
                );
            }

            var viewModel = new DetailsAndSizesViewModel
            {
                Item = item,
                SizeString = InventoryGenerator.GetInventoryDetailString(inventoryDetails, true),
                InventoryId = sizeSelections
            };

            return View(viewModel);
        }
        public ActionResult Index()
        {
            var shoppingCart = ShoppingCart.GetCart(this.HttpContext);
            string cartId = shoppingCart.GetCartId(this.HttpContext);

            var viewModel = new ShoppingCartViewModel();
            var carts = webStoreDb.Carts.Where(c => c.CartId == cartId);
            List<CartDetail> details = new List<CartDetail>();
            decimal cartTotal = 0;
            //bool insufficientInventory = false;
            var alertMessages = new List<string>();
            var displayImage = new DisplayImage(DisplayImage.ImageCategory.Clothing);

            foreach (Cart cart in carts)
            {
                Item item = mainDb.Items.Single(i => i.ItemID == cart.ItemId);
                Inventory inventory = mainDb.Inventories.Single(i => i.InventoryID == cart.InventoryId);
                InventoryDetailGenerator inventoryDetailGenerator = new InventoryDetailGenerator();
                List<InventoryDetail> inventoryDetails = inventoryDetailGenerator.GetInventoryDetails(inventory);
                decimal cartDetailTotal = cart.Price * cart.Count;
                bool insufficientInventoryItem = false;
                if (inventory.QuantityInStock < cart.Count)
                {
                    insufficientInventoryItem = true;
                    //insufficientInventory = true;
                    alertMessages.Add("Choose new quantity for " + item.Name + ".");
                }
                details.Add(new CartDetail
                    {
                        RecordId = cart.RecordId,
                        InventoryId = cart.InventoryId,
                        ItemId = cart.ItemId,
                        SubTotal = cart.Price,
                        Quantity = cart.Count,
                        QuantityInStock = inventory.QuantityInStock,
                        Name = item.Name,
                        Size = inventoryDetailGenerator.GetInventoryDetailString(inventoryDetails, false),
                        Picture = displayImage.GetPath(item, true),
                        Total = cartDetailTotal,
                        InventoryFlag = insufficientInventoryItem
                    }
                );
                cartTotal += cartDetailTotal;
            }
            viewModel.Details = details;
            viewModel.CartId = cartId;
            viewModel.Total = cartTotal;
            viewModel.NumItems = shoppingCart.GetCount();
            ViewBag.AlertMessages = alertMessages;

            return View(viewModel);
        }