public IEnumerable <ShoppingCartItemViewModel> GetAll()
        {
            IEnumerable <ShoppingCartItem> shoppingCartItems = _shoppingCartItemService.Search(x => x.Active == true);

            List <ShoppingCartItemViewModel> shoppingCartItemViewModels = new List <ShoppingCartItemViewModel>();

            if (shoppingCartItems != null)
            {
                foreach (var shoppingCart in shoppingCartItems)
                {
                    shoppingCartItemViewModels.Add(new ShoppingCartItemViewModel(shoppingCart));
                }
            }

            return(shoppingCartItemViewModels);
        }
Beispiel #2
0
        public IEnumerable <ShoppingCartItemViewModel> GetItemsByCartNumber(int cartNumber)
        {
            ShoppingCart shoppingCart = _shoppingCartService.Search(x => x.Number == cartNumber).FirstOrDefault();

            ShoppingCartViewModel shoppingCartViewModel = new ShoppingCartViewModel();

            if (shoppingCart != null)
            {
                shoppingCartViewModel = new ShoppingCartViewModel(shoppingCart);
            }

            if (shoppingCartViewModel == null)
            {
                Add(new ShoppingCartViewModel {
                    Number = cartNumber
                });

                shoppingCart = _shoppingCartService.Search(x => x.Number == cartNumber).FirstOrDefault();

                shoppingCartViewModel = new ShoppingCartViewModel(shoppingCart);
            }

            IEnumerable <ShoppingCartItem> items = _shoppingCartItemService.Search(x => x.ShoppingCart.Number == cartNumber);

            List <ShoppingCartItemViewModel> itemsViewModels = new List <ShoppingCartItemViewModel>();

            if (items != null)
            {
                foreach (var item in items)
                {
                    itemsViewModels.Add(new ShoppingCartItemViewModel(item));
                }
            }

            foreach (var item in itemsViewModels)
            {
                item.Name = _productService.GetById(item.ProductId).Name;
            }

            return(itemsViewModels);
        }
        public IEnumerable <ShoppingCartItemViewModel> GetItemsByCartNumber(int cartNumber)
        {
            ShoppingCartViewModel shoppingCartViewModel = Mapper.Map <ShoppingCart, ShoppingCartViewModel>(_shoppingCartService.Search(x => x.Number == cartNumber)
                                                                                                           .FirstOrDefault());

            if (shoppingCartViewModel == null)
            {
                Add(new ShoppingCartViewModel {
                    Number = cartNumber
                });

                shoppingCartViewModel = Mapper.Map <ShoppingCart, ShoppingCartViewModel>(_shoppingCartService.Search(x => x.Number == cartNumber).FirstOrDefault());
            }

            IEnumerable <ShoppingCartItemViewModel> itemsViewModel =
                Mapper.Map <IEnumerable <ShoppingCartItem>, IEnumerable <ShoppingCartItemViewModel> >(_shoppingCartItemService.Search(x => x.ShoppingCart.Number == cartNumber));

            foreach (var item in itemsViewModel)
            {
                item.Name = _productService.GetById(item.ProductId).Name;
            }

            return(itemsViewModel);
        }
Beispiel #4
0
 public IEnumerable <ShoppingCartItemViewModel> GetAll()
 {
     return(Mapper.Map <IEnumerable <ShoppingCartItem>, IEnumerable <ShoppingCartItemViewModel> >(_shoppingCartItemService.Search(x => x.Active == true)));
 }