public async Task <Result <List <ToDoItem> > > GetAllIncompleteItemsAsync(int projectId, string searchString)
        {
            if (string.IsNullOrEmpty(searchString))
            {
                var errors = new List <ValidationError>();
                errors.Add(new ValidationError()
                {
                    Identifier   = nameof(searchString),
                    ErrorMessage = $"{nameof(searchString)} is required."
                });
                return(Result <List <ToDoItem> > .Invalid(errors));
            }

            var projectSpec = new ProjectByIdWithItemsSpec(projectId);
            var project     = await _repository.GetBySpecAsync(projectSpec);

            var incompleteSpec = new IncompleteItemsSpec();

            try
            {
                //var items = await _repository.ListAsync(incompleteSpec);
                var items = incompleteSpec.Evaluate(project.Items).ToList();

                return(new Result <List <ToDoItem> >(items));
            }
            catch (Exception ex)
            {
                // TODO: Log details here
                return(Result <List <ToDoItem> > .Error(new[] { ex.Message }));
            }
        }
예제 #2
0
        public async Task OnGetAsync()
        {
            var projectSpec = new ProjectByIdWithItemsSpec(1); // TODO: get from route
            var project     = await _repository.GetBySpecAsync(projectSpec);

            var spec = new IncompleteItemsSpec();

            ToDoItems = spec.Evaluate(project.Items).ToList();
        }
    public async Task OnGetAsync()
    {
        var projectSpec = new ProjectByIdWithItemsSpec(ProjectId);
        var project     = await _repository.GetBySpecAsync(projectSpec);

        if (project == null)
        {
            return;
        }

        var spec = new IncompleteItemsSpec();

        ToDoItems = spec.Evaluate(project.Items).ToList();
    }
        public async Task <Result <ToDoItem> > GetNextIncompleteItemAsync(int projectId)
        {
            var projectSpec = new ProjectByIdWithItemsSpec(projectId);
            var project     = await _repository.GetBySpecAsync(projectSpec);

            var incompleteSpec = new IncompleteItemsSpec();

            var items = incompleteSpec.Evaluate(project.Items).ToList();

            if (!items.Any())
            {
                return(Result <ToDoItem> .NotFound());
            }

            return(new Result <ToDoItem>(items.First()));
        }
    public void FilterCollectionToOnlyReturnItemsWithIsDoneFalse()
    {
        var item1 = new ToDoItem();
        var item2 = new ToDoItem();
        var item3 = new ToDoItem();

        item3.MarkComplete();

        var items = new List <ToDoItem>()
        {
            item1, item2, item3
        };

        var spec = new IncompleteItemsSpec();

        var filteredList = spec.Evaluate(items);

        Assert.Contains(item1, filteredList);
        Assert.Contains(item2, filteredList);
        Assert.DoesNotContain(item3, filteredList);
    }
        public void FilterCollectionToOnlyReturnItemsWithIsDoneFalse()
        {
            var item1 = new ToDoItem();
            var item2 = new ToDoItem();
            var item3 = new ToDoItem();

            item3.MarkComplete();

            var items = new List <ToDoItem>()
            {
                item1, item2, item3
            };

            var             spec         = new IncompleteItemsSpec();
            List <ToDoItem> filteredList = items
                                           .Where(spec.WhereExpressions.First().Compile())
                                           .ToList();

            Assert.Contains(item1, filteredList);
            Assert.Contains(item2, filteredList);
            Assert.DoesNotContain(item3, filteredList);
        }