本文整理汇总了C#中Models.UpdateLastLoginDate方法的典型用法代码示例。如果您正苦于以下问题:C# Models.UpdateLastLoginDate方法的具体用法?C# Models.UpdateLastLoginDate怎么用?C# Models.UpdateLastLoginDate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Models
的用法示例。
在下文中一共展示了Models.UpdateLastLoginDate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Login
public ActionResult Login( Models.User user )
{
if( ModelState.IsValid ) {
//Check if password is valid
if( user.IsPasswordValid( user.Username, user.Password ) ) {
//Password is valid, create authentication cookie
FormsAuthentication.SetAuthCookie( user.Username, false );
//Update LastLoginDate in the database for future usage statistics
user.UpdateLastLoginDate( user.Username );
//Refresh site
return RedirectToAction( "Index", "Index" );
}
else {
//Username or password is not valid, display an error
//For additional security do not specify if username exists
ModelState.AddModelError( "", "Username or password is incorrect" );
}
}
return View( user );
}
示例2: Create
public ActionResult Create( Models.User user )
{
if( ModelState.IsValid ) {
//Check if username already exists in the database
if( user.IsUsernameInUse( user.Username ) ) {
ModelState.AddModelError( "", "Username already exists, please try a different one" );
}
else {
//Username does not exist, create new user
user.CreateNewUser( user.Username, user.Password );
//Create authentication cookie for new account
FormsAuthentication.SetAuthCookie( user.Username, false );
//Update LastLoginDate in the database for future usage statistics
user.UpdateLastLoginDate( user.Username );
//Refresh site
return RedirectToAction( "Index", "Index" );
}
}
return View( user );
}