public async Task <IActionResult> Put(Guid itemId, int?count) { var product = await _repository.GetAsync(itemId); if (product != null) { if (User.Identity.IsAuthenticated) { var cartId = (await _context.Carts.FirstOrDefaultAsync(c => c.AppUserId == _userManager.GetUserId(User))).Id; if (product != null && cartId != null) { await _productsRepository.AddAsync(cartId, product, count ??= 1); return(Ok()); } } // карт всегда пустой, надо чекнуть дессириализатор var cartProducts = HttpContext.Session.Get <List <CartProducts> >("productsList"); if (cartProducts == null) { cartProducts = new List <CartProducts>(); } var cartProduct = cartProducts.FirstOrDefault(i => i.Product.Id == product.Id); if (cartProduct == null) { cartProducts.Add(new CartProducts { Cart = new Cart(), Product = product, Count = count ??= 1 });
public async Task <IActionResult> Get() => Ok(await _repository.GetAsync());
public async Task <IActionResult> Get() { return(Ok(await _repository.GetAsync())); }