Esempio n. 1
0
        public async Task HandleStaleGroups()
        {
            var allGroups = await _stockportApiRepository.GetResponse <List <Group> >();

            if (allGroups == null || !allGroups.Any())
            {
                throw new GroupsServiceException("No groups were returned from content api");
            }

            _logger.LogInformation($"Returned {allGroups.Count} groups");

            var emailPeriods = _configuration.GetArchiveEmailPeriods();

            if (emailPeriods == null || !emailPeriods.Any())
            {
                throw new GroupsServiceException("No periods returned from the service");
            }

            var fromAddress = _configuration.GetEmailEmailFrom("stockportgov");

            foreach (var period in emailPeriods)
            {
                var stagedGroups = FilterGroupsByStage(allGroups, period.NumOfDays);

                if (period.NumOfDays == emailPeriods.Select(p => p.NumOfDays).Max())
                {
                    var loopExceptions = new List <Exception>();
                    foreach (var group in stagedGroups)
                    {
                        try
                        {
                            ArchiveGroup(group);
                        }
                        catch (Exception e)
                        {
                            loopExceptions.Add(e);
                        }
                    }

                    foreach (var exception in loopExceptions)
                    {
                        _logger.LogError(exception.Message);
                    }
                }

                SendEmailToGroups(stagedGroups, period.Template, period.Subject, fromAddress.ToString());
            }
        }
Esempio n. 2
0
 public async Task <List <Event> > GetEventsByCategory(string category, bool onlyNextOccurrence = true)
 {
     return(await _stockportApiRepository.GetResponse <List <Event> >("by-category", new List <Query> {
         new Query("category", category), new Query("onlyNextOccurrence", onlyNextOccurrence.ToString())
     }));
 }