public Cart Get() { var userId = _userService.GetCurrentUserId(); var cart = new Cart(); cart.Items.AddRange(_entityContext.Entities.Where(c => c.UserId == userId)); return cart; }
public CartViewModel(Cart cart, IProductRepository productRepository) { _cart = cart; _items = new List<CartItemViewModel>(); foreach( var item in cart.Items ) { var product = productRepository.GetById(item.ProductId); var cartItemViewModel = new CartItemViewModel(item, product); _items.Add(cartItemViewModel); } }