public void Add(Todo todo)
 {
     Todos[todo.Id] = todo.Clone();
     todo           = Todos[todo.Id]; // Get cloned copy
     if (todo.TodoComments != null)
     {
         foreach (var c in todo.TodoComments)
         {
             TodoComments[c.Id] = c;
         }
     }
 }
Exemple #2
0
        public Task <Todo> Add(Todo todo)
        {
            if (todo.Id != null)
            {
                throw new InvalidOperationException("New Todo ID must be null. ID will be assigned by the repository.");
            }

            int id = Interlocked.Increment(ref m_nextId);

            var repositoryTodo = todo.Clone();

            repositoryTodo.Id = id;

            if (!repositoryTodo.Completed.HasValue)
            {
                repositoryTodo.Completed = false;
            }

            m_todos[id] = repositoryTodo;

            return(Task.FromResult(repositoryTodo));
        }