SHARE
TWEET

Untitled

a guest May 25th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top