using MapoSDK; using System; using System.Collections.Generic; using System.Web.Http; namespace MP.Controllers { /// /// Controller per calcolo vacanze... /// DA ESTENDERE: deve richiedere chaive SW applicativo con licenza... e salvare la richiesta /// public class HolidayController : ApiController { /// /// Calculate Easter Sunday for any given year. /// src.: https://stackoverflow.com/a/2510411/1233379 /// /// The year to calcolate Easter against. /// a DateTime object containing the Easter month and day for the given year public static DateTime GetEasterSunday(int year) { int day = 0; int month = 0; int g = year % 19; int c = year / 100; int h = (c - (int)(c / 4) - (int)((8 * c + 13) / 25) + 19 * g + 15) % 30; int i = h - (int)(h / 28) * (1 - (int)(h / 28) * (int)(29 / (h + 1)) * (int)((21 - g) / 11)); day = i - ((year + (int)(year / 4) + i + 2 - c + (int)(c / 4)) % 7) + 28; month = 3; if (day > 31) { month++; day -= 31; } return new DateTime(year, month, day); } /// /// Elenco festività per l'anno indicato /// /// /// protected List elencoEventi(int anno) { List answ = new List(); // aggiungo le feste comandate... answ.Add(new EventDetail() { what = "Capodanno", when = new DateTime(anno, 1, 1) }); answ.Add(new EventDetail() { what = "Epifania", when = new DateTime(anno, 1, 6) }); answ.Add(new EventDetail() { what = "Lavoro", when = new DateTime(anno, 5, 1) }); answ.Add(new EventDetail() { what = "Ferragosto", when = new DateTime(anno, 8, 15) }); answ.Add(new EventDetail() { what = "Ognissanti", when = new DateTime(anno, 11, 1) }); answ.Add(new EventDetail() { what = "Immacolata", when = new DateTime(anno, 12, 8) }); answ.Add(new EventDetail() { what = "Natale", when = new DateTime(anno, 12, 25) }); answ.Add(new EventDetail() { what = "S.Stefano", when = new DateTime(anno, 12, 26) }); // Pasqua + Pasquetta answ.Add(new EventDetail() { what = "Pasqua", when = GetEasterSunday(anno) }); answ.Add(new EventDetail() { what = "Pasquetta", when = GetEasterSunday(anno).AddDays(1) }); // feste ITA answ.Add(new EventDetail() { what = "Liberazione", when = new DateTime(anno, 4, 25) }); answ.Add(new EventDetail() { what = "Repubblica", when = new DateTime(anno, 6, 2) }); return answ; } /// /// Elenco eventi anno corrente (solo ITA per ora) /// GET api/Holiday /// /// [HttpGet] public List Get() { int anno = DateTime.Now.Year; return elencoEventi(anno); } /// /// Elenco eventi anno richiesto /// GET api/Holiday/2020 /// /// [HttpGet] public List Get(int id) { // se chiede 0 --> prende anno corrente! id = id == 0 ? DateTime.Now.Year : id; return elencoEventi(id); } //// POST api/Calendar //public void Post([FromBody]string value) //{ //} //// PUT api/Calendar/5 //public void Put(int id, [FromBody]string value) //{ //} //// DELETE api/Calendar/5 //public void Delete(int id) //{ //} } }