/// <summary> /// Todo.Id is not needed to be specified; it will be set/handled internally /// </summary> /// <param name="userId"></param> /// <param name="todo"></param> Todo IUserRepository.AddTodo(int userId, Todo todo) { if (todo == null) { throw new ArgumentNullException("todo"); } User user = iUserRepository.Get(userId); lock (user) { todo.Id = user.Todos.Count() + 1; user.Todos.Add(todo); } return todo; }
public HttpResponseMessage PostTodo(int userId, Todo todo) { Todo addedTodo = DbUserRepository.AddTodo(userId, todo); var response = this.Request.CreateResponse<Todo>(HttpStatusCode.Created, addedTodo); return response; }