public async Task <IActionResult> Update([FromBody] CartViewModel viewModel) { var user = await userManager.FindByNameAsync(User.Identity.Name).ConfigureAwait(false); var cart = await context.Carts .Where(x => x.UserId == user.Id) .Include(x => x.Items) .ThenInclude(y => y.Product) .ThenInclude(z => z.Mesurement) .FirstOrDefaultAsync() .ConfigureAwait(false); var newCart = updateService.UpdateCart(cart, viewModel, user); if (string.IsNullOrEmpty(newCart.Id)) { context.Carts.Add(newCart); } else { context.Carts.Update(newCart); } await context.SaveChangesAsync().ConfigureAwait(false); return(Ok(CartConverter.Convert(newCart))); }
public async Task <IActionResult> View() { var user = await userManager.FindByNameAsync(User.Identity.Name).ConfigureAwait(false); var cart = await context.Carts .Where(x => x.UserId == user.Id) .Include(x => x.Items) .ThenInclude(y => y.Product) .ThenInclude(z => z.Mesurement) .FirstOrDefaultAsync() .ConfigureAwait(false); if (cart != null) { return(Ok(CartConverter.Convert(cart))); } else { return(NotFound()); } }