// TODO MVP API doesn't yet have support for submitting a new Online Identity //public async Task<OnlineIdentity> SubmitOnlineIdentityAsync(OnlineIdentityViewModel onlineIdentity) //{ // if (onlineIdentity == null) // throw new NullReferenceException("The OnlineIdentity parameter was null."); // try // { // var serializedOnlineIdentity = JsonConvert.SerializeObject(onlineIdentity); // byte[] byteData = Encoding.UTF8.GetBytes(serializedOnlineIdentity); // using (var content = new ByteArrayContent(byteData)) // { // content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); // using (var response = await _client.PostAsync("https://mvpapi.azure-api.net/mvp/api/onlineidentities?", content)) // { // if (response.IsSuccessStatusCode) // { // var json = await response.Content.ReadAsStringAsync(); // Debug.WriteLine($"OnlineIdentity Save JSON: {json}"); // var result = JsonConvert.DeserializeObject<OnlineIdentity>(json); // Debug.WriteLine($"OnlineIdentity Save Result: ID {result.PrivateSiteId}"); // return result; // } // else // { // if (response.StatusCode == HttpStatusCode.Unauthorized || response.StatusCode == HttpStatusCode.Forbidden) // { // AccessTokenExpired?.Invoke(this, new EventArgs()); // } // } // } // } // } // catch (HttpRequestException e) // { // await e.LogExceptionAsync(); // if (e.Message.Contains("500")) // { // RequestErrorOccurred?.Invoke(this, new EventArgs()); // } // Debug.WriteLine($"SubmitOnlineIdentitiesAsync HttpRequestException: {e}"); // } // catch (Exception e) // { // await e.LogExceptionAsync(); // Debug.WriteLine($"SubmitOnlineIdentitiesAsync Exception: {e}"); // } // return null; //} public async Task <bool> DeleteOnlineIdentityAsync(OnlineIdentityViewModel onlineIdentity) { if (onlineIdentity == null) { throw new NullReferenceException("The OnlineIdentity parameter was null."); } try { using (var response = await _client.DeleteAsync($"https://mvpapi.azure-api.net/mvp/api/onlineidentities?id={onlineIdentity.PrivateSiteId}")) { if (response.IsSuccessStatusCode) { return(true); } else { if (response.StatusCode == HttpStatusCode.Unauthorized || response.StatusCode == HttpStatusCode.Forbidden) { AccessTokenExpired?.Invoke(this, new EventArgs()); } } } } catch (HttpRequestException e) { await e.LogExceptionAsync(); if (e.Message.Contains("500")) { RequestErrorOccurred?.Invoke(this, new EventArgs()); } Debug.WriteLine($"SubmitOnlineIdentitiesAsync HttpRequestException: {e}"); } catch (Exception e) { await e.LogExceptionAsync(); Debug.WriteLine($"SubmitOnlineIdentitiesAsync Exception: {e}"); } return(false); }
/// <summary> /// Keep PrivateSiteId == 0 and Retricted to the current user /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='subscriptionKey'> /// subscription key in url /// </param> /// <param name='ocpApimSubscriptionKey'> /// subscription key in header /// </param> /// <param name='onlineIdentityViewModel'> /// OnlineIdentityViewModel object /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <object> PostOnlineIdentityAsync(this IMVPProduction operations, string subscriptionKey = default(string), string ocpApimSubscriptionKey = default(string), OnlineIdentityViewModel onlineIdentityViewModel = default(OnlineIdentityViewModel), CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.PostOnlineIdentityWithHttpMessagesAsync(subscriptionKey, ocpApimSubscriptionKey, onlineIdentityViewModel, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Keep PrivateSiteId == 0 and Retricted to the current user /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='subscriptionKey'> /// subscription key in url /// </param> /// <param name='ocpApimSubscriptionKey'> /// subscription key in header /// </param> /// <param name='onlineIdentityViewModel'> /// OnlineIdentityViewModel object /// </param> public static object PostOnlineIdentity(this IMVPProduction operations, string subscriptionKey = default(string), string ocpApimSubscriptionKey = default(string), OnlineIdentityViewModel onlineIdentityViewModel = default(OnlineIdentityViewModel)) { return(Task.Factory.StartNew(s => ((IMVPProduction)s).PostOnlineIdentityAsync(subscriptionKey, ocpApimSubscriptionKey, onlineIdentityViewModel), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
/// <summary> /// Set PrivateSiteId in model to identity id /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='subscriptionKey'> /// subscription key in url /// </param> /// <param name='ocpApimSubscriptionKey'> /// subscription key in header /// </param> /// <param name='onlineIdentityViewModel'> /// OnlineIdentityViewModel model /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task PutOnlineIdentityAsync(this IMVPProduction operations, string subscriptionKey = default(string), string ocpApimSubscriptionKey = default(string), OnlineIdentityViewModel onlineIdentityViewModel = default(OnlineIdentityViewModel), CancellationToken cancellationToken = default(CancellationToken)) { await operations.PutOnlineIdentityWithHttpMessagesAsync(subscriptionKey, ocpApimSubscriptionKey, onlineIdentityViewModel, null, cancellationToken).ConfigureAwait(false); }