/// <summary> /// Changes a ToDoItem inside collection, unless it does not exist. Then it adds given item. /// Perhaps not an ideal solution, wait for next patch... /// </summary> /// <param name="todoItem"></param> public void Update(TodoItem toDoItem) { if (Get(toDoItem.Id) != null) { _inMemoryToDoDatabase.RemoveAt(_inMemoryToDoDatabase.IndexOf(toDoItem)); } Add(toDoItem); }
public TodoItem Update(TodoItem todoItem) { int index = _inMemoryTodoDatabase.IndexOf(todoItem); TodoItem a = _inMemoryTodoDatabase.GetElement(index); if (_inMemoryTodoDatabase.Contains(todoItem)) { a = todoItem; _inMemoryTodoDatabase.RemoveAt(index); } _inMemoryTodoDatabase.Add(a); return(todoItem); }
public TodoItem Get(Guid todoId) { var temp = _inMemoryTodoDatabase.FirstOrDefault(s => s.Id == todoId); int pom = _inMemoryTodoDatabase.IndexOf(temp); if (pom >= 0) { return(_inMemoryTodoDatabase.GetElement(pom)); } else { return(null); } }
public bool Remove(Guid todoId) { /// <summary > /// Tries to remove a TodoItem with given id from the database . /// </ summary > /// <returns > True if success , false otherwise </ returns > TodoItem temp = _inMemoryTodoDatabase.Where(o => o.Id.Equals(todoId)).FirstOrDefault(); if (temp != null) { //int index = _inMemoryTodoDatabase.IndexOf(temp); return(_inMemoryTodoDatabase.RemoveAt(_inMemoryTodoDatabase.IndexOf(temp))); } return(false); //throw new NotImplementedException(); }