Ejemplo n.º 1
0
        public List <PublicHoliday> GetAllHolidays(long year)
        {
            var holidaysToInsert = new List <PublicHoliday>();
            var allHolidays      = new List <PublicHoliday>();
            var holidaysFromDb   = _repository.GetPulbicHolidaysByYear(year);

            foreach (var enumValue in Enum.GetValues(typeof(CountryCodesEnum)))
            {
                var holidays = new List <PublicHoliday>();
                if (holidaysFromDb.Any(x => x.CountryCode == enumValue.ToString() && x.Date.Year == year))
                {
                    holidays = holidaysFromDb.Where(x => x.CountryCode == enumValue.ToString()).ToList();
                }
                else
                {
                    holidays = _naggerClient.GetPublicHolidays(year, enumValue.ToString()).Result;
                    holidays.ForEach(x => x.EndDate = x.Date.AddHours(24));
                    holidaysToInsert.AddRange(holidays);
                }
                allHolidays.AddRange(holidays);
            }
            _repository.InsertHolidaysAsync(holidaysToInsert);

            return(allHolidays);
        }
Ejemplo n.º 2
0
        public void Execute()
        {
            var year = DateTime.Now.Year;

            _repository.DeleteHolidaysByYear(year);
            foreach (var enumValue in Enum.GetValues(typeof(CountryCodesEnum)))
            {
                var holidays = _naggerClient.GetPublicHolidays(year, enumValue.ToString()).Result;
                holidays.ForEach(x => x.EndDate = x.Date.AddHours(24));
                _repository.InsertHolidays(holidays);
            }
        }