예제 #1
0
        public Task <SearchResult <ProcessFileResult> > Find(FindProcessFilesParameter parameter, CancellationToken token)
        {
            IQueryable <ProcessFileAggregate> result = _processFiles.AsQueryable();

            if (!string.IsNullOrWhiteSpace(parameter.FileId))
            {
                result = result.Where(_ => _.FileId == parameter.FileId);
            }

            if (parameter.TakeLatest)
            {
                result = result.OrderByDescending(r => r.Version);
                result = result.GroupBy(r => r.FileId).Select(r => r.First());
            }

            if (MAPPING_PROCESSFILE_TO_PROPERTYNAME.ContainsKey(parameter.OrderBy))
            {
                result = result.InvokeOrderBy(MAPPING_PROCESSFILE_TO_PROPERTYNAME[parameter.OrderBy], parameter.Order);
            }

            int totalLength = result.Count();

            result = result.Skip(parameter.StartIndex).Take(parameter.Count);
            return(Task.FromResult(new SearchResult <ProcessFileResult>
            {
                StartIndex = parameter.StartIndex,
                Count = parameter.Count,
                TotalLength = totalLength,
                Content = result.Select(_ => ProcessFileResult.ToDto(_)).ToList()
            }));
        }
예제 #2
0
        public async Task <SearchResult <ProcessFileResult> > Find(FindProcessFilesParameter parameter, CancellationToken token)
        {
            IQueryable <ProcessFileAggregate> result = _dbContext.ProcessFiles;

            if (MAPPING_PROCESSFILE_TO_PROPERTYNAME.ContainsKey(parameter.OrderBy))
            {
                result = result.InvokeOrderBy(MAPPING_PROCESSFILE_TO_PROPERTYNAME[parameter.OrderBy], parameter.Order);
            }

            int totalLength = await result.CountAsync(token);

            result = result.Skip(parameter.StartIndex).Take(parameter.Count);
            var content = await result.ToListAsync(token);

            if (parameter.TakeLatest)
            {
                content = content.OrderByDescending(r => r.Version).GroupBy(r => r.FileId).Select(r => r.First()).ToList();
            }

            return(new SearchResult <ProcessFileResult>
            {
                StartIndex = parameter.StartIndex,
                Count = parameter.Count,
                TotalLength = totalLength,
                Content = content.Select(_ => ProcessFileResult.ToDto(_)).ToList()
            });
        }
예제 #3
0
        public Task <ProcessFileResult> Get(string id, CancellationToken token)
        {
            var processFile = _processFiles.FirstOrDefault(_ => _.AggregateId == id);
            var result      = processFile == null ? null : ProcessFileResult.ToDto(processFile);

            return(Task.FromResult(result));
        }
예제 #4
0
        public async Task <ProcessFileResult> Get(string id, CancellationToken cancellationToken)
        {
            var processFile = await _dbContext.ProcessFiles.FirstOrDefaultAsync(_ => _.AggregateId == id, cancellationToken);

            return(processFile == null ? null : ProcessFileResult.ToDto(processFile));
        }