public IActionResult Index() { var user = _userManager.GetUserAsync(User).Result.Id; var cart = _repository.GetCartByUserId(user); if (cart == null) { return(View(null)); } else { var cartItem = _repository.GetCartItemByCartId(cart.Id); cart.CartItem = cartItem; var viewModel = new CartViewModel { Cart = cart }; return(View(viewModel)); } }
public async Task <IActionResult> Index() { var user = await _userManager.GetUserAsync(User); var countries = _repository.GetCountries(); var cart = _repository.GetCartByUserId(user.Id); var cartItem = _repository.GetCartItemByCartId(cart.Id); cart.CartItem = cartItem; if (cart == null || cart.CartItem.Count <= 0) { return(RedirectToAction("Index", "Cart")); } foreach (var c in cartItem) { if (c.Size == "Odaberite veličinu") { return(RedirectToAction("Index", "Cart")); } } var viewModel = new CheckoutViewModel() { FirstName = user.FirstName, LastName = user.LastName, Address = user.Address, PostalNumber = user.PostalNumber, City = user.City, PhoneNumber = user.PhoneNumber, CountryId = user.CountryId, Country = countries, Cart = cart }; return(View(viewModel)); }