public void Update(TodoItem item)
 {
     var todoItem = Find(item.ID);
     var index = _todoList.IndexOf(todoItem);
     _todoList.RemoveAt(index);
     _todoList.Insert(index, item);
 }
        private void InitializeData()
        {
            _todoList = new List<TodoItem>();

            var todoItem1 = new TodoItem
            {
                ID = "6bb8a868-dba1-4f1a-93b7-24ebce87e243",
                Name = "Learn app development",
                Notes = "Attend Xamarin University",
                Done = true
            };

            var todoItem2 = new TodoItem
            {
                ID = "b94afb54-a1cb-4313-8af3-b7511551b33b",
                Name = "Develop apps",
                Notes = "Use Xamarin Studio/Visual Studio",
                Done = false
            };

            var todoItem3 = new TodoItem
            {
                ID = "ecfa6f80-3671-4911-aabe-63cc442c1ecf",
                Name = "Publish apps",
                Notes = "All app stores",
                Done = false,
            };

            _todoList.Add(todoItem1);
            _todoList.Add(todoItem2);
            _todoList.Add(todoItem3);
        }
        public void EditTodoItem(TodoItem item)
        {
            try
            {
                if (item == null ||
                    string.IsNullOrWhiteSpace(item.Name) ||
                    string.IsNullOrWhiteSpace(item.Notes))
                {
                    throw new FaultException("TodoItem name and notes fields are required");
                }

                var todoItem = todoService.Find(item.ID);
                if (todoItem != null)
                {
                    todoService.UpdateData(item);
                }
                else
                {
                    throw new FaultException("TodoItem not found");
                }
            }
            catch (Exception ex)
            {
                throw new FaultException(string.Format("Error: {0}", ex.Message));
            }
        }
        public void UpdateData(TodoItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            _repository.Update(item);
        }
        public void InsertData(TodoItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            _repository.Insert(item);
        }
        public void CreateTodoItem(TodoItem item)
        {
            try
            {
                if (item == null ||
                    string.IsNullOrWhiteSpace(item.Name) ||
                    string.IsNullOrWhiteSpace(item.Notes))
                {
                    throw new FaultException("TodoItem name and notes fields are required");
                }

                // Determine if the ID already exists
                var itemExists = todoService.DoesItemExist(item.ID);
                if (itemExists)
                {
                    throw new FaultException("TodoItem ID is in use");
                }
                todoService.InsertData(item);
            }
            catch (Exception ex)
            {
                throw new FaultException(string.Format("Error: {0}", ex.Message));
            }
        }
 public void Insert(TodoItem item)
 {
     _todoList.Add(item);
 }