Advertisement
Guest User

Untitled

a guest
May 25th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. public class TodoRepository : ITodoRepository
  2. {
  3. private readonly List<ToDo> _items;
  4.  
  5. public TodoRepository()
  6. {
  7. _items = new List<ToDo>();
  8. }
  9.  
  10. public Task<bool> UpsertTodoItemsAsync(IEnumerable<ToDo> items)
  11. {
  12. var itemsToUpsert = items?.ToList() ?? new List<ToDo>();
  13.  
  14. if (!itemsToUpsert.Any())
  15. {
  16. return Task.FromResult(false);
  17. }
  18.  
  19. foreach (var item in itemsToUpsert)
  20. {
  21. var indexOf = _items.FindIndex(x => x.Id == item.Id);
  22. if (indexOf < 0)
  23. {
  24. _items.Add(item);
  25. }
  26. else
  27. {
  28. _items[indexOf] = item;
  29. }
  30. }
  31.  
  32. return Task.FromResult(true);
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement