Exemplo n.º 1
0
        static async Task ProcessSeasonMessageAsync(IBusEvent message, CancellationToken c)
        {
            var payload = Encoding.UTF8.GetString(message.Body);

            _logger.LogDebug($"Received message: Body:{payload}");

            dynamic payloadvalues = JsonConvert.DeserializeObject <ExpandoObject>(payload);
            var     startdate     = new DateTime(Convert.ToInt32(payloadvalues.SeasonName.Split('-')[0]), 8, 1);
            var     enddate       = new DateTime(Convert.ToInt32(payloadvalues.SeasonName.Split('-')[0]) + 1, 5, 31);
            var     pdate         = startdate;

            while (pdate <= enddate)
            {
                dynamic jsonpayload = new ExpandoObject();
                jsonpayload.TournamentKey = payloadvalues.TournamentKey;
                jsonpayload.SeasonKey     = payloadvalues.SeasonKey;
                jsonpayload.StageKey      = payloadvalues.StageKey;
                jsonpayload.RegionKey     = payloadvalues.RegionKey;
                jsonpayload.CountryKey    = payloadvalues.CountryKey;
                jsonpayload.SeasonName    = payloadvalues.SeasonName;
                jsonpayload.SeasonPeriod  = pdate;
                var buspayload = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(jsonpayload));
                await _newseasonperiodBus.SendEvent(new BusEventBase(buspayload));

                pdate = pdate.AddDays(7);
            }
            await _newseasonBus.CompleteEvent(message.LockToken);
        }
Exemplo n.º 2
0
 public async Task <IActionResult> CreateBatch([FromBody] List <ClubSeasonRegistrationResource> resources)
 {
     if (resources == null)
     {
         return(BadRequest("A batch of club season registration resources was expected on request body!"));
     }
     if (resources.Count < 1)
     {
         return(BadRequest("At least one club season registration resource was expected to be on the request body collection!"));
     }
     try
     {
         bool dochange = false;
         foreach (var r in resources)
         {
             if (!_context.Clubs.Any(x => x.Key == r.ClubKey))
             {
                 dochange = true;
                 var club = new Club()
                 {
                     Key         = r.ClubKey,
                     Name        = r.ClubName,
                     NickName    = r.ClubNickName,
                     CountryKey  = r.CountryKey,
                     StadiumName = r.StadiumName,
                 };
                 _context.Clubs.Add(club);
             }
             if (!_context.ClubSeasonAssociations.Any(x => x.ClubKey == r.ClubKey && x.SeasonKey == r.SeasonKey))
             {
                 dochange = true;
                 var association = new ClubSeasonAssociation()
                 {
                     ClubKey   = r.ClubKey,
                     SeasonKey = r.SeasonKey
                 };
                 _context.ClubSeasonAssociations.Add(association);
                 await _newClubSeasonRegistrationBus.SendEvent(BuildNewClubSeasonAssociationEvent(r.ClubKey, r.StageKey, r.SeasonKey));
             }
         }
         if (dochange)
         {
             await _context.SaveChangesAsync();
         }
         return(Ok());
     }
     catch (DbUpdateException pkex)
     {
         // TODO: we are seeing this occaisionally due to async processing from multiple instances
         //       its ok to swallow as we dont support data updates and if the key exists there is no need for dupe store
         return(Conflict($"A primary key violation occured while saving club season participation data: { pkex.Message }"));
     }
 }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([FromBody] SeasonResource model)
        {
            try
            {
                bool dochange = false;
                if (!_context.Seasons.Any(x => x.Key == model.SeasonKey))
                {
                    dochange = true;
                    var season = new Season()
                    {
                        Key            = model.SeasonKey,
                        Name           = model.Name,
                        TournamentName = model.TournamentName,
                        StartDate      = model.StartDate,
                        EndDate        = model.EndDate,

                        TournamentKey = model.TournamentKey,
                        CountryKey    = model.CountryKey,
                        RegionKey     = model.RegionKey,
                        StageKey      = model.StageKey
                    };
                    _context.Seasons.Add(season);
                    await _newSeasonRegistrationBus.SendEvent(BuildNewSeasonEvent(model.TournamentKey, model.SeasonKey, model.StageKey, model.RegionKey, model.CountryKey, model.Name));
                }
                else
                {
                    Conflict($"The key '{model.SeasonKey}' already exists!");
                }
                if (dochange)
                {
                    await _context.SaveChangesAsync();
                }
                return(Ok(model));
            }
            catch (DbUpdateException pkex)
            {
                // TODO: we are seeing this occaisionally due to async processing from multiple instances
                //       its ok to swallow as we dont support data updates and if the key exists there is no need for dupe store
                return(Conflict($"A primary key violation occured while saving player data: { pkex.Message }"));
            }
        }
Exemplo n.º 4
0
        public async Task <IActionResult> CreateBatch([FromBody] List <FixtureParticipantsModel> model)
        {
            try
            {
                // create player dto from model and save if key is new
                bool dochange = false;
                foreach (var p in model)
                {
                    if (!_context.Fixtures.Any(x => x.Key == p.FixtureKey))
                    {
                        dochange = true;
                        var fixture = new Models.Fixture()
                        {
                            Key         = p.FixtureKey,
                            SeasonKey   = p.SeasonKey,
                            HomeClubKey = p.HomeClubKey,
                            AwayClubKey = p.AwayClubKey,
                            KickOffTime = p.KickOffTime,
                            FinalScore  = p.FinalScore,
                        };
                        _context.Fixtures.Add(fixture);
                        await _fixturebus.SendEvent(BuildNewFixtureEvent(p.FixtureKey, p.RegionKey, p.TournamentKey));
                    }
                    if (!_context.ClubFixtureAppearances.Any(x => x.FixtureKey == p.FixtureKey &&
                                                             x.ClubKey == p.HomeClubKey &&
                                                             x.IsHomeTeam))
                    {
                        dochange = true;
                        var homeassociation = new ClubFixtureAppearance()
                        {
                            ClubKey       = p.HomeClubKey,
                            SeasonKey     = p.SeasonKey,
                            FixtureKey    = p.FixtureKey,
                            GoalsScored   = p.HomeGoalsScored,
                            GoalsConceded = p.HomeGoalsConceded,
                            IsHomeTeam    = true
                        };
                        _context.ClubFixtureAppearances.Add(homeassociation);
                    }
                    if (!_context.ClubFixtureAppearances.Any(x => x.FixtureKey == p.FixtureKey &&
                                                             x.ClubKey == p.AwayClubKey &&
                                                             !x.IsHomeTeam))
                    {
                        dochange = true;
                        var awayassociation = new ClubFixtureAppearance()
                        {
                            ClubKey       = p.AwayClubKey,
                            SeasonKey     = p.SeasonKey,
                            FixtureKey    = p.FixtureKey,
                            GoalsScored   = p.AwayGoalsScored,
                            GoalsConceded = p.AwayGoalsConceded,
                            IsHomeTeam    = false
                        };
                        _context.ClubFixtureAppearances.Add(awayassociation);
                    }
                }
                if (dochange)
                {
                    await _context.SaveChangesAsync();
                }
                return(Ok());
            }
            catch (DbUpdateException pkex)
            {
                // TODO: we are seeing this occaisionally due to async processing from multiple instances
                //       its ok to swallow as we dont support data updates and if the key exists there is no need for dupe store

                return(Conflict($"A primary key violation occured while saving player data: { pkex.Message }"));
            }
        }