public async Task <AddScopeResponse> Execute(PostScope request, string url)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (string.IsNullOrWhiteSpace(url))
            {
                throw new ArgumentNullException(nameof(url));
            }

            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)
            };
            var httpResult = await httpClient.SendAsync(httpRequest);

            httpResult.EnsureSuccessStatusCode();
            var content = await httpResult.Content.ReadAsStringAsync();

            return(JsonConvert.DeserializeObject <AddScopeResponse>(content));
        }
Beispiel #2
0
 public static AddScopeParameter ToParameter(this PostScope postScope)
 {
     return(new AddScopeParameter
     {
         Id = postScope.Id,
         Name = postScope.Name,
         IconUri = postScope.IconUri
     });
 }
        public async Task <ActionResult> AddScope([FromBody] PostScope postScope)
        {
            if (postScope == null)
            {
                throw new ArgumentNullException(nameof(postScope));
            }

            var parameter = postScope.ToParameter();
            await _scopeActions.InsertScope(parameter);

            var response = new AddScopeResponse
            {
                Id = postScope.Id
            };

            return(new ObjectResult(response)
            {
                StatusCode = (int)HttpStatusCode.Created
            });
        }
Beispiel #4
0
        public async Task <AddScopeResponse> AddByResolution(PostScope request, string url)
        {
            var configuration = await _getConfigurationOperation.ExecuteAsync(UriHelpers.GetUri(url));

            return(await Add(request, configuration.ScopeEndPoint));
        }
Beispiel #5
0
 public Task <AddScopeResponse> Add(PostScope request, string url)
 {
     return(_addScopeOperation.Execute(request, url));
 }