/// <inheritdoc/>
        public async Task <CertificateRequestQueryResultModel> QueryRequestsAsync(
            CertificateRequestQueryRequestModel query, int?maxResults,
            CancellationToken ct)
        {
            var results = await _repo.QueryAsync(query, null, maxResults, ct);

            return(new CertificateRequestQueryResultModel {
                Requests = results.Requests.Select(r => r.Record).ToList(),
                NextPageLink = results.NextPageLink
            });
        }
Пример #2
0
        /// <summary>
        /// Create query string from parameters
        /// </summary>
        /// <param name="query"></param>
        /// <param name="queryParameters"></param>
        /// <returns></returns>
        private static string CreateQuery(CertificateRequestQueryRequestModel query,
                                          out Dictionary <string, object> queryParameters)
        {
            queryParameters = new Dictionary <string, object>();
            var queryString = "SELECT * FROM CertificateRequests r WHERE ";

            if (query?.State != null)
            {
                queryString +=
                    $"r.{nameof(RequestDocument.State)} = @state AND ";
                queryParameters.Add("@state", query.State.Value);
            }
            if (query?.EntityId != null)
            {
                queryString +=
                    $"r.{nameof(RequestDocument.Entity)}.{nameof(EntityInfoModel.Id)} = @entityId AND ";
                queryParameters.Add("@entityId", query.EntityId);
            }
            queryString +=
                $"r.{nameof(RequestDocument.ClassType)} = '{RequestDocument.ClassTypeName}'";
            return(queryString);
        }
Пример #3
0
        /// <inheritdoc/>
        public async Task <CertificateRequestListModel> QueryAsync(
            CertificateRequestQueryRequestModel query, string nextPageLink,
            int?maxResults, CancellationToken ct)
        {
            var client  = _requests.OpenSqlClient();
            var results = nextPageLink != null?
                          client.Continue <RequestDocument>(nextPageLink, maxResults) :
                              client.Query <RequestDocument>(
                                  CreateQuery(query, out var queryParameters),
                                  queryParameters, maxResults);

            if (!results.HasMore())
            {
                return(new CertificateRequestListModel());
            }
            var documents = await results.ReadAsync(ct);

            return(new CertificateRequestListModel {
                NextPageLink = results.ContinuationToken,
                Requests = documents.Select(r => r.Value.ToServiceModel()).ToList()
            });
        }
Пример #4
0
 /// <summary>
 /// Create query
 /// </summary>
 /// <param name="model"></param>
 public CertificateRequestQueryRequestApiModel(CertificateRequestQueryRequestModel model)
 {
     EntityId = model.EntityId;
     State    = model.State;
 }