Ejemplo n.º 1
0
        public IMessageContext Load(IMessage input)
        {
            var cmd = input as MatchResetCommand;
            var match_created_ev = _es.Replay(typeof(MatchCreated)).First(record =>
            {
                var match_data = record.Data as MatchData;
                return(match_data.Id.Equals(cmd.MatchId));
            });

            _ctx_model = new StoreMatchResetCommandContextModel()
            {
                Tournament_id = match_created_ev.Context.Id
            };
            Update(new Event[] { match_created_ev });

            var player_strength_ev = _es.Replay(new TournamentContext(_ctx_model.Tournament_id, nameof(TournamentContext)),
                                                typeof(PlayerStrengthChanged)).Where(record =>
            {
                var data = record.Data as PlayerStrengthData;
                return(data.Match_id.Equals(cmd.MatchId));
            });

            Update(player_strength_ev);

            return(_ctx_model);
        }
        public Event[] Map_person_strength(StoreMatchResetCommandContextModel ctx_model)
        {
            var home_players_strength = Calculate_strength(ctx_model.Home_strength);
            var away_players_strength = Calculate_strength(ctx_model.Away_strength);

            var home_players_ev = Map(ctx_model.Home_player, ctx_model, home_players_strength);
            var away_players_ev = Map(ctx_model.Away_player, ctx_model, away_players_strength);

            return(home_players_ev.Concat(away_players_ev).ToArray());
        }
 private IEnumerable <Event> Map(IEnumerable <string> players,
                                 StoreMatchResetCommandContextModel ctx_model, int strength)
 {
     return(players.Select(id => new PlayerStrengthChanged(nameof(PlayerStrengthChanged),
                                                           new TournamentContext(ctx_model.Tournament_id, nameof(TournamentContext)), new PlayerStrengthData()
     {
         Match_id = ctx_model.Match_id,
         Player_id = id,
         Strength_amount = strength
     })));
 }
        public Event[] Map_person_stats(StoreMatchResetCommandContextModel ctx_model)
        {
            var all_players = ctx_model.Home_player.Concat(ctx_model.Away_player).ToList();
            var datas       = all_players.Select(player_id => Map(ctx_model.Tournament_id,
                                                                  ctx_model.Match_id,
                                                                  player_id,
                                                                  PersonMatchStatsData.Result.None));

            return(datas.Select(data => new PersonMatchStatsDeleted(nameof(PersonMatchStatsDeleted),
                                                                    new PersonsContext(data.Person_id, nameof(PersonsContext)), data)).ToArray());
        }
        private Event Map_match_reset(StoreMatchResetCommandContextModel ctx_model)
        {
            var match_reset_data = new MatchResetData()
            {
                Tournament_id = ctx_model.Tournament_id,
                Match_id      = ctx_model.Match_id
            };

            return(new MatchReseted(nameof(MatchReseted),
                                    new TournamentContext(ctx_model.Tournament_id, nameof(TournamentContext)), match_reset_data));
        }