public async Task <ActionResult> PostAddResourceSet(string id, [FromBody] PostAddResourceSet postAddResourceSet) { if (string.IsNullOrWhiteSpace(id)) { throw new ArgumentNullException(nameof(id)); } if (postAddResourceSet == null) { throw new ArgumentNullException(nameof(postAddResourceSet)); } var isPolicyExists = await _policyActions.AddResourceSet(new AddResourceSetParameter { PolicyId = id, ResourceSets = postAddResourceSet.ResourceSets }); if (!isPolicyExists) { return(GetNotFoundPolicy()); } await _representationManager.AddOrUpdateRepresentationAsync(this, CachingStoreNames.GetPolicyStoreName + id, false); return(new StatusCodeResult((int)HttpStatusCode.NoContent)); }
public async Task <ActionResult> PostAddResourceSet(string id, [FromBody] PostAddResourceSet postAddResourceSet) { if (string.IsNullOrWhiteSpace(id)) { return(BuildError(ErrorCodes.InvalidRequestCode, "the identifier must be specified", HttpStatusCode.BadRequest)); } if (postAddResourceSet == null) { return(BuildError(ErrorCodes.InvalidRequestCode, "no parameter in body request", HttpStatusCode.BadRequest)); } var isPolicyExists = await _policyActions.AddResourceSet(new AddResourceSetParameter { PolicyId = id, ResourceSets = postAddResourceSet.ResourceSets }); if (!isPolicyExists) { return(GetNotFoundPolicy()); } await _representationManager.AddOrUpdateRepresentationAsync(this, Constants.CachingStoreNames.GetPolicyStoreName + id, false); return(new StatusCodeResult((int)HttpStatusCode.NoContent)); }
public async Task <BaseResponse> ExecuteAsync(string id, PostAddResourceSet request, string url, string token) { if (string.IsNullOrWhiteSpace(id)) { throw new ArgumentNullException(nameof(id)); } if (request == null) { throw new ArgumentNullException(nameof(request)); } if (string.IsNullOrWhiteSpace(url)) { throw new ArgumentNullException(nameof(url)); } if (string.IsNullOrWhiteSpace(token)) { throw new ArgumentNullException(nameof(token)); } if (url.EndsWith("/")) { url = url.Remove(0, url.Length - 1); } url = url + "/" + id + "/resources"; var httpClient = _httpClientFactory.GetHttpClient(); var serializedPostResourceSet = JsonConvert.SerializeObject(request); var body = new StringContent(serializedPostResourceSet, Encoding.UTF8, "application/json"); var httpRequest = new HttpRequestMessage { Content = body, Method = HttpMethod.Post, RequestUri = new Uri(url) }; httpRequest.Headers.Add("Authorization", "Bearer " + token); var httpResult = await httpClient.SendAsync(httpRequest).ConfigureAwait(false); var content = await httpResult.Content.ReadAsStringAsync().ConfigureAwait(false); try { httpResult.EnsureSuccessStatusCode(); } catch (Exception) { return(new BaseResponse { ContainsError = true, Error = JsonConvert.DeserializeObject <ErrorResponse>(content), HttpStatus = httpResult.StatusCode }); } return(new BaseResponse()); }
public async Task <bool> AddResourceByResolution(string id, PostAddResourceSet request, string url, string token) { var policyEndpoint = await GetPolicyEndPoint(UriHelpers.GetUri(url)); return(await AddResource(id, request, policyEndpoint, token)); }
public Task <bool> AddResource(string id, PostAddResourceSet request, string url, string token) { return(_addResourceToPolicyOperation.ExecuteAsync(id, request, url, token)); }
public async Task <BaseResponse> AddResourceByResolution(string id, PostAddResourceSet request, string url, string token) { var policyEndpoint = await GetPolicyEndPoint(UriHelpers.GetUri(url)).ConfigureAwait(false); return(await AddResource(id, request, policyEndpoint, token).ConfigureAwait(false)); }