public async Task <IEnumerable <TaskModel> > GetWithParameters(TasksParameters parameters)
        {
            var queryFilters = string.Empty;

            if (!string.IsNullOrWhiteSpace(parameters.Id))
            {
                queryFilters = TableQuery.GenerateFilterCondition(nameof(TaskEntity.RowKey), QueryComparisons.Equal, parameters.Id);
            }
            if (!string.IsNullOrWhiteSpace(parameters.ProjectId))
            {
                var projectCondition =
                    TableQuery.GenerateFilterCondition(nameof(TaskEntity.PartitionKey), QueryComparisons.Equal, parameters.ProjectId);
                queryFilters = string.IsNullOrEmpty(queryFilters) ? projectCondition : TableQuery.CombineFilters(queryFilters, TableOperators.And, projectCondition);
            }
            if (!string.IsNullOrWhiteSpace(parameters.Subject))
            {
                var subjectCondition =
                    TableQuery.GenerateFilterCondition(nameof(TaskEntity.Subject), QueryComparisons.Equal, parameters.Subject);
                queryFilters = string.IsNullOrEmpty(queryFilters) ? subjectCondition : TableQuery.CombineFilters(queryFilters, TableOperators.And, subjectCondition);
            }

            TableQuery <TaskEntity> tableQuery = new TableQuery <TaskEntity>().Where(queryFilters);

            if (parameters.Take.HasValue)
            {
                tableQuery = tableQuery.Take(parameters.Take.Value);
            }

            var tasks = await _context.QueryWithParametersAsync(TableName, tableQuery);

            return(_mapper.Map <List <TaskModel> >(tasks));
        }
Example #2
0
        public async Task <IEnumerable <TaskModel> > Get([FromQuery] TasksParameters parameters)
        {
            if (!parameters.HasValues())
            {
                return(await _taskService.GetAllAsync());
            }

            if (parameters.HasOnlyKeys())
            {
                var task = await _taskService.GetAsync(parameters.Id, parameters.ProjectId);

                return(new List <TaskModel> {
                    task
                });
            }

            return(await _taskService.GetWithParameters(parameters));
        }