UpdateKey() public method

public UpdateKey ( APIKey key ) : bool
key APIKey
return bool
示例#1
0
    public static Hashtable UpdateKey(string Key, string Description)
    {
        System.Collections.Hashtable ht = new System.Collections.Hashtable();
        HttpContext context             = HttpContext.Current;

        if (context.User.Identity.IsAuthenticated)
        {
            try
            {
                vwar.service.host.APIKeyManager keyMan = new vwar.service.host.APIKeyManager();
                if (keyMan.GetUserByKey(Key).Equals(context.User.Identity.Name))
                {
                    vwar.service.host.APIKey currentKey = keyMan.GetKeyByKey(Key);
                    currentKey.Usage = context.Server.HtmlEncode(Description);
                    if (keyMan.UpdateKey(currentKey))
                    {
                        ht["Message"] = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyUpdateSuccess"];
                        ht["Usage"]   = currentKey.Usage;
                    }
                    else
                    {
                        ht["Message"] = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyUpdateError"];
                    }
                }
                else
                {
                    ht["Message"] = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyUpdateError"];
                }
            }
            catch
            {
                ht["Message"] = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyUpdateError"];
            }
        }
        else
        {
            context.Response.StatusCode = 401;
        }

        return(ht);
    }
    public static Hashtable UpdateKey(string Key, string Description)
    {
        System.Collections.Hashtable ht = new System.Collections.Hashtable();
        HttpContext context = HttpContext.Current;
        if (context.User.Identity.IsAuthenticated)
        {
            try
            {
                vwar.service.host.APIKeyManager keyMan = new vwar.service.host.APIKeyManager();
                if (keyMan.GetUserByKey(Key).Equals(context.User.Identity.Name))
                {
                    vwar.service.host.APIKey currentKey = keyMan.GetKeyByKey(Key);
                    currentKey.Usage = context.Server.HtmlEncode(Description);
                    if (keyMan.UpdateKey(currentKey))
                    {
                        ht["Message"] = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyUpdateSuccess"];
                        ht["Usage"] = currentKey.Usage;
                    }
                    else
                    {
                        ht["Message"] = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyUpdateError"];
                    }
                }
                else
                {
                    ht["Message"] = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyUpdateError"];
                }
            }
            catch
            {
                ht["Message"] = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyUpdateError"];
            }

        }
        else
        {
            context.Response.StatusCode = 401;
        }

        return ht;
    }