当前位置: 首页>>代码示例>>C#>>正文


C# Account.Insert方法代码示例

本文整理汇总了C#中Account.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# Account.Insert方法的具体用法?C# Account.Insert怎么用?C# Account.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Account的用法示例。


在下文中一共展示了Account.Insert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Callback

        public ActionResult Callback(string code, string state)
        {
            FacebookOAuthResult oauthResult;
            if (FacebookOAuthResult.TryParse(Request.Url, out oauthResult))
            {
                if (oauthResult.IsSuccess)
                {
                    var oAuthClient = new FacebookOAuthClient(FacebookApplication.Current);
                    oAuthClient.RedirectUri = new Uri(redirectUrl);
                    dynamic tokenResult = oAuthClient.ExchangeCodeForAccessToken(code);
                    string accessToken = tokenResult.access_token;

                    DateTime expiresOn = DateTime.MaxValue;

                    FacebookClient fbClient = new FacebookClient(accessToken);
                    dynamic me = fbClient.Get("me?fields=id,name");
                    long facebookId = Convert.ToInt64(me.id);

                    var account = Accounts.Get().Where(Accounts.Columns.ForeignID, Actions.Equal, facebookId).SelectOne();
                    if (account == null)
                    {
                        account = new Account { FBKey = accessToken, Name = me.name, ForeignID = facebookId.ToString() };
                        account.Insert();
                    }
                    else
                    {
                        account.FBKey = accessToken;
                        account.Name = me.name;
                        account.Update();
                    }
                    dynamic pages = fbClient.Get("me/accounts");
                    foreach (var p in pages.data)
                    {
                        FBPage page = FBPages.Get().Where(FBPages.Columns.ForeignID, Actions.Equal, p.id).SelectOne();
                        if (page == null)
                        {
                            page = new FBPage { ForeignID = p.id, Name = p.name, Token = p.access_token };
                            page.Insert();
                        }
                        else
                        {
                            page.Name = p.name;
                            page.Token = p.access_token;
                            page.Update();
                        }
                    }

                    ViewBag.Name = account.Name;
                }
            }

            return View();
        }
开发者ID:Otegaman,项目名称:lehavi-sap,代码行数:53,代码来源:FacebookController.cs

示例2: Register

        public void Register(string username, string password)
        {
            string message;

            username = username.Trim();

            do
            {
                if (Session != null)
                {
                    message = "You can not register while logged in.";
                    break;
                }

                if (!Util.IsValidUsername(username))
                {
                    message = Util.InvalidUsernameMessage;
                    break;
                }

                if (!Util.IsValidPassword(password))
                {
                    message = Util.InvalidPasswordMessage;
                    break;
                }

                var accountsFromAddress = Account.FindWithAddress(Address).Count();
                if (accountsFromAddress >= 3)
                {
                    message = "Too many accounts were created from this location.";
                    break;
                }

                var salt = Util.GenerateSalt();
                var account = new Account
                {
                    Address = Address,
                    Name = username,
                    Password = Convert.ToBase64String(Util.HashPassword(password, salt)),
                    Salt = Convert.ToBase64String(salt),
                    EnabledStyle = "",
                    Rooms = new string[0]
                };

                try
                {
                    account.Insert();
                }
                catch (NpgsqlException)
                {
                    message = "An account with that name already exists.";
                    break;
                }

                message = "Account created. You can now login.";
            } while (false);

            SendSysMessage(message);
        }
开发者ID:Naarkie,项目名称:RohBot,代码行数:59,代码来源:Connection.cs


注:本文中的Account.Insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。