public async Task CalculateOptimalBreakCommercialsAsync(
            string uniqueUserId,
            List <Commercial> commercials)
        {
            var breaks = await _breakFactory.GetBreaksAsync();

            var optimalBreakCommercials =
                _optimiserHelper.GetOptimalBreakCommercials(
                    breaks,
                    commercials);

            //create report
            var userReportBreaks = new List <UserReportBreak>();

            foreach (var breakCommercials in optimalBreakCommercials)
            {
                userReportBreaks.Add(
                    new UserReportBreak
                {
                    BreakTitle = breakCommercials.Break.Title,
                    UserReportBreakCommercials =
                        breakCommercials.Commercials.Select(
                            commercial =>
                            new UserReportBreakCommercial
                    {
                        CommercialTitle = commercial.Title,
                        Rating          = breakCommercials.Break.BreakDemographics.FirstOrDefault(
                            value => value.Demographic.Id == commercial.Demographic.Id)
                                          ?.Rating ?? 0
                    }).ToList(),
                    UserUniqueId = uniqueUserId
                });
            }

            await _userReportBreakFactory.AddReportBreaksAsync(uniqueUserId, userReportBreaks);
        }
Ejemplo n.º 2
0
 public async Task <List <Break> > GetBreaksAsync()
 {
     return(await _breakFactory.GetBreaksAsync());
 }