Пример #1
0
        /// <summary>
        /// Upgrade/downgrade an existing subscription.
        /// </summary>
        public async Task <UpdateSubscriptionResponseModel> UpdateSubscriptionAsync(UpdateSubscriptionRequestModel model)
        {
            try
            {
                string        json          = Newtonsoft.Json.JsonConvert.SerializeObject(model);
                StringContent stringContent = new StringContent(json, System.Text.Encoding.Default, "application/json");

                if (string.IsNullOrEmpty(model.SubscriptionId) && string.IsNullOrEmpty(model.SubscriptionAlias))
                {
                    throw new MissingMemberException("Either you need to set 'SubscriptionId' or 'SubscriptionAlias'");
                }

                var result = await client.PutAsync("v2/subscriptions/" + (string.IsNullOrEmpty(model.SubscriptionAlias) ? model.SubscriptionId : model.SubscriptionAlias) + "/", stringContent);

                var jsonResponse = await result.Content.ReadAsStringAsync();

                var response = Newtonsoft.Json.JsonConvert.DeserializeObject <UpdateSubscriptionResponseModel>(jsonResponse);
                if (response == null)
                {
                    response = new UpdateSubscriptionResponseModel();
                }
                response.IsSuccessfull = result.IsSuccessStatusCode;
                return(response);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Пример #2
0
        public async Task <ActionResult> Change(UpdateSubscriptionRequestModel model)
        {
            var userId = this.currentUser.GetId();

            var result = await this.subscriptionService.ChangeAsync(userId, model.Subscription);

            if (result.Failure)
            {
                return(this.BadRequest(result.Error));
            }

            return(this.Ok());
        }
Пример #3
0
 /// <summary>
 /// Upgrade/downgrade an existing subscription.
 /// </summary>
 public UpdateSubscriptionResponseModel UpdateSubscription(UpdateSubscriptionRequestModel model) => UpdateSubscriptionAsync(model).ConfigureAwait(false).GetAwaiter().GetResult();