public ActionResult GetTodosById(int id)
        {
            var userId = User.Claims.ToList()[0].Value;
            var Todo   = AllTodos.FirstOrDefault(i => i.Id == id && i.Author.Id == userId || i.Members.Any(i => i.Id == userId));

            if (Todo != null)
            {
                return(Ok(Todo));
            }

            return(Ok(null));
        }
        public IEnumerable <Tags> GetTagsById(int id)
        {
            var userId = User.Claims.ToList()[0].Value;
            var list   = AllTodos.FirstOrDefault(i => i.Id == id);

            if (list != null)
            {
                var tags = AllTags.Where(t => t.TodoId == list.Id).ToList();
                return(tags);
            }

            return(null);
        }
        public ActionResult TodoIsCompleted(int todoId)
        {
            var userId = User.Claims.ToList()[0].Value;
            var Todo   = AllTodos.FirstOrDefault(i => i.Id == todoId && i.Author.Id == userId);

            if (Todo != null)
            {
                Todo.IsComplete = true;
                if (_context.SaveChanges() > 0)
                {
                    return(Ok(true));
                }
            }

            return(Ok(false));
        }
        public IActionResult PostANewTagToTodo(Tags model)
        {
            var userId = User.Claims.ToList()[0].Value;
            var todo   = AllTodos.FirstOrDefault(i => i.Id == model.TodoId && i.Author.Id == userId);

            if (todo != null)
            {
                _context.TagsItems.Add(model);
                if (_context.SaveChanges() > 0)
                {
                    return(Ok(true));
                }
            }

            return(Ok(false));
        }
        public ActionResult UpdateTodoListWithId(int id, TodoModel model)
        {
            var Todo   = AllTodos.FirstOrDefault(i => i.Id == id);
            var userId = User.Claims.ToList()[0].Value;

            if (Todo != null && Todo.Author.Id == userId)
            {
                Todo.Name        = model.Name;
                Todo.Description = model.Description;
                if (_context.SaveChanges() > 0)
                {
                    return(Ok(true));
                }
            }

            return(Ok(false));
        }
        public ActionResult AddNewMemberToList(int id, string user_id)
        {
            var Todo   = AllTodos.FirstOrDefault(x => x.Id == id);
            var userId = User.Claims.ToList()[0].Value;

            if (Todo != null && Todo.Author.Id == userId)
            {
                var member = _context.Users.FirstOrDefault(x => x.Id == user_id);
                if (member != null)
                {
                    Todo.Members.Add(member);
                    if (_context.SaveChanges() > 0)
                    {
                        return(Ok(true));
                    }
                }
            }
            return(Ok(false));
        }
        public ActionResult DeleteTodo(int id)
        {
            var userId = User.Claims.ToList()[0].Value;
            var todo   = AllTodos.FirstOrDefault(x => x.Id == id && x.Author.Id == userId);

            if (todo != null)
            {
                var tags = AllTags.Where(x => x.TodoId == todo.Id).ToList();
                if (tags.Count > 0)
                {
                    for (var i = 0; i < tags.Count; i++)
                    {
                        _context.TagsItems.Remove(tags[i]);
                    }
                }
                _context.TodoItems.Remove(todo);
                if (_context.SaveChanges() > 0)
                {
                    return(Ok(true));
                }
            }
            return(Ok(false));
        }