/// <summary> /// Asynchronously unlocks the <see cref="User" /> in the system. /// </summary> /// <param name="id">The identifier.</param> /// <returns>True if <see cref="User" /> is unlocked, false otherwise.</returns> public virtual async Task <bool> UnlockUserAsync(object id) { try { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { return(await client.PutAsync <object, bool>(client.GetApiUrl(String.Format("{0}/{{0}}/unlock", ModuleRelativePath), id), new { })); } } catch (BaasicClientException ex) { if (ex.ErrorCode == (int)HttpStatusCode.NotFound) { return(false); } throw; } catch (Exception) { throw; } }
/// <summary> /// Asynchronously disconnects social login provider from the <see cref="User" /> in the system. /// </summary> /// <param name="userName">Name of the user.</param> /// <param name="providerName">Name of the provider.</param> /// <returns>True if <see cref="User" /> is disconnected from social login provider, false otherwise.</returns> public virtual async Task <bool> DisconnectSNProviderAsync(string userName, string providerName) { try { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { return(await client.DeleteAsync(client.GetApiUrl(String.Format("{0}/social-login/{{0}}/{{1}}", ModuleRelativePath), userName, providerName))); } } catch (BaasicClientException ex) { if (ex.ErrorCode == (int)HttpStatusCode.NotFound) { return(false); } throw; } catch (Exception) { throw; } }
/// <summary> /// Asynchronously deletes the collection <see cref="Blog" /> from the system. /// </summary> /// <param name="ids">The collection of identifiers.</param> /// <returns>True if the collection <see cref="Blog" /> is deleted, false otherwise.</returns> public virtual Task <bool> BulkDeleteAsync(object ids) { try { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { return(client.DeleteAsync(client.GetApiUrl(string.Format("{0}/batch", ModuleRelativePath)), ids)); } } catch (BaasicClientException ex) { if (ex.ErrorCode == (int)HttpStatusCode.NotFound) { return(Task.FromResult(false)); } throw; } catch (Exception) { throw; } }
/// <summary> /// Asynchronously find <see cref="BlogPostStatus" /> s. /// </summary> /// <typeparam name="T">Type of extended <see cref="BlogPostStatus" />.</typeparam> /// <param name="searchQuery">Search query.</param> /// <param name="from">The form date.</param> /// <param name="to">The to date.</param> /// <param name="ids">The file ids.</param> /// <param name="tags">The article tags.</param> /// <param name="page">Page number.</param> /// <param name="rpp">Records per page limit.</param> /// <param name="sort">Sort by field.</param> /// <param name="embed">Embed related resources.</param> /// <param name="fields">The fields to include in response.</param> /// <returns>Collection of <typeparamref name="T" /> s.</returns> public virtual async Task <CollectionModelBase <T> > FindAsync <T>(string searchQuery = DefaultSearchQuery, DateTime?from = null, DateTime?to = null, string ids = null, int page = DefaultPage, int rpp = DefaultMaxNumberOfResults, string sort = DefaultSorting, string embed = DefaultEmbed, string fields = DefaultFields) where T : BlogPostStatus { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { UrlBuilder uriBuilder = new UrlBuilder(client.GetApiUrl(ModuleRelativePath)); InitializeQueryString(uriBuilder, searchQuery, page, rpp, sort, embed, fields); InitializeQueryStringPair(uriBuilder, "from", from); InitializeQueryStringPair(uriBuilder, "to", to); InitializeQueryStringPair(uriBuilder, "ids", ids); var result = await client.GetAsync <CollectionModelBase <T> >(uriBuilder.ToString()); if (result == null) { result = new CollectionModelBase <T>(); } return(result); } }
/// <summary> /// Deletes the comment. /// </summary> /// <param name="commentId">The comment identifier.</param> /// <returns></returns> public virtual async Task <bool> DeleteAsync(SGuid commentId) { try { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { return(await client.DeleteAsync(client.GetApiUrl(String.Format("{0}/{{0}}", ModuleRelativePath), commentId))); } } catch (BaasicClientException ex) { if (ex.ErrorCode == (int)HttpStatusCode.NotFound) { return(false); } throw; } catch (Exception) { throw; } }
/// <summary> /// Asynchronously deletes the <see cref="FileEntry" /> from the system. /// </summary> /// <param name="id">The identifier.</param> /// <param name="fileFormat">The file format.</param> /// <returns>True if <see cref="FileEntry" /> is deleted, false otherwise.</returns> public virtual async Task <bool> DeleteAsync(object id, object fileFormat = null) { try { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { UrlBuilder uriBuilder = new UrlBuilder(client.GetApiUrl(String.Format("{0}/unlink/{{0}}", ModuleRelativePath, id))); InitializeQueryStringPair(uriBuilder, "fileFormat", fileFormat); return(await client.DeleteAsync(uriBuilder.ToString())); } } catch (BaasicClientException ex) { if (ex.ErrorCode == (int)HttpStatusCode.NotFound) { return(false); } throw; } catch (Exception) { throw; } }
/// <summary> /// Asynchronously schedule publish for specified <see cref="Notification" /> s. /// </summary> /// <typeparam name="T">Type of extended <see cref="Notification" />.</typeparam> /// <param name="notifications">The notifications.</param> /// <returns>True if <see cref="Notification" /> is scheduled for publish, false otherwise.</returns> public virtual async Task <bool> PublishAsync <T>(T[] notifications) where T : Notification { foreach (var notification in notifications) { if (String.IsNullOrWhiteSpace(notification.TemplateId)) { throw new ArgumentNullException("TemplateId"); } if (notification.Channels == null || notification.Channels.Length == 0) { throw new ArgumentNullException("Channels"); } } try { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { var httpStatusCode = await client.PostAsync <Notification[], HttpStatusCode>(client.GetApiUrl(String.Format("{0}/publish/batch/", ModuleRelativePath)), notifications); return(httpStatusCode == HttpStatusCode.Created); } } catch (BaasicClientException ex) { if (ex.ErrorCode == (int)HttpStatusCode.NotFound) { return(false); } throw; } catch (Exception) { throw; } }