Ejemplo n.º 1
0
        public async Task <IActionResult> GetSupportedCountries()
        {
            var response = new List <Country>();

            if (_ctx.Countries.Any())
            {
                response = _ctx.Countries.Where(x => !string.IsNullOrEmpty(x.FullName)).ToList();
            }
            else
            {
                var listCountries = await _holidayService.GetSupportedCountries();

                foreach (var item in listCountries)
                {
                    response.Add(new Country
                    {
                        FullName    = item.FullName,
                        CountryCode = item.CountryCode,
                        HolidayType = string.Join(", ", item.HolidayTypes),
                        FromDate    = new DateTime(item.FromDate.Year, item.FromDate.Month, item.FromDate.Day),
                        ToDate      = new DateTime(2999, item.ToDate.Month, item.ToDate.Day)
                    });
                }

                _ctx.Countries.AddRange(response);
                await _ctx.SaveChangesAsync();
            }

            return(Ok(response));
        }