Returns the added item in the shoppinglist

This commit is contained in:
Jeas0001 2025-05-08 10:22:43 +02:00
parent 050ff896e1
commit dfb2838565
2 changed files with 19 additions and 1 deletions

View File

@ -84,7 +84,13 @@ namespace API.BusinessLogic
user.ShoppingList.Add(newItem);
}
return await _dbAccess.UpdateShoppingList(user);
bool succes = await _dbAccess.AddItemToShoppingList(user);
var updatedShoppingList = await _dbAccess.ReadShoppingList(userId);
if (succes) { return new OkObjectResult(updatedShoppingList.ShoppingList.Where(s => s.Name == listItemDTO.Name)); }
return new ConflictObjectResult(new { message = "Could not save to database" });
}
// Gets the shoppinglist and tries to find the item and when it does it checks/unchecks that item

View File

@ -34,5 +34,17 @@ namespace API.DBAccess
return new ConflictObjectResult(new { message = "Could not save to database" });
}
// Adds an item to the shoppinglist
public async Task<bool> AddItemToShoppingList(User user)
{
_context.Entry(user).State = EntityState.Modified;
bool saved = await _context.SaveChangesAsync() >= 1;
if (saved) { return true; }
return false;
}
}
}