當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。