public Task <SearchResult <CasePlanInstanceResult> > Find(FindCasePlanInstancesParameter parameter, CancellationToken token)
        {
            IQueryable <CasePlanInstanceAggregate> result = _instances.AsQueryable();

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

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

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

            int totalLength = result.Count();

            result = result.Skip(parameter.StartIndex).Take(parameter.Count);
            return(Task.FromResult(new SearchResult <CasePlanInstanceResult>
            {
                StartIndex = parameter.StartIndex,
                Count = parameter.Count,
                TotalLength = totalLength,
                Content = result.Select(c => CasePlanInstanceResult.ToDto(c)).ToList()
            }));
        }
        public Task <CasePlanInstanceResult> Get(string id, CancellationToken token)
        {
            var result = _instances.FirstOrDefault(i => i.AggregateId == id);

            if (result == null)
            {
                return(Task.FromResult((CasePlanInstanceResult)null));
            }

            return(Task.FromResult(CasePlanInstanceResult.ToDto(result)));
        }
        public async Task <CasePlanInstanceResult> Get(string id, CancellationToken token)
        {
            var result = await _dbContext.CasePlanInstances.FirstOrDefaultAsync(_ => _.AggregateId == id, token);

            if (result == null)
            {
                return(null);
            }

            return(CasePlanInstanceResult.ToDto(result));
        }