public async Task <IActionResult> PostShoppingList([FromBody] APIShoppingList shoppingList, CancellationToken ct) { if (!ModelState.IsValid) { return(BadRequest(new { error = "Model state is not valid" })); } var currentUser = HttpContext.User; var userclaim = currentUser.Claims.First(); var userId = Guid.Parse(userclaim.Value); var shoppingUser = await _shoppingUserRepository.GetEntityAsync(userId, ct); if (shoppingUser != null) { ShoppingListEntity list = new ShoppingListEntity { Name = shoppingList.Name, ShoppingUserId = shoppingUser.Id, StoreId = shoppingUser.HomeStoreId, TimeOfCreation = DateTimeOffset.UtcNow }; var listAdded = await _shoppingListRepository.AddShoppingList(list, ct); if (listAdded.Item1) { shoppingUser.ShoppingLists.Add(list); var user = await _shoppingUserRepository.UpdateEntity(shoppingUser, ct); return(Ok(new ShoppingList { Id = list.Id, Items = new List <ShoppingListItem>(), Name = list.Name, TimeOfCreation = list.TimeOfCreation, TotalCost = 0, TotalItems = 0 })); } else { return(BadRequest(new { error = listAdded.Item2 })); } } return(BadRequest(new { error = "Could not find shopping user" })); }