/// <summary> /// Creates the db. /// Data is read from the excel reader and added to the sets Subventions and Participants. /// </summary> public void CreateDB() { using (var context = new ReligionDatabaseContext()) { //Clears and delete the database context.Database.EnsureDeleted(); //Creates the database context.Database.EnsureCreated(); ExcelReader excel = new ExcelReader(); //Adds every Subvention from the ReadSubventionSource SubventionList into the DatabaseContext foreach (Subvention s in excel.ReadSubventionSource()) { context.Subventions.Add(s); } //Adds every Participant from the ReadParticipantSource ParticipantList into the DatabaseContext foreach (Participant p in excel.ReadParticipantSource()) { context.Participants.Add(p); } //Saves all Changes to the database context.SaveChanges(); } }
/// <summary> /// Datas the by year. /// </summary> /// <returns>The by year. Returned as a JSON string</returns> /// <param name="year">Year. Default is 2011</param> public string DataByYear(int year = 2011) { List <DataPoint> dataPoints = new List <DataPoint> (); using (var context = new ReligionDatabaseContext()) { var subventionYears = from v in context.Subventions where v.Year == year select v; foreach (var subvention in subventionYears) { dataPoints.Add(new DataPoint(subvention.Religion, subvention.SubventionAmount)); } } return(JsonConvert.SerializeObject(dataPoints)); }
/// <summary> /// Subventions by religion. /// </summary> /// <returns>The by religion. Returned as a JSON string</returns> /// <param name="religion">Religion.</param> public string SubventionsByReligion(string religion) { List <DataPoint> dataPoints = new List <DataPoint> (); using (var context = new ReligionDatabaseContext()) { var subventions = from v in context.Subventions where v.Religion == religion.Trim() select v; foreach (var subvention in subventions) { dataPoints.Add(new DataPoint(Convert.ToString(subvention.Year), subvention.SubventionAmount)); } } return(JsonConvert.SerializeObject(dataPoints)); }
/// <summary> /// Participants the by year. /// </summary> /// <returns>The by year. Returned as a JSON string.</returns> /// <param name="year">Year.</param> public string ParticipantsByYear(int year) { List <DataPoint> dataPoints = new List <DataPoint> (); using (var context = new ReligionDatabaseContext()) { var participants = from v in context.Participants where v.Year == year select v; foreach (var participant in participants) { dataPoints.Add(new DataPoint(Convert.ToString(participant.Religion), participant.ParticipantAmount)); } } return(JsonConvert.SerializeObject(dataPoints)); }