コード例 #1
0
ファイル: RoleClient.cs プロジェクト: Baasic/baasic-sdk-net
 /// <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));
     }
 }
コード例 #2
0
 /// <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));
     }
 }
コード例 #3
0
 /// <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));
     }
 }
コード例 #4
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;
            }
        }
コード例 #5
0
ファイル: UserClient.cs プロジェクト: Nodios/baasic-sdk-net
 /// <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));
     }
 }
コード例 #6
0
        /// <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;
            }
        }
コード例 #7
0
 /// <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));
     }
 }
コード例 #8
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));
     }
 }
コード例 #9
0
 /// <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));
     }
 }
コード例 #10
0
        /// <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;
            }
        }
コード例 #11
0
 /// <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));
     }
 }
コード例 #12
0
        /// <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;
            }
        }
コード例 #13
0
ファイル: UserClient.cs プロジェクト: Nodios/baasic-sdk-net
        /// <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)
        {
            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);
                }
            }
        }
コード例 #14
0
        /// <summary>
        /// Reports the comment asynchronous.
        /// </summary>
        /// <param name="commentId">The comment identifier.</param>
        /// <param name="options">The options.</param>
        /// <returns></returns>
        public virtual async Task <bool> ReportCommentAsync(SGuid commentId, ArticleCommentOptions options)
        {
            using (IBaasicClient client = BaasicClientFactory.Create(Configuration))
            {
                var result = await client.PutAsync <ArticleCommentOptions, HttpStatusCode>(client.GetApiUrl(String.Format("{0}/{{0}}/report", 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);
                }
            }
        }
コード例 #15
0
 /// <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)
 {
     try
     {
         using (IBaasicClient client = BaasicClientFactory.Create(Configuration))
         {
             return(await client.PutAsync <UpdatePasswordDTO, bool>(client.GetApiUrl(String.Format("{0}/{1}/change-password", ModuleRelativePath, userName)), recoveryParams));
         }
     }
     catch (BaasicClientException ex)
     {
         if (ex.ErrorCode == (int)HttpStatusCode.NotFound)
         {
             return(false);
         }
         throw;
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #16
0
        /// <summary>
        /// Asynchronously activates the <see cref="User" /> using activation token.
        /// </summary>
        /// <param name="activationToken">The activation token.</param>
        /// <param name="tokenOptions">The token options.</param>
        /// <returns><see cref="IAuthenticationToken" />.</returns>
        public virtual async Task <IAuthenticationToken> ActivateAsync(string activationToken, TokenOptions tokenOptions = null)
        {
            using (IBaasicClient client = BaasicClientFactory.Create(Configuration))
            {
                if (tokenOptions == null)
                {
                    tokenOptions = new TokenOptions();
                }

                var response = await client.PutAsync <Newtonsoft.Json.Linq.JObject>(client.GetApiUrl(String.Format("{0}/activate/{1}?{2}", ModuleRelativePath, activationToken, tokenOptions.GetOptionsCSV())), null);

                var token = this.ReadToken(response);

                var tokenHandler = this.Configuration.TokenHandler;
                if (tokenHandler != null)
                {
                    tokenHandler.Save(token);
                }

                return(token);
            }
        }
コード例 #17
0
 /// <summary>
 /// Asynchronously approves the <see cref="User" /> in the system.
 /// </summary>
 /// <param name="id">The identifier.</param>
 /// <returns>True if <see cref="User" /> is approved, false otherwise.</returns>
 public virtual async Task <bool> ApproveUserAsync(object id)
 {
     try
     {
         using (IBaasicClient client = BaasicClientFactory.Create(Configuration))
         {
             return(await client.PutAsync <object, bool>(client.GetApiUrl(String.Format("{0}/{{0}}/approve", ModuleRelativePath), id), new { }));
         }
     }
     catch (BaasicClientException ex)
     {
         if (ex.ErrorCode == (int)HttpStatusCode.NotFound)
         {
             return(false);
         }
         throw;
     }
     catch (Exception)
     {
         throw;
     }
 }