Ejemplo n.º 1
0
        public async Task SendAsync()
        {
            var jumpStarts = new List <JumpStart>();
            var settings   = await _settingsService.GetValueAsync <VolkswagenSettings>(VolkswagenCompany.Slug);

            var dailyPlans = await _jumpStartPlanService.GetAsync();

            dailyPlans = dailyPlans.Where(item => item.DateTime < DateTime.UtcNow.AddMinutes(15)).ToList();

            foreach (var dailyPlan in dailyPlans)
            {
                var jumpStart = dailyPlan.JumpStart;

                if (jumpStart is null)
                {
                    if (!settings.EnableAutoSend)
                    {
                        // Do not send these articles because admin didn't schedule it and the auto send is off
                        continue;
                    }

                    jumpStart = await CreateJumpStart(dailyPlan.DateTime, dailyPlan.DistributionGroups,
                                                      dailyPlan.Articles);
                }

                jumpStart.Status = JumpStartStatus.Sending;
                jumpStarts.Add(jumpStart);
            }

            _dbContext.UpdateRange(jumpStarts);
            await _dbContext.SaveChangesAsync();

            foreach (var jumpStart in jumpStarts)
            {
                _backgroundJobClient.Enqueue <JumpStartPdfJob>(service =>
                                                               service.CreatePdfAsync(jumpStart.Id));
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <List <JumpStartPlanResult> > > DailyPlan()
        {
            var dailyPlan = await _jumpStartPlanService.GetAsync();

            return(Ok(dailyPlan.Select(item => new JumpStartPlanResult(item))));
        }