/// <summary>
 /// Asynchronously insert the collection of <see cref="BlogPostStatus" /> into the system.
 /// </summary>
 /// <typeparam name="T">Type of extended <see cref="BlogPostStatus" />.</typeparam>
 /// <param name="pages">Resource instance.</param>
 /// <returns>Collection of newly created <typeparamref name="T" /> .</returns>
 public virtual Task <BatchResult <T>[]> InsertAsync <T>(T[] pages) where T : BlogPostStatus
 {
     using (IBaasicClient client = BaasicClientFactory.Create(Configuration))
     {
         return(client.PostAsync <T[], BatchResult <T>[]>(client.GetApiUrl(String.Format("{0}/batch", ModuleRelativePath)), pages));
     }
 }
 /// <summary>
 /// Asynchronously insert the <see cref="BlogPostStatus" /> into the system.
 /// </summary>
 /// <typeparam name="T">Type of extended <see cref="BlogPostStatus" />.</typeparam>
 /// <param name="blogPost">Resource instance.</param>
 /// <returns>Newly created <typeparamref name="T" /> .</returns>
 public virtual Task <T> InsertAsync <T>(T blogPost) where T : BlogPostStatus
 {
     using (IBaasicClient client = BaasicClientFactory.Create(Configuration))
     {
         return(client.PostAsync <T>(client.GetApiUrl(ModuleRelativePath), blogPost));
     }
 }
 /// <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 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>
 /// 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));
     }
 }
Exemple #6
0
 /// <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));
     }
 }
Exemple #7
0
 /// <summary>
 /// Asynchronously insert the <see cref="CreateArticleCommentReply" /> into the system.
 /// </summary>
 /// <param name="comment">The comment.</param>
 /// <returns>Newly created <see cref="ArticleCommentReply" /> .</returns>
 public virtual Task <ArticleCommentReply> InsertCommentAsync(CreateArticleCommentReply comment)
 {
     using (IBaasicClient client = BaasicClientFactory.Create(Configuration))
     {
         return(client.PostAsync <ArticleCommentReply>(client.GetApiUrl(ModuleRelativePath), comment));
     }
 }
 /// <summary>
 /// Asynchronously insert the <see cref="User" /> into the system.
 /// </summary>
 /// <typeparam name="T">Type of extended <see cref="User" />.</typeparam>
 /// <param name="content">Resource instance.</param>
 /// <returns>Newly created <typeparamref name="T" /> .</returns>
 public virtual Task <T> InsertAsync <T>(T content) where T : NewUser
 {
     using (IBaasicClient client = BaasicClientFactory.Create(Configuration))
     {
         return(client.PostAsync <T>(client.GetApiUrl(ModuleRelativePath), content));
     }
 }
 /// <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 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));
     }
 }
Exemple #11
0
 /// <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));
     }
 }
Exemple #12
0
        /// <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;
            }
        }
Exemple #13
0
        /// <summary>
        /// Asynchronously update the <see cref="User" /> in the system.
        /// </summary>
        /// <param name="content">Resource instance.</param>
        /// <returns>True if <see cref="User" /> is updated, false otherwise.</returns>
        public virtual async Task <bool> UpdateAsync(User content)
        {
            try
            {
                using (IBaasicClient client = BaasicClientFactory.Create(Configuration))
                {
                    var result = await client.PutAsync <User, HttpStatusCode>(client.GetApiUrl(String.Format("{0}/{1}", ModuleRelativePath, content.Id)), content);

                    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;
            }
        }
Exemple #14
0
 /// <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));
     }
 }
Exemple #15
0
 /// <summary>
 /// Asynchronously updates the collection of <see cref="Blog" /> into the system.
 /// </summary>
 /// <typeparam name="T">Type of extended <see cref="Blog" />.</typeparam>
 /// <param name="blogs">The blogs.</param>
 /// <returns>Collection of updated <typeparamref name="T" /> .</returns>
 public virtual Task <BatchResult <T>[]> UpdateAsync <T>(T[] blogs) where T : Blog
 {
     using (IBaasicClient client = BaasicClientFactory.Create(Configuration))
     {
         return(client.PutAsync <T[], BatchResult <T>[]>(client.GetApiUrl(string.Format("{0}/batch", ModuleRelativePath)), blogs));
     }
 }
Exemple #16
0
        /// <summary>
        /// Asynchronously update the <see cref="Blog" /> in the system.
        /// </summary>
        /// <typeparam name="T">Type of extended <see cref="Blog" />.</typeparam>
        /// <param name="blog">The blog.</param>
        /// <returns>True if <typeparamref name="T" /> is successfully updated, false otherwise.</returns>
        public virtual async Task <bool> UpdateAsync <T>(T blog) where T : Blog
        {
            try
            {
                using (IBaasicClient client = BaasicClientFactory.Create(Configuration))
                {
                    UrlBuilder uriBuilder = new UrlBuilder(client.GetApiUrl(string.Format("{0}/{1}", ModuleRelativePath, blog.Id)));
                    var        result     = await client.PutAsync <Blog, HttpStatusCode>(uriBuilder.ToString(), blog);

                    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;
            }
        }
Exemple #17
0
        /// <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;
            }
        }
 /// <summary>
 /// Asynchronously approves the <see cref="User" /> in the system.
 /// </summary>
 /// <param name="userName">Name of the user.</param>
 /// <returns>True if <see cref="User" /> is approved, false otherwise.</returns>
 public virtual Task <bool> ApproveUserAsync(string userName)
 {
     using (IBaasicClient client = BaasicClientFactory.Create(Configuration))
     {
         return(client.DeleteAsync(client.GetApiUrl(String.Format("{0}/approve/{{0}}", ModuleRelativePath), userName)));
     }
 }
 /// <summary>
 /// Asynchronously insert the <see cref="FileEntry" /> into the system.
 /// </summary>
 /// <param name="fileName">The file name.</param>
 /// <param name="file">The file.</param>
 public virtual Task <FileEntry> InsertAsync(string fileName, Stream file)
 {
     using (IBaasicClient client = BaasicClientFactory.Create(Configuration))
     {
         UrlBuilder uriBuilder = new UrlBuilder(client.GetApiUrl(String.Format("{0}/{1}", ModuleRelativePath, fileName)));
         return(client.PostFileAsync <FileEntry>(uriBuilder.ToString(), file, fileName));
     }
 }
 /// <summary>
 /// Asynchronously insert the <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>Newly created <typeparamref name="T" /> .</returns>
 public virtual Task <T> InsertAsync <T>(T blogPost) where T : BlogPost
 {
     using (IBaasicClient client = BaasicClientFactory.Create(Configuration))
     {
         UrlBuilder uriBuilder = new UrlBuilder(client.GetApiUrl(ModuleRelativePath));
         return(client.PostAsync <T>(uriBuilder.ToString(), blogPost));
     }
 }
 /// <summary>
 /// Asynchronously insert the <see cref="PageFile" /> into the system.
 /// </summary>
 /// <param name="pageId">Resource instance.</param>
 /// <returns>Newly created <see cref="PageFile" /> .</returns>
 public virtual Task <PageFile> InsertAsync(string fileName, Stream file, SGuid pageId)
 {
     using (IBaasicClient client = BaasicClientFactory.Create(Configuration))
     {
         UrlBuilder uriBuilder = new UrlBuilder(client.GetApiUrl(String.Format("{0}/{1}", ModuleRelativePath, fileName)));
         InitializeQueryStringPair(uriBuilder, "pageId", pageId);
         return(client.PostFileAsync <PageFile>(uriBuilder.ToString(), file, fileName));
     }
 }
Exemple #22
0
 /// <summary>
 /// Asynchronously insert the collection of <see cref="Menu" /> into the system.
 /// </summary>
 /// <typeparam name="T">Type of extended <see cref="Menu" />.</typeparam>
 /// <param name="menus">Resource instance.</param>
 /// <param name="forcePositionsUpdate">True if menu needs to be saved on position no matter of existing menus.</param>
 /// <returns>Collection of newly created <typeparamref name="T" /> .</returns>
 public virtual Task <BatchResult <T>[]> InsertAsync <T>(T[] menus, bool?forcePositionsUpdate = null) where T : Menu
 {
     using (IBaasicClient client = BaasicClientFactory.Create(Configuration))
     {
         UrlBuilder uriBuilder = new UrlBuilder(client.GetApiUrl(String.Format("{0}/batch", ModuleRelativePath)));
         InitializeQueryStringPair(uriBuilder, "forcePositionsUpdate", forcePositionsUpdate);
         return(client.PostAsync <T[], BatchResult <T>[]>(uriBuilder.ToString(), menus));
     }
 }
Exemple #23
0
 /// <summary>
 /// Asynchronously insert the <see cref="Menu" /> into 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>Newly created <typeparamref name="T" /> .</returns>
 public virtual Task <T> InsertAsync <T>(T menu, bool?forcePositionsUpdate = null) where T : Menu
 {
     using (IBaasicClient client = BaasicClientFactory.Create(Configuration))
     {
         UrlBuilder uriBuilder = new UrlBuilder(client.GetApiUrl(ModuleRelativePath));
         InitializeQueryStringPair(uriBuilder, "forcePositionsUpdate", forcePositionsUpdate);
         return(client.PostAsync <T>(uriBuilder.ToString(), menu));
     }
 }
Exemple #24
0
 /// <summary>
 /// Asynchronously gets the <see cref="Navigation" /> from the system.
 /// </summary>
 /// <typeparam name="T">Type of extended <see cref="Navigation" />.</typeparam>
 /// <param name="id">The identifier.</param>
 /// <param name="embed">Embed related resources.</param>
 /// <param name="fields">The fields to include in response.</param>
 /// <returns>If found <typeparamref name="T" /> is returned, otherwise null.</returns>
 public virtual Task <T> GetAsync <T>(object id, string embed = DefaultEmbed, string fields = DefaultFields) where T : Navigation
 {
     using (IBaasicClient client = BaasicClientFactory.Create(Configuration))
     {
         UrlBuilder uriBuilder = new UrlBuilder(client.GetApiUrl(String.Format("{0}/{{0}}", ModuleRelativePath), id));
         InitializeQueryString(uriBuilder, embed, fields);
         return(client.GetAsync <T>(uriBuilder.ToString()));
     }
 }
 /// <summary>
 /// Asynchronously gets the <see cref="T" /> by provided key.
 /// </summary>
 /// <param name="id">The identifier.</param>
 /// <param name="schemaName">The schema name.</param>
 /// <param name="embed">The embed.</param>
 /// <param name="fields">The fields to include in response.</param>
 /// <returns><see cref="T" /> .</returns>
 public virtual Task <T> GetAsync(string schemaName, SGuid id, string embed = ClientBase.DefaultEmbed, string fields = ClientBase.DefaultFields)
 {
     using (IBaasicClient client = BaasicClientFactory.Create(Configuration))
     {
         UrlBuilder uriBuilder = new UrlBuilder(client.GetApiUrl(String.Format("{0}/{1}/{{0}}", ModuleRelativePath, schemaName), id));
         InitializeQueryString(uriBuilder, embed, fields);
         return(client.GetAsync <T>(uriBuilder.ToString()));
     }
 }
        /// <summary>
        /// Uns the report comment asynchronous.
        /// </summary>
        /// <param name="commentId">The comment identifier.</param>
        /// <returns></returns>
        public virtual async Task <bool> UnReportAsync(SGuid commentId)
        {
            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);
            }
        }
 /// <summary>
 /// Asynchronously gets the <see cref="PageFile" /> from the system.
 /// </summary>
 /// <typeparam name="T">Type of extended <see cref="PageFile" />.</typeparam>
 /// <param name="id">The identifier.</param>
 /// <param name="width">The file width.</param>
 /// <param name="height">The file height.</param>
 /// <returns>If found <typeparamref name="T" /> is returned, otherwise null.</returns>
 public virtual Task <Stream> GetFileAsync(object id, string fileName, int?width = null, int?height = null)
 {
     using (IBaasicClient client = BaasicClientFactory.Create(Configuration))
     {
         UrlBuilder uriBuilder = new UrlBuilder(client.GetApiUrl(String.Format("{0}/{1}/{2}", ModuleRelativePath, id, fileName)));
         InitializeQueryStringPair(uriBuilder, "width", width);
         InitializeQueryStringPair(uriBuilder, "height", height);
         return(client.GetAsync(uriBuilder.ToString()));
     }
 }
 /// <summary>
 /// Asynchronously gets the <see cref="FileEntry" /> from the system.
 /// </summary>
 /// <typeparam name="T">Type of extended <see cref="FileEntry" />.</typeparam>
 /// <param name="id">The identifier.</param>
 /// <param name="width">The file width.</param>
 /// <param name="height">The file height.</param>
 /// <returns>If found <typeparamref name="T" /> is returned, otherwise null.</returns>
 public virtual Task <string> GetFileUrlAsync(object id, int?width = null, int?height = null)
 {
     using (IBaasicClient client = BaasicClientFactory.Create(Configuration))
     {
         UrlBuilder uriBuilder = new UrlBuilder(client.GetApiUrl(String.Format("{0}/{{0}}", ModuleRelativePath), id));
         InitializeQueryStringPair(uriBuilder, "width", width);
         InitializeQueryStringPair(uriBuilder, "height", height);
         return(Task.FromResult(uriBuilder.ToString()));
     }
 }
Exemple #29
0
        /// <summary>
        /// Asynchronously gets the collection of <see cref="Navigation" /> from the system ordered in a tree structure.
        /// </summary>
        /// <typeparam name="T">Type of extended <see cref="Navigation" />.</typeparam>
        /// <param name="menuId">The <see cref="Menu" /> identifier.</param>
        /// <param name="embed">Embed related resources.</param>
        /// <param name="fields">The fields to include in response.</param>
        /// <returns>If found <typeparamref name="T" /> is returned, otherwise null.</returns>
        public virtual async Task <CollectionModelBase <T> > GetTreeAsync <T>(object menuId, string embed = DefaultEmbed, string fields = DefaultFields) where T : Navigation
        {
            using (IBaasicClient client = BaasicClientFactory.Create(Configuration))
            {
                UrlBuilder uriBuilder = new UrlBuilder(client.GetApiUrl(String.Format("{0}/tree/{{0}}", ModuleRelativePath), menuId));
                InitializeQueryString(uriBuilder, embed, fields);
                var result = await client.GetAsync <CollectionModelBase <T> >(uriBuilder.ToString());

                if (result == null)
                {
                    result = new CollectionModelBase <T>();
                }
                return(result);
            }
        }
        /// <summary>
        /// Asynchronously find <see cref="T" /> s.
        /// </summary>
        /// <param name="schemaName">The schema name.</param>
        /// <param name="searchQuery">Search query.</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>List of <see cref="T" /> s.</returns>
        public virtual async Task <CollectionModelBase <T> > FindAsync(string schemaName, string searchQuery = ClientBase.DefaultSearchQuery, int page = ClientBase.DefaultPage, int rpp = ClientBase.DefaultMaxNumberOfResults, string sort = ClientBase.DefaultSorting, string embed = ClientBase.DefaultEmbed, string fields = ClientBase.DefaultFields)
        {
            using (IBaasicClient client = BaasicClientFactory.Create(Configuration))
            {
                UrlBuilder uriBuilder = new UrlBuilder(client.GetApiUrl("{0}/{1}", ModuleRelativePath, schemaName));
                InitializeQueryString(uriBuilder, searchQuery, page, rpp, sort, embed, fields);
                CollectionModelBase <T> result = await client.GetAsync <CollectionModelBase <T> >(uriBuilder.ToString());

                if (result == null)
                {
                    result = new CollectionModelBase <T>();
                }
                return(result);
            }
        }