本文整理汇总了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();
}
示例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);
}