Ejemplo n.º 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);
        }