Beispiel #1
0
        /// <summary>
        /// Add new todo item in database
        /// </summary>
        /// <param name="newTodo">new item</param>
        /// <returns>result of adding</returns>
        public Todo AddTodo(Todo newTodo)
        {
            _context.Todos.Add(newTodo);
            _context.SaveChanges();

            //Get created task form datebase
            var todo = _context.Todos.FirstOrDefault(item => item.Text.Equals(newTodo.Text));
            return todo;
        }
Beispiel #2
0
 public Todo Udate(Todo item)
 {
     return _repository.UpdateTodo(item);
 }
Beispiel #3
0
        /// <summary>
        /// Update todo 
        /// </summary>
        /// <param name="newTodo">new state</param>
        /// <returns>result of ubdating</returns>
        public Todo UpdateTodo(Todo newTodo)
        {
            var todo = _context.Todos.Find(newTodo.TodoId);
            if (todo != null)
            {
                if (todo.IsDone != newTodo.IsDone)//change state of todo
                {
                    todo.IsDone = newTodo.IsDone;

                    if (todo.IsDone)
                    {
                        //change state of all subtodos to true
                        todo.SubTodos.Where(i => i.IsDone == false).ToList().ForEach(subtodo => subtodo.IsDone = true);
                    }
                    else
                    {
                        //change state of all subtodos to false
                        todo.SubTodos.Where(i => i.IsDone == true).ToList().ForEach(subtodo => subtodo.IsDone = false);
                    }
                }

                _context.SaveChanges();
            }

            return todo;
        }
Beispiel #4
0
 public Todo Add(Todo item)
 {
     return _repository.AddTodo(item);
 }