Compare commits
2 Commits
b3b4562f21
...
bf588c62ed
Author | SHA1 | Date | |
---|---|---|---|
|
bf588c62ed | ||
|
dfb2838565 |
@ -84,7 +84,13 @@ namespace API.BusinessLogic
|
|||||||
|
|
||||||
user.ShoppingList.Add(newItem);
|
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
|
// 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" });
|
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