Пример #1
0
        /// <summary>
        /// Gets the contact.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>
        /// The contact.
        /// </returns>
        public async Task <Resource> GetContact(ContactGetRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            try
            {
                var configurationBuilder = this.CreateConfigurationBuilder();

                var configReader = ServiceFactory.CreateConfigurationReader(configurationBuilder);
                var config       = configReader.Read();

                var service = ServiceFactory.CreateContactService(
                    this.serviceResolver,
                    ConnectionHelper.CreateCosmosUserConnectionInfo(config),
                    ConnectionHelper.CreateCosmosContactConnectionInfo(config),
                    this.logService);

                var contact = await service.GetContactAsync(request).ConfigureAwait(false);

                this.logService.LogInformation(
                    "Successfully executed Get Contact at {Timestamp}",
                    DateTime.UtcNow);

                return(contact);
            }
            catch (Exception e)
            {
                var errorMessage = $"Fatal exception during Get Contact. ErrorMessage message: {e.Message}";
                this.logService.LogError(e, errorMessage);
                throw;
            }
        }
Пример #2
0
        /// <inheritdoc />
        public Task <ContactDocument> GetContactAsync(ContactGetRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            return(this.cosmosRepository.GetContactAsync(request));
        }
Пример #3
0
 public async Task <ActionResult> Get([FromRoute] ContactGetRequest rq)
 {
     try
     {
         ContactGetResponse rs = await(new ContactGetService(this.Context, _contactModRepo)).RunAsync(rq);
         return(new ApiActionResult(this.Context.Request, rs));
     }
     catch (Exception ex)
     {
         return(new ApiActionResult(this.Context.Request, ex));
     }
 }
Пример #4
0
        /// <inheritdoc />
        public async Task <ContactDocument> GetContactAsync(ContactGetRequest request)
        {
            var query = this.client.CreateDocumentQuery <ContactDocument>(
                this.ContactDocumentCollectionUri,
                new FeedOptions()
            {
                ConsistencyLevel = ConsistencyLevel.Session,
                MaxItemCount     = MaxPerFeedRequest,
                PartitionKey     = new PartitionKey(request.UserId)
            }).Where(x => x.ContactId == request.ContactId).AsDocumentQuery();

            if (!query.HasMoreResults)
            {
                return(null);
            }

            var documentFeed = await query.ExecuteNextAsync <ContactDocument>().ConfigureAwait(false);

            return(documentFeed.FirstOrDefault());
        }