public async Task <UpdateCartItemBm> UpdateAsync(UpdateCartItemBm model) { model.CartId = await GetCurrentCartIdByUserIdAsync(model.UserId); model = await UpdateQuantityAsync(model); return(model); }
private async Task <UpdateCartItemBm> UpdateQuantityAsync(UpdateCartItemBm model) { foreach (var cartItem in model.CartItems) { var entity = await DbContext .CartItems .Where(ci => ci.CartId == model.CartId && ci.ProductId == cartItem.ProductId && ci.IsDeleted == false) .FirstOrDefaultAsync(); entity.Quantity = cartItem.Quantity; DbContext.CartItems.Update(entity); await DbContext.SaveChangesAsync(); } return(model); }