コード例 #1
0
        public static List <CartAttributeViewModel> GetCartItems(int cartId)
        {
            List <CartAttributeViewModel> response        = new List <CartAttributeViewModel>();
            List <CartItemOption>         cartItemOptions = new List <CartItemOption>();
            Cart cart = GetCart(cartId);

            if (cart != null)
            {
                using (EcommerceEntities entities = new EcommerceEntities())
                {
                    List <GetCartItemsByCartId_Result> cartItems = entities.GetCartItemsByCartId(cartId).ToList();
                    foreach (var cartitem in cartItems)
                    {
                        ProductAtrributeOptionsViewModel        productAtrributeViewModel     = null;
                        List <ProductAtrributeOptionsViewModel> productAtrributeViewModelList = new List <ProductAtrributeOptionsViewModel>();
                        CartAttributeViewModel viewModel      = new CartAttributeViewModel();
                        CartItemOption         cartItemOption = new CartItemOption();
                        viewModel.cartItem = cartitem;
                        cartItemOptions    = entities.CartItemOptions.Where(entry => entry.CartItemID == cartitem.ID).ToList();
                        foreach (var cartOption in cartItemOptions)
                        {
                            productAtrributeViewModel = new ProductAtrributeOptionsViewModel();
                            ProductAttributeOption optionDb           = new ProductAttributeOption();
                            OptionList             option             = new OptionList();
                            List <OptionList>      optionList         = new List <OptionList>();
                            ProductAttribute       productAttributeDb = new ProductAttribute();
                            optionDb           = entities.ProductAttributeOptions.Where(entry => entry.ID == cartOption.OptionsID).FirstOrDefault();
                            productAttributeDb = entities.ProductAttributes.Where(entry => entry.ID == optionDb.ProductAtrributeID).FirstOrDefault();
                            option.optionId    = Convert.ToInt32(cartOption.OptionsID);
                            option.optionName  = optionDb.Value;
                            optionList.Add(option);
                            productAtrributeViewModel.attributeId   = Convert.ToInt32(productAttributeDb.ID);
                            productAtrributeViewModel.attributeName = productAttributeDb.Name;
                            productAtrributeViewModel.optionList    = optionList;
                            productAtrributeViewModelList.Add(productAtrributeViewModel);
                        }
                        viewModel.options = productAtrributeViewModelList;
                        response.Add(viewModel);
                    }
                }
            }
            return(response);
        }