Esempio n. 1
0
        public async Task <IEnumerable <Project> > Get([FromQuery] ProjectsParameters parameters)
        {
            if (!parameters.HasValues())
            {
                return(await _projectService.GetAllAsync());
            }
            if (parameters.HasOnlyKeys())
            {
                var project = await _projectService.GetAsync(parameters.Id, parameters.Code);

                return(new List <Project>()
                {
                    project
                });
            }

            return(await _projectService.GetWithParameters(parameters));
        }
Esempio n. 2
0
        public async Task <IEnumerable <Project> > GetWithParameters(ProjectsParameters parameters)
        {
            var queryFilters = string.Empty;

            if (!string.IsNullOrWhiteSpace(parameters.Id))
            {
                queryFilters = TableQuery.GenerateFilterCondition(nameof(ProjectEntity.RowKey), QueryComparisons.Equal, parameters.Id);
            }
            if (!string.IsNullOrWhiteSpace(parameters.Code))
            {
                var codeCondition =
                    TableQuery.GenerateFilterCondition(nameof(ProjectEntity.PartitionKey), QueryComparisons.Equal, parameters.Code);
                queryFilters = string.IsNullOrEmpty(queryFilters) ? codeCondition : TableQuery.CombineFilters(queryFilters, TableOperators.And, codeCondition);
            }
            if (!string.IsNullOrWhiteSpace(parameters.Name))
            {
                var nameCondition =
                    TableQuery.GenerateFilterCondition(nameof(ProjectEntity.Name), QueryComparisons.Equal, parameters.Name);
                queryFilters = string.IsNullOrEmpty(queryFilters) ? nameCondition : TableQuery.CombineFilters(queryFilters, TableOperators.And, nameCondition);
            }

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

            if (parameters.Take.HasValue)
            {
                tableQuery = tableQuery.Take(parameters.Take.Value);
            }
            //if (parameters.Offset.HasValue)
            //{
            //    //TODO: offset parameter
            //}

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

            return(_mapper.Map <List <Project> >(projects));
        }