예제 #1
0
        protected async Task <Campaign> ProcessCampaign(Guid competitionKey, DateTime matchDate)
        {
            var campaign = await Provider.FindCampaignAsync(competitionKey, matchDate);

            if (campaign != null)
            {
                return(campaign);
            }

            var competitionViewModel = await Provider.GetCompetition(competitionKey, matchDate);

            if (competitionViewModel == null)
            {
                return(null);
            }

            var startDate = Date.LowDate;
            var endDate   = Date.HighDate;

            if (!competitionViewModel.GetCampaignDates(matchDate, ref startDate, ref endDate))
            {
                return(null);
            }

            var newCampaign = Campaign.CreateNew(competitionViewModel.HeaderKey, startDate, endDate);

            campaign = newCampaign;

            Provider.Add(newCampaign);
            Provider.SaveChanges();

            return(campaign);
        }
예제 #2
0
        protected async Task ProcessMatch(string lookupId, DateTime matchDate, CompetitionV competitionV, Guid?venueGuid, int?attendance, Guid team1Guid, short?team1Ht, short?team1Ft, Guid team2Guid, short?team2Ht, short?team2Ft, Guid campaignStageKey)
        {
            if (campaignStageKey == null)
            {
                return;
            }

            var lookupMatchSearch = await Provider.GetLookupMatch(ImportSite, lookupId);

            var startOfDay = matchDate.Date;
            var endOfDay   = matchDate.ToEndOfDay();

            var matchSearch = await Provider.GetMatchByTeams(team1Guid, team2Guid, matchDate);

            var campaign = await Provider.FindCampaignAsync(competitionV.HeaderKey, matchDate);

            if (campaign == null)
            {
                var startDate = Date.LowDate;
                var endDate   = Date.HighDate;

                if (!competitionV.GetCampaignDates(matchDate, ref startDate, ref endDate))
                {
                    return;
                }

                var newCampaign = Campaign.CreateNew(competitionV.HeaderKey, startDate, endDate);
                campaign = newCampaign;

                Provider.Add(newCampaign);
                Provider.SaveChanges();
            }

            if (lookupMatchSearch != null || matchSearch != null)
            {
                MatchV matchV = null;

                if (lookupMatchSearch != null)
                {
                    var lookupMatch = lookupMatchSearch;
                    matchV = (await Provider.GetMatch(lookupMatch.MatchGuid, DateTime.Now));
                }
                else if (matchSearch != null)
                {
                    matchV = matchSearch;
                }

                if (matchV == null || matchV.MatchImportType == MatchImportType.ManualResult)
                {
                    return;
                }

                matchV.MatchDate        = matchDate.Date;
                matchV.MatchTimeTicks   = (matchDate - matchDate.Date).Ticks;
                matchV.VenueGuid        = venueGuid;
                matchV.Attendance       = attendance;
                matchV.Team1Guid        = team1Guid;
                matchV.Team1HT          = team1Ht;
                matchV.Team1FT          = team1Ft;
                matchV.Team2Guid        = team2Guid;
                matchV.Team2HT          = team2Ht;
                matchV.Team2FT          = team2Ft;
                matchV.MatchImportType  = matchV.GetMatchImportType(true);
                matchV.CampaignStageKey = campaignStageKey;
            }
            else
            {
                if (matchDate < DateTime.Now && team1Ft == null && team2Ft == null)
                {
                    return;
                }

                var matchGuid = Guid.NewGuid();

                Provider.Add(new Match()
                {
                    PrimaryKey = matchGuid
                });

                var matchV = MatchV.CreateNew <MatchV>(User.GetUserId());
                matchV.HeaderKey        = matchGuid;
                matchV.MatchDate        = matchDate.Date;
                matchV.MatchTimeTicks   = (matchDate - matchDate.Date).Ticks;
                matchV.VenueGuid        = venueGuid;
                matchV.Attendance       = attendance;
                matchV.Team1Guid        = team1Guid;
                matchV.Team1HT          = team1Ht;
                matchV.Team1FT          = team1Ft;
                matchV.Team2Guid        = team2Guid;
                matchV.Team2HT          = team2Ht;
                matchV.Team2FT          = team2Ft;
                matchV.EffectiveFrom    = Date.LowDate;
                matchV.EffectiveTo      = Date.HighDate;
                matchV.MatchImportType  = matchV.GetMatchImportType(true);
                matchV.CampaignStageKey = campaignStageKey;

                Provider.Add(matchV);

                if (lookupId != string.Empty)
                {
                    Provider.Add(new LookupMatch()
                    {
                        PrimaryKey = Guid.NewGuid(),
                        ImportSite = ImportSite,
                        MatchGuid  = matchGuid,
                        LookupId   = lookupId
                    });
                }
            }

            Provider.SaveChanges();
        }