本文整理汇总了C#中IDatabase.GetGames方法的典型用法代码示例。如果您正苦于以下问题:C# IDatabase.GetGames方法的具体用法?C# IDatabase.GetGames怎么用?C# IDatabase.GetGames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDatabase
的用法示例。
在下文中一共展示了IDatabase.GetGames方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DefaultModule
public DefaultModule( IDatabase database )
{
Get[Route.Home] = o =>
{
return Response.AsRedirect( Route.SelectGame );
};
Get[Route.SelectGame] = o =>
{
var model = new SelectGameViewModel(database.GetGames());
return View[Route.SelectGame, model];
};
}
示例2: UserProfileModule
public UserProfileModule( IDatabase database, IPasswordEncryptor passwordEncryptor )
: base(database)
{
this.passwordEncryptor = passwordEncryptor;
this.RequiresAuthentication();
Get[Route.UserProfile] = o =>
{
return View[Route.UserProfile];
};
Get[Route.ChangePassword] = o =>
{
return View[Route.ChangePassword];
};
Post[Route.ChangePassword] = o =>
{
var request = this.Bind<ChangePasswordRequest>();
var user = this.CurrentUser;
try
{
var userCredentials = database.GetUserCredentialsByUserId( user.Id );
if ( string.IsNullOrWhiteSpace( request.CurrentPassword ) )
{
throw new Exception( "Incorrect password" );
}
if ( passwordEncryptor.Encrypt( request.CurrentPassword ) != userCredentials.EncryptedPassword )
{
throw new Exception( "Incorrect password" );
}
if ( request.NewPassword1 != request.NewPassword2 )
{
throw new Exception( "Passwords don't match" );
}
var result = PasswordValidator.Validate( request.NewPassword1 );
if ( !result.IsValid )
{
throw new Exception( string.Join( ", ", result.ValidationErrors ) );
}
userCredentials.EncryptedPassword = passwordEncryptor.Encrypt( request.NewPassword1 );
database.UpdateUserCredentials( userCredentials );
}
catch ( Exception ex )
{
this.AddUserMessage( ex.Message );
return View[Route.ChangePassword];
}
this.AddUserMessage( "Your password has been changed" );
return View[Route.UserProfile];
};
Get[Route.SelectGames] = o =>
{
var model = new SelectGamesViewModel();
var availableGames = database.GetGames();
var gamesPlayedByUser = database.GetGamesPlayedByUser( ((UserIdentity)Context.CurrentUser).UserId );
foreach ( var availableGame in availableGames )
{
model.SelectableGames.Add( new Selectable<Game>
{
Item = availableGame,
IsSelected = gamesPlayedByUser.Any( game => game.Id == availableGame.Id )
} );
}
return View[Route.SelectGames, model];
};
Post[Route.SelectGames] = o =>
{
var request = this.Bind<SelectGamesRequest>();
database.SetGamesPlayedByUser(((UserIdentity)Context.CurrentUser).UserId, request.GameIds);
return Response.AsRedirect( Route.Home );
};
}