public Task Put(UpdateTodo request)
        {
            var todo = Todos.FirstOrDefault(x => x.Id == request.Id)
                       ?? throw HttpError.NotFound($"Todo with Id '{request.Id}' does not exit");

            todo.PopulateWith(request);
            return(ServerEvents.NotifyChannelAsync("todos", "todos.update", todo));
        }
Exemplo n.º 2
0
        public void Get(int id, bool isDone = false)
        {
            if (isDone)
            {
                Dones.FirstOrDefault(x => x.Id == id);
            }

            Todos.FirstOrDefault(x => x.Id == id);
        }
Exemplo n.º 3
0
        public Task <bool> Delete(string id)
        {
            var todo = Todos.FirstOrDefault(t => t.Id == id);

            if (todo != null)
            {
                Todos.Remove(todo);
            }
            return(Task.FromResult(todo != null));
        }
Exemplo n.º 4
0
        public void Remove(int id)
        {
            var todo = Todos.FirstOrDefault(x => x.Id == id);

            if (todo == null)
            {
                throw new KeyNotFoundException();
            }

            Todos.Remove(todo);
        }
Exemplo n.º 5
0
        public Task <Todo> Upsert(Todo upsertTodo)
        {
            var todo = Todos.FirstOrDefault(t => t.Id == upsertTodo.Id);

            if (todo == null)
            {
                todo = upsertTodo;
                Todos.Add(todo);
            }
            else
            {
                todo.Description = upsertTodo.Description;
                todo.Done        = upsertTodo.Done;
            }
            return(Task.FromResult(todo));
        }
Exemplo n.º 6
0
        public static void RepeatTask(dynamic metadata, dynamic content)
        {
            var id = content.Id.ToString();
            var repeatIfAllClosed = bool.Parse(content.RepeatIfAllClosed?.ToString() ?? "false");
            var date    = DateTimeOffset.Parse(content.LastGeneratedTime.ToString());
            var hours   = int.Parse(content.Hours.ToString());
            var dateStr = " (" + date.Date.ToShortDateString() + ")";

            TodoItem task = Todos.FirstOrDefault(t => t.Id == id);

            if (task != null)
            {
                var shouldRepeat = !repeatIfAllClosed || !Todos.Where(t => (t.OriginalRepeatId == id || t.Id == id) && t.Status != TodoStatus.Close).Any();
                if (shouldRepeat)
                {
                    AddTaskAndChildrenRepeat(task, task.ParentId, dateStr, hours, id, actionTime: GetCreateDate(metadata));
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="item"></param>
        public async Task Update(Todo item)
        {
            if (item == null)
            {
                return;
            }
            var p = Todos.FirstOrDefault(x => x.Id == item.Id);

            if (p == null)
            {
                Created(item);
                Todos.Add(item);
                DataIndex.Todos.AddUniq(item.Key);
                await Save(DataIndex);
            }
            else
            {
                p.Update(item);
            }
            await Save(item);

            MessageAction?.Invoke(MessageTypeUpdate);
        }
Exemplo n.º 8
0
 static TodoItem FindFirstByCondition(string groupKey, Func <TodoItem, bool> condition) => Todos.FirstOrDefault(t => t.GroupKey == groupKey && condition(t));
 public object Get(GetTodo request) => new GetTodoResponse
 {
     Result = Todos.FirstOrDefault(x => x.Id == request.Id)
 };
Exemplo n.º 10
0
 private bool TodoWithNameExists(string name) => Todos.FirstOrDefault(todo => todo.Name == name) != null;