public async Task <ActionResult <Models.ApimSubscription> > UpdateSubsription([FromBody] Models.ApimSubscriptionCreateOrUpdateContract model, string id, bool?notify)
        {
            var requestUri = ApiUriFormatter.GetRequestUri(this.settings.Value, $"subscriptions/{id}", (notify != null) ? $"&notify={notify}" : string.Empty);
            var request    = new HttpRequestMessage(HttpMethod.Head, requestUri);

            var response = await client.SendAsync(request);

            response.EnsureSuccessStatusCode();
            response.Headers.TryGetValues("etag", out IEnumerable <string> etags);

            // optionally handle if match to make sure not to override a subscription after it has been changed
            request = new HttpRequestMessage(HttpMethod.Patch, requestUri)
            {
                Content = new StringContent(JsonConvert.SerializeObject(model.ToSubscriptionCreateOrUpdateContract(this.settings.Value), new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Ignore
                }), Encoding.Unicode, "application/json")
            };

            request.Headers.TryAddWithoutValidation("If-Match", etags.First().Replace("\"", string.Empty));
            response = await client.SendAsync(request);

            response.EnsureSuccessStatusCode();

            return(NoContent());
        }
        public async Task <ActionResult <Models.ApimUser> > RemoveUserFromGroup([FromBody] Models.UserCreateOrUpdateContract model, string id, string userId)
        {
            var requestUri = ApiUriFormatter.GetRequestUri(this.settings.Value, $"groups/{id}/users/{userId}", string.Empty);
            var request    = new HttpRequestMessage(HttpMethod.Delete, requestUri);

            var response = await client.SendAsync(request);

            response.EnsureSuccessStatusCode();
            return(NoContent());
        }
Exemple #3
0
        public async Task <ActionResult <IEnumerable <Models.ApimUserGroup> > > RemoveGroupFromProduct(string id, string groupId)
        {
            var requestUri = ApiUriFormatter.GetRequestUri(this.settings.Value, $"products/{id}/groups/{groupId}", string.Empty);
            var request    = new HttpRequestMessage(HttpMethod.Delete, requestUri);

            var response = await client.SendAsync(request);

            response.EnsureSuccessStatusCode();
            return(NoContent());
        }
        public async Task <ActionResult <Models.ApimSsoUrlResult> > DeleteUser(string id)
        {
            var requestUri = ApiUriFormatter.GetRequestUri(this.settings.Value, $"users/{id}", string.Empty);
            var request    = new HttpRequestMessage(HttpMethod.Delete, requestUri);

            var response = await client.SendAsync(request);

            response.EnsureSuccessStatusCode();
            return(NoContent());
        }
        public async Task <ActionResult> DeleteSubsription(string id, bool?notify)
        {
            var requestUri = ApiUriFormatter.GetRequestUri(this.settings.Value, $"subscriptions/{id}", (notify != null) ? $"&notify={notify}" : string.Empty);
            var request    = new HttpRequestMessage(HttpMethod.Delete, requestUri);

            var response = await client.SendAsync(request);

            response.EnsureSuccessStatusCode();

            return(NoContent());
        }
        public async Task <ActionResult <Models.ApimUser> > AddUserToGroup(string id, string userId)
        {
            var requestUri = ApiUriFormatter.GetRequestUri(this.settings.Value, $"groups/{id}/users/{userId}", string.Empty);
            var request    = new HttpRequestMessage(HttpMethod.Put, requestUri);

            var response = await client.SendAsync(request);

            response.EnsureSuccessStatusCode();
            var responseData = await response.Content.ReadAsAsync <Models.UserContract>();

            var value = responseData.ToApimUser();

            return(Ok(value));
        }
        public async Task <ActionResult <IEnumerable <Models.ApimUser> > > GetGroupUsers(string id)
        {
            var requestUri = ApiUriFormatter.GetRequestUri(this.settings.Value, $"groups/{id}/users", string.Empty);
            var request    = new HttpRequestMessage(HttpMethod.Get, requestUri);

            var response = await client.SendAsync(request);

            response.EnsureSuccessStatusCode();
            var responseData = await response.Content.ReadAsAsync <Models.ApimCollection <Models.UserContract> >();

            var values = responseData.Value.Select(s => s.ToApimUser());

            return(Ok(values));
        }
Exemple #8
0
        public async Task <ActionResult <Models.ApimSsoUrlResult> > GenerateSsoUrl(string id)
        {
            var requestUri = ApiUriFormatter.GetRequestUri(this.settings.Value, $"users/{id}/generateSsoUrl", string.Empty);
            var request    = new HttpRequestMessage(HttpMethod.Post, requestUri);

            var response = await client.SendAsync(request);

            response.EnsureSuccessStatusCode();
            var responseData = await response.Content.ReadAsAsync <Models.GenerateSsoUrlResult>();

            var value = responseData.ToApimSsoUrlResult();

            return(Ok(value));
        }
Exemple #9
0
        public async Task <ActionResult <Models.ApimProduct> > GetProduct(string id)
        {
            var requestUri = ApiUriFormatter.GetRequestUri(this.settings.Value, $"products/{id}", string.Empty);
            var request    = new HttpRequestMessage(HttpMethod.Get, requestUri);

            var response = await client.SendAsync(request);

            response.EnsureSuccessStatusCode();
            var responseData = await response.Content.ReadAsAsync <Models.ProductContract>();

            var value = responseData.ToApiProduct();

            return(Ok(value));
        }
Exemple #10
0
        public async Task <ActionResult <IEnumerable <Models.ApimTag> > > GetProductTags(string id)
        {
            var requestUri = ApiUriFormatter.GetRequestUri(this.settings.Value, $"products/{id}/tags", string.Empty);
            var request    = new HttpRequestMessage(HttpMethod.Get, requestUri);

            var response = await client.SendAsync(request);

            response.EnsureSuccessStatusCode();
            var responseData = await response.Content.ReadAsAsync <Models.ApimCollection <Models.TagContract> >();

            var value = responseData.Value.Select(t => t.ToApimTag());

            return(Ok(value));
        }
Exemple #11
0
        public async Task <ActionResult <Models.ApimUser> > CreateOrUpdateUser([FromBody] Models.UserCreateContract model, string id)
        {
            var requestUri = ApiUriFormatter.GetRequestUri(this.settings.Value, $"users/{id}", string.Empty);
            var request    = new HttpRequestMessage(HttpMethod.Put, requestUri)
            {
                Content = new StringContent(JsonConvert.SerializeObject(model, new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Ignore
                }), Encoding.Unicode, "application/json")
            };

            var response = await client.SendAsync(request);

            response.EnsureSuccessStatusCode();
            var responseData = await response.Content.ReadAsAsync <Models.UserContract>();

            var value = responseData.ToApimUser();

            return(Ok(value));
        }
        public async Task <ActionResult <Models.ApimSubscription> > CreateOrUpdateSubscription([FromBody] Models.ApimSubscriptionCreateOrUpdateContract model, string id, bool?notify)
        {
            var requestUri = ApiUriFormatter.GetRequestUri(this.settings.Value, $"subscriptions/{id}", (notify != null) ? $"&notify={notify}" : string.Empty);
            var createOrUpdateSubscriptionContract = model.ToSubscriptionCreateOrUpdateContract(this.settings.Value);
            var request = new HttpRequestMessage(HttpMethod.Put, requestUri)
            {
                Content = new StringContent(JsonConvert.SerializeObject(createOrUpdateSubscriptionContract, new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Ignore
                }), Encoding.Unicode, "application/json")
            };

            var response = await client.SendAsync(request);

            response.EnsureSuccessStatusCode();
            var responseData = await response.Content.ReadAsAsync <Models.SubscriptionContract>();

            var value = responseData.ToApimSubscription();

            return(Ok(value));
        }