/// <summary>
        /// Associated a set of Event Clusters Ids to a response
        /// </summary>
        /// <param name="responseObj">ResponseEventClustersUpdateModel</param>
        /// <returns>ResponseModel</returns>
        public async Task <ResponseModel> AddEventClusterIdsToResponse(ResponseEventClustersUpdateModel responseUpdate)
        {
            ResponseDAO response = await _repoResponses.GetItemAsync(responseUpdate.ResponseId);

            if (response == null)
            {
                throw new Exception($"No response found that matches responseid: {responseUpdate.ResponseId}");
            }

            string etag = response.ETag;

            if (response.EventClusterIds == null)
            {
                response.EventClusterIds = new List <Guid>();
            }
            response.EventClusterIds = response.EventClusterIds.Concat(responseUpdate.EventClusterIds);
            response.ETag            = etag;

            try
            {
                await _repoResponses.UpdateItemAsync(response);
            }
            catch (DocumentClientException e)
            {
                //Update concurrency issue, retrying
                if (e.StatusCode == HttpStatusCode.PreconditionFailed)
                {
                    return(await AddEventClusterIdsToResponse(responseUpdate));
                }
                throw e;
            }

            return(_mapper.Map <ResponseModel>(response));
        }
示例#2
0
        public async Task <ResponseModel> AddEventClusterIdsToResponse(ResponseEventClustersUpdateModel responseObj)
        {
            RestRequest request = await PrepareQuery("Responses/AddEventClusters", Method.PUT);

            request.AddParameter("application/json", JsonConvert.SerializeObject(responseObj), ParameterType.RequestBody);
            var queryResult = await _client.ExecuteTaskAsync <ResponseModel>(request);

            if (queryResult.IsSuccessful)
            {
                return(queryResult.Data);
            }
            else
            {
                _logger.LogError($"AddEventClusterIdsToResponse: Error while updating a response: {queryResult.StatusCode}");
            }
            return(null);
        }
        public async Task <IActionResult> AddEventClusterIdsToResponse(ResponseEventClustersUpdateModel responseObj)
        {
            ResponseModel result = await _responseDataManager.AddEventClusterIdsToResponse(responseObj);

            return(Ok(result));
        }