Returns the added item in the shoppinglist
This commit is contained in:
parent
050ff896e1
commit
dfb2838565
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user