예제 #1
0
        private ImmutableList <Todo> _store = ImmutableList <Todo> .Empty; // It's always sorted by Id though

        // Commands

        public virtual Task <Todo> AddOrUpdate(AddOrUpdateTodoCommand command, CancellationToken cancellationToken = default)
        {
            var(session, todo) = command;
            if (Computed.IsInvalidating())
            {
                TryGet(session, todo.Id, CancellationToken.None).Ignore();
                PseudoGetAllItems(session).Ignore();
                return(Task.FromResult(default(Todo) !));
            }

            if (string.IsNullOrEmpty(todo.Id))
            {
                todo = todo with {
                    Id = Ulid.NewUlid().ToString()
                }
            }
            ;
            _store = _store.RemoveAll(i => i.Id == todo.Id).Add(todo);
            return(Task.FromResult(todo));
        }
예제 #2
0
    private ImmutableList <Todo> _store = ImmutableList <Todo> .Empty; // It's always sorted by Id though

    // Commands

#pragma warning disable 1998
    public virtual async Task <Todo> AddOrUpdate(AddOrUpdateTodoCommand command, CancellationToken cancellationToken = default)
    {
        if (Computed.IsInvalidating())
        {
            return(null !);
        }

        var(session, todo) = command;
        if (string.IsNullOrEmpty(todo.Id))
        {
            todo = todo with {
                Id = Ulid.NewUlid().ToString()
            }
        }
        ;
        _store = _store.RemoveAll(i => i.Id == todo.Id).Add(todo);

        using var invalidating = Computed.Invalidate();
        _ = Get(session, todo.Id, CancellationToken.None);
        _ = PseudoGetAllItems(session);
        return(todo);
    }
예제 #3
0
 public Task <Todo> AddOrUpdate([FromBody] AddOrUpdateTodoCommand command, CancellationToken cancellationToken = default)
 {
     command.UseDefaultSession(_sessionResolver);
     return(_todoService.AddOrUpdate(command, cancellationToken));
 }
예제 #4
0
        // Commands

        public virtual async Task <Todo> AddOrUpdate(AddOrUpdateTodoCommand command, CancellationToken cancellationToken = default)
        {
            if (Computed.IsInvalidating())
            {
                return(default !);
 public Task <Todo> AddOrUpdate([FromBody] AddOrUpdateTodoCommand command, CancellationToken cancellationToken = default)
 => _todos.AddOrUpdate(command.UseDefaultSession(_sessionResolver), cancellationToken);