/// <summary> /// Instantiate Card / Card Constructor /// </summary> /// <param name="rank">Card Rank Type (Enums)</param> /// <param name="suit">Card Suit Type (Enums)</param> public Card(Enums.Rank rank, Enums.Suit suit) { this._rank = rank; this._suit = suit; this._code = CardHelper.GetCardCode(this); }
public static IServiceCollection AddBlackJackServices(this IServiceCollection services, IConfiguration configuration) { services.AddTransient <IHttpContextAccessor, HttpContextAccessor>(); services.Configure <DbSettingsOptions>(configuration.GetSection("DbSettings")); bool isDapperEnabled = bool.Parse(configuration["IsDapperEnabled"]); if (isDapperEnabled) { services.AddTransient <ICardRepository, DataAccess.Repositories.Dapper.CardRepository>(); services.AddTransient <IPlayerRepository, DataAccess.Repositories.Dapper.PlayerRepository>(); services.AddTransient <IGameRepository, DataAccess.Repositories.Dapper.GameRepository>(); services.AddTransient <IRoundPlayerRepository, DataAccess.Repositories.Dapper.RoundPlayerRepository>(); services.AddTransient <IRoundPlayerCardRepository, DataAccess.Repositories.Dapper.RoundPlayerCardRepository>(); } if (!isDapperEnabled) { services.AddDbContext <GameDbContext>(); services.AddTransient <ICardRepository, DataAccess.Repositories.EntityFrameworkCore.CardRepository>(); services.AddTransient <IPlayerRepository, DataAccess.Repositories.EntityFrameworkCore.PlayerRepository>(); services.AddTransient <IGameRepository, DataAccess.Repositories.EntityFrameworkCore.GameRepository>(); services.AddTransient <IRoundPlayerRepository, DataAccess.Repositories.EntityFrameworkCore.RoundPlayerRepository>(); services.AddTransient <IRoundPlayerCardRepository, DataAccess.Repositories.EntityFrameworkCore.RoundPlayerCardRepository>(); } Mapper.Initialize(config => { config.CreateMap <RoundPlayer, PlayerGameViewModel>() .ForMember( playerGameViewModel => playerGameViewModel.PlayerName, options => options.MapFrom( roundPlayer => roundPlayer.Player.Name)) .ForMember( playerGameViewModel => playerGameViewModel.State, options => options.MapFrom( roundPlayer => roundPlayer.State)) .ForMember( playerGameViewModel => playerGameViewModel.Cards, options => options.MapFrom( roundPlayer => roundPlayer.Cards.Select(roundPlayerCard => CardHelper.GetCardCode(roundPlayerCard.Card.Suit, roundPlayerCard.Card.Rank)))) .ForMember( playerGameViewModel => playerGameViewModel.Score, options => options.MapFrom( roundPlayer => GameService.CalculateCardScore(roundPlayer.Cards.Select(roundPlayerCard => roundPlayerCard.Card)))); config.CreateMap <Game, GameGamesHistoryViewModel>() .ForMember( gameGamesHistoryViewModel => gameGamesHistoryViewModel.CreationTime, options => options.MapFrom( game => game.CreationTime)) .ForMember( gameGamesHistoryViewModel => gameGamesHistoryViewModel.PlayerCount, options => options.MapFrom( game => game.RoundPlayers.GroupBy(roundPlayer => roundPlayer.PlayerId).Count())) .ForMember( gameGamesHistoryViewModel => gameGamesHistoryViewModel.RoundCount, options => options.MapFrom( game => game.RoundPlayers.GroupBy(roundPlayer => roundPlayer.CreationTime).Count())); }); services.AddTransient <IAuthenticationService, AuthenticationService>(); services.AddTransient <IGameService, GameService>(); services.AddTransient <IHistoryService, HistoryService>(); return(services); }