/// <summary> /// Asynchronously insert the collection of <see cref="BlogPost" /> into the system. /// </summary> /// <typeparam name="T">Type of extended <see cref="BlogPost" />.</typeparam> /// <param name="blogPost">The blog post.</param> /// <returns>Collection of newly created <typeparamref name="T" /> .</returns> public virtual Task <BatchResult <T>[]> InsertAsync <T>(T[] blogPost) where T : BlogPost { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { return(client.PostAsync <T[], BatchResult <T>[]>(client.GetApiUrl(string.Format("{0}/batch", ModuleRelativePath)), blogPost)); } }
/// <summary> /// Asynchronously insert the <see cref="Navigation" /> into the system. /// </summary> /// <typeparam name="T">Type of extended <see cref="Navigation" />.</typeparam> /// <param name="navigation">Resource instance.</param> /// <returns>Newly created <typeparamref name="T" /> .</returns> public virtual Task <T> InsertAsync <T>(T navigation) where T : Navigation { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { return(client.PostAsync <T>(client.GetApiUrl(ModuleRelativePath), navigation)); } }
/// <summary> /// Asynchronously updates the collection of <see cref="Navigation" /> into the system. /// </summary> /// <typeparam name="T">Type of extended <see cref="Navigation" />.</typeparam> /// <param name="navigations">Resource instance.</param> /// <returns>Collection of updated <typeparamref name="T" /> .</returns> public virtual Task <BatchResult <T>[]> UpdateAsync <T>(T[] navigations) where T : Navigation { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { return(client.PutAsync <T[], BatchResult <T>[]>(client.GetApiUrl(String.Format("{0}/batch", ModuleRelativePath)), navigations)); } }
/// <summary> /// Asynchronously update the <see cref="User" /> password in the system. /// </summary> /// <param name="userName">Name of the user.</param> /// <param name="recoveryParams">The recovery parameters.</param> /// <returns>True if <see cref="User" /> password is updated, false otherwise.</returns> public virtual async Task <bool> UpdatePasswordAsync(string userName, UpdatePasswordDTO recoveryParams) { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { return(await client.PutAsync <UpdatePasswordDTO, bool>(client.GetApiUrl(String.Format("{0}/{1}/change-password", ModuleRelativePath, userName)), recoveryParams)); } }
/// <summary> /// Asynchronously disapproves the <see cref="User" /> in the system. /// </summary> /// <param name="userName">Name of the user.</param> /// <returns>True if <see cref="User" /> is disapproved, false otherwise.</returns> public virtual Task <bool> DisapproveUserAsync(string userName) { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { return(client.DeleteAsync(client.GetApiUrl(String.Format("{0}/disapprove/{{0}}", ModuleRelativePath), userName))); } }
/// <summary> /// Asynchronously updates the collection of <see cref="PageFile" /> into the system. /// </summary> /// <typeparam name="T">Type of extended <see cref="PageFile" />.</typeparam> /// <param name="pageFiles">Resource instance.</param> /// <returns>Collection of updated <typeparamref name="T" /> .</returns> public virtual Task <T[]> UpdateAsync <T>(T[] pageFiles) where T : PageFile { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { return(client.PutAsync <T[]>(client.GetApiUrl(String.Format("{0}/batch", ModuleRelativePath)), pageFiles)); } }
/// <summary> /// Asynchronously insert the collection of <see cref="FileEntry" /> into the system. /// </summary> /// <typeparam name="T">Type of extended <see cref="FileEntry" />.</typeparam> /// <param name="fileEntries">Resource instance.</param> /// <returns>Collection of newly created <typeparamref name="T" /> .</returns> public virtual Task <BatchResult <T>[]> InsertAsync <T>(T[] fileEntries) where T : FileEntry { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { return(client.PostAsync <T[], BatchResult <T>[]>(client.GetApiUrl(String.Format("{0}/batch/link", ModuleRelativePath)), fileEntries)); } }
/// <summary> /// Uns the report comment asynchronous. /// </summary> /// <param name="commentId">The comment identifier.</param> /// <returns></returns> public virtual async Task <bool> UnReportAsync(SGuid commentId) { try { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { var request = new HttpRequestMessage(HttpMethod.Put, client.GetApiUrl(String.Format("{0}/{{0}}/unreport", ModuleRelativePath), commentId)); var result = await client.SendAsync(request); return(result.IsSuccessStatusCode); } } catch (BaasicClientException ex) { if (ex.ErrorCode == (int)HttpStatusCode.NotFound) { return(false); } throw; } catch (Exception) { throw; } }
/// <summary> /// Approves the comment. /// </summary> /// <param name="commentId">The comment identifier.</param> /// <param name="options">The options.</param> /// <returns></returns> public virtual async Task <bool> ApproveAsync(SGuid commentId, ArticleCommentOptions options) { try { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { var result = await client.PutAsync <ArticleCommentOptions, HttpStatusCode>(client.GetApiUrl(String.Format("{0}/{{0}}/approve", ModuleRelativePath), commentId), options); switch (result) { case System.Net.HttpStatusCode.Created: case System.Net.HttpStatusCode.NoContent: case System.Net.HttpStatusCode.OK: return(true); default: return(false); } } } catch (BaasicClientException ex) { if (ex.ErrorCode == (int)HttpStatusCode.NotFound) { return(false); } throw; } catch (Exception) { throw; } }
/// <summary> /// Asynchronously adds the <see cref="ArticleTag" /> . /// </summary> /// <typeparam name="T">Type of extended <see cref="ArticleTag" />.</typeparam> /// <param name="entry">The tag entry.</param> /// <returns>If tag is added <typeparamref name="T" /> is returned, otherwise null.</returns> public virtual Task <T> InsertAsync <T>(T entry) where T : ArticleTag { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { return(client.PostAsync <T>(client.GetApiUrl(ModuleRelativePath), entry)); } }
/// <summary> /// Asynchronously update the <see cref="ArticleTag" /> . /// </summary> /// <typeparam name="T">Type of extended <see cref="ArticleTag" />.</typeparam> /// <param name="tag">The new or existing <see cref="ArticleTag" /> .</param> /// <returns>If tag is updated <typeparamref name="T" /> is returned, otherwise null.</returns> public virtual Task <T> UpdateAsync <T>(T tag) where T : ArticleTag { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { return(client.PutAsync <T>(client.GetApiUrl(string.Format("{0}/{1}", ModuleRelativePath, tag.Id)), tag)); } }
/// <summary> /// Asynchronously gets the <see cref="KeyValue" /> by provided key. /// </summary> /// <param name="key">Key.</param> /// <returns><see cref="KeyValue" /> .</returns> public virtual Task <KeyValue> GetAsync(object key) { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { return(client.GetAsync <KeyValue>(client.GetApiUrl(String.Format("{0}/{{0}}", ModuleRelativePath), key))); } }
/// <summary> /// Asynchronously insert the collection of <see cref="Language" /> into the system. /// </summary> /// <typeparam name="T">Type of extended <see cref="Language" />.</typeparam> /// <param name="languages">Resource instance.</param> /// <returns>Collection of newly created <typeparamref name="T" /> .</returns> public virtual Task <T[]> InsertAsync <T>(T[] languages) where T : Language { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { return(client.PostAsync <T[]>(client.GetApiUrl(String.Format("{0}/batch", ModuleRelativePath)), languages)); } }
/// <summary> /// Asynchronously update the <see cref="BlogPost" /> in the system. /// </summary> /// <typeparam name="T">Type of extended <see cref="BlogPost" />.</typeparam> /// <param name="blogPost">The blog post.</param> /// <returns>True if <typeparamref name="T" /> is successfully updated, false otherwise.</returns> public virtual async Task <bool> UpdateAsync <T>(T blogPost) where T : BlogPost { try { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { UrlBuilder uriBuilder = new UrlBuilder(client.GetApiUrl(string.Format("{0}/{1}", ModuleRelativePath, blogPost.Id))); var result = await client.PutAsync <BlogPost, HttpStatusCode>(uriBuilder.ToString(), blogPost); switch (result) { case HttpStatusCode.Created: case HttpStatusCode.NoContent: case HttpStatusCode.OK: return(true); default: return(false); } } } catch (BaasicClientException ex) { if (ex.ErrorCode == (int)HttpStatusCode.NotFound) { return(false); } throw; } catch (Exception) { throw; } }
/// <summary> /// Asynchronously insert the <see cref="CreateArticleComment" /> into the system. /// </summary> /// <typeparam name="T">Type of extended <see cref="ArticleComment" />.</typeparam> /// <param name="comment">The comment.</param> /// <returns>Newly created <typeparamref name="T" /> .</returns> public virtual Task <T> InsertCommentAsync <T>(T comment) { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { return(client.PostAsync <T>(client.GetApiUrl(ModuleRelativePath), comment)); } }
/// <summary> /// Asynchronously checks the URL uniqness. /// </summary> /// <param name="url">The URL.</param> /// <returns>True if url is unique</returns> public virtual async Task <bool> IsUrlUniqueAsync(string url) { try { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { UrlBuilder uriBuilder = new UrlBuilder(client.GetApiUrl(string.Format("{0}/unique/url", ModuleRelativePath), url)); InitializeQueryStringPair(uriBuilder, "url", url); await client.GetAsync <bool>(uriBuilder.ToString()); return(true); } } catch (BaasicClientException ex) { if (ex.ErrorCode == (int)HttpStatusCode.Conflict) { return(false); } throw; } catch (Exception) { throw; } }
/// <summary> /// Updates the comment asynchronous. /// </summary> /// <typeparam name="T">Type of extended <see cref="ArticleComment" />.</typeparam> /// <param name="comment">The comment.</param> /// <returns>Updated <typeparamref name="T" /></returns> public virtual Task <T> UpdateCommentAsync <T>(T comment) where T : ArticleComment { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { return(client.PutAsync <T>(client.GetApiUrl(String.Format("{0}/{{0}}", ModuleRelativePath), comment.Id), comment)); } }
/// <summary> /// Patches the <see cref="T" /> asynchronous. /// </summary> /// <param name="schemaName">The schema name.</param> /// <param name="id">The identifier.</param> /// <param name="resource">The resource.</param> /// <returns>True if updated, false otherwise.</returns> public Task <bool> PatchAsync <T>(string schemaName, SGuid id, T resource) { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { return(client.PatchAsync <T>(client.GetApiUrl(string.Format("{{0}}/{{1}}/{0}", id), ModuleRelativePath, schemaName), resource)); } }
/// <summary> /// Asynchronously insert the <see cref="FileEntry" /> into the system. /// </summary> /// <typeparam name="T">Type of extended <see cref="FileEntry" />.</typeparam> /// <param name="fileEntry">Resource instance.</param> /// <returns>Newly created <typeparamref name="T" /> .</returns> public virtual Task <T> InsertAsync <T>(T fileEntry) where T : FileEntry { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { return(client.PostAsync <T>(String.Format("{0}/link", client.GetApiUrl(ModuleRelativePath)), fileEntry)); } }
/// <summary> /// Asynchronously insert the <see cref="T" /> into the system. /// </summary> /// <param name="schemaName">The schema name.</param> /// <param name="resource">The resource.</param> /// <returns>Newly created <see cref="T" /> .</returns> public virtual Task <T> InsertAsync(string schemaName, T resource) { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { return(client.PostAsync <T>(client.GetApiUrl("{0}/{1}", ModuleRelativePath, schemaName), resource)); } }
/// <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 Task <bool> DisconnectSNProviderAsync(string userName, string providerName) { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { return(client.DeleteAsync(client.GetApiUrl(String.Format("{0}/social-login/{{0}}/{{1}}", ModuleRelativePath), userName, providerName))); } }
/// <summary> /// Asynchronously update the <see cref="T" /> in the system. /// </summary> /// <param name="schemaName">The schema name.</param> /// <param name="resource">The resource.</param> /// <returns>Updated <see cref="T" /> .</returns> public virtual Task <T> UpdateAsync(string schemaName, T resource) { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { return(client.PutAsync <T>(client.GetApiUrl(string.Format("{{0}}/{{1}}/{0}", resource.Id), ModuleRelativePath, schemaName), resource)); } }
/// <summary> /// Asynchronously deletes the <see cref="User" /> from the system. /// </summary> /// <param name="id">The identifier.</param> /// <returns>True if <see cref="User" /> is deleted, false otherwise.</returns> public virtual Task <bool> DeleteAsync(object id) { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { return(client.DeleteAsync(client.GetApiUrl(String.Format("{0}/{{0}}", ModuleRelativePath), id))); } }
/// <summary> /// Asynchronously schedule publish for specified <see cref="Notification" />. /// </summary> /// <typeparam name="T">Type of extended <see cref="Notification" />.</typeparam> /// <param name="notification">The notification.</param> /// <returns>True if <see cref="Notification" /> is scheduled for publish, false otherwise.</returns> public virtual async Task <bool> PublishAsync <T>(T notification) where T : Notification { 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/", ModuleRelativePath)), notification); return(httpStatusCode == HttpStatusCode.Created); } } catch (BaasicClientException ex) { if (ex.ErrorCode == (int)HttpStatusCode.NotFound) { return(false); } throw; } catch (Exception) { throw; } }
/// <summary> /// Asynchronously find <see cref="Navigation" /> s. /// </summary> /// <typeparam name="T">Type of extended <see cref="Navigation" />.</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="url">The url.</param> /// <param name="menuId">The menu id.</param> /// <param name="pageIds">The page ids.</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, string url = null, string menuId = null, string pageIds = null, int page = DefaultPage, int rpp = DefaultMaxNumberOfResults, string sort = DefaultSorting, string embed = DefaultEmbed, string fields = DefaultFields) where T : Navigation { 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); InitializeQueryStringPair(uriBuilder, "url", url); InitializeQueryStringPair(uriBuilder, "menuId", menuId); InitializeQueryStringPair(uriBuilder, "pageIds", pageIds); var result = await client.GetAsync <CollectionModelBase <T> >(uriBuilder.ToString()); if (result == null) { result = new CollectionModelBase <T>(); } return(result); } }
/// <summary> /// Asynchronously insert the <see cref="Role" /> into the system. /// </summary> /// <param name="content">Resource instance.</param> /// <returns>Newly created <see cref="Role" /> .</returns> public virtual Task <Role> InsertAsync(Role content) { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { return(client.PostAsync <Role>(client.GetApiUrl(ModuleRelativePath), content)); } }
/// <summary> /// Asynchronously update the <see cref="Navigation" /> in the system. /// </summary> /// <typeparam name="T">Type of extended <see cref="Navigation" />.</typeparam> /// <param name="navigation">Resource instance.</param> /// <returns>True if <typeparamref name="T" /> is successfully updated, false otherwise.</returns> public virtual async Task <bool> UpdateAsync <T>(T navigation) where T : Navigation { try { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { var result = await client.PutAsync <Navigation, HttpStatusCode>(client.GetApiUrl(String.Format("{0}/{1}", ModuleRelativePath, navigation.Id)), navigation); switch (result) { case System.Net.HttpStatusCode.Created: case System.Net.HttpStatusCode.NoContent: case System.Net.HttpStatusCode.OK: return(true); default: return(false); } } } catch (BaasicClientException ex) { if (ex.ErrorCode == (int)HttpStatusCode.NotFound) { return(false); } throw; } catch (Exception) { throw; } }
/// <summary> /// Asynchronously update the <see cref="Role" /> in the system. /// </summary> /// <param name="content">Resource instance.</param> /// <returns>Updated <see cref="Role" /> .</returns> public virtual Task <Role> UpdateAsync(Role content) { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { return(client.PutAsync <Role>(client.GetApiUrl(String.Format("{0}/{1}", ModuleRelativePath, content.Id)), content)); } }
/// <summary> /// Asynchronously updates the collection of <see cref="Navigation" /> into the system. /// </summary> /// <typeparam name="T">Type of extended <see cref="Navigation" />.</typeparam> /// <param name="navigations">Resource instance.</param> /// <returns>Collection of updated <typeparamref name="T" /> .</returns> public virtual Task UpdateMenuNavigationAsync <T>(Guid menuId, T[] navigations) where T : Navigation { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { return(client.PutAsync(client.GetApiUrl(String.Format("{0}/batch/menu/{1}", ModuleRelativePath, menuId)), navigations)); } }
/// <summary> /// Asynchronously update the <see cref="Menu" /> in the system. /// </summary> /// <typeparam name="T">Type of extended <see cref="Menu" />.</typeparam> /// <param name="menu">Resource instance.</param> /// <param name="forcePositionsUpdate">True if menu needs to be saved on position no matter of existing menus.</param> /// <returns>True if <typeparamref name="T" /> is successfully updated, false otherwise.</returns> public virtual async Task <bool> UpdateAsync <T>(T menu, bool?forcePositionsUpdate = null) where T : Menu { try { using (IBaasicClient client = BaasicClientFactory.Create(Configuration)) { UrlBuilder uriBuilder = new UrlBuilder(client.GetApiUrl(String.Format("{0}/{1}", ModuleRelativePath, menu.Id))); InitializeQueryStringPair(uriBuilder, "forcePositionsUpdate", forcePositionsUpdate); var result = await client.PutAsync <Menu, HttpStatusCode>(uriBuilder.ToString(), menu); switch (result) { case System.Net.HttpStatusCode.Created: case System.Net.HttpStatusCode.NoContent: case System.Net.HttpStatusCode.OK: return(true); default: return(false); } } } catch (BaasicClientException ex) { if (ex.ErrorCode == (int)HttpStatusCode.NotFound) { return(false); } throw; } catch (Exception) { throw; } }