108 lines
3.5 KiB
C#
108 lines
3.5 KiB
C#
using MapoSDK;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Web.Http;
|
|
|
|
namespace MP.Controllers
|
|
{
|
|
/// <summary>
|
|
/// Controller per calcolo vacanze...
|
|
/// DA ESTENDERE: deve richiedere chaive SW applicativo con licenza... e salvare la richiesta
|
|
/// </summary>
|
|
public class HolidayController : ApiController
|
|
{
|
|
/// <summary>
|
|
/// Calculate Easter Sunday for any given year.
|
|
/// src.: https://stackoverflow.com/a/2510411/1233379
|
|
/// </summary>
|
|
/// <param name="year">The year to calcolate Easter against.</param>
|
|
/// <returns>a DateTime object containing the Easter month and day for the given year</returns>
|
|
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);
|
|
}
|
|
/// <summary>
|
|
/// Elenco festività per l'anno indicato
|
|
/// </summary>
|
|
/// <param name="anno"></param>
|
|
/// <returns></returns>
|
|
protected List<EventDetail> elencoEventi(int anno)
|
|
{
|
|
List<EventDetail> answ = new List<EventDetail>();
|
|
// 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco eventi anno corrente (solo ITA per ora)
|
|
/// GET api/Holiday
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public List<EventDetail> Get()
|
|
{
|
|
int anno = DateTime.Now.Year;
|
|
return elencoEventi(anno);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco eventi anno richiesto
|
|
/// GET api/Holiday/2020
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public List<EventDetail> 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)
|
|
//{
|
|
//}
|
|
}
|
|
} |