public ActionResult ListOfCouncillors(int organisationid) { MeetingAttendanceList vm = new MeetingAttendanceList( ); vm.Attendees = new List <OfficialListItem>( ); using (creo_dbEntities dbContext = new creo_dbEntities( )) { foreach (Official official in dbContext.Officials.Where(w => w.OrganisationId == organisationid)) { string url = null; urlDict.TryGetValue(official.Name, out url); if (official.Attendances.Count > 2) { vm.Attendees.Add(new OfficialListItem { Id = official.Id, Attendances = official.Attendances.Count, Name = official.Name, ProfileImageUrl = url }); } } } vm.Attendees = vm.Attendees.OrderByDescending(a => a.Attendances).ToList( ); vm.MaxAttending = vm.Attendees.Select(a => a.Attendances).Max( ); vm.Title = organisationid == 13 ? "Napier City Councillors" : "Hastings District Councillors"; return(View(vm)); }
public Organisation GetOrCreateOrganisation(creo_dbEntities dbContext, string orgName) { string nameRefined = orgName.ToLower( ).Trim( ); Organisation entity = null; if (!orgCache.TryGetValue(nameRefined, out entity)) { entity = dbContext.Organisations.FirstOrDefault(o => o.Name.ToLower( ) == nameRefined); if (entity == null) { dbContext.Organisations.Add(entity = new Organisation( ) { Name = orgName }); } orgCache.Add(nameRefined, entity); } return(entity); }
public Official GetOrCreateOfficial(creo_dbEntities dbContext, string officialName, Organisation organisation) { string nameRefined = officialName.ToLower( ).Trim( ); Official entity = null; if (!officialCache.TryGetValue(nameRefined, out entity)) { entity = dbContext.Officials.FirstOrDefault(o => o.Name.ToLower( ) == nameRefined); if (entity == null) { entity = new Official( ) { Name = officialName, Organisation = organisation }; dbContext.Officials.Add(entity); } officialCache.Add(nameRefined, entity); } return(entity); }
public Meeting GetOrCreateMeeting(creo_dbEntities dbContext, string meetingName, DateTime date, Organisation organisation) { string nameRefined = meetingName.ToLower( ).Trim( ); Meeting entity = null; if (!meetingCache.TryGetValue(nameRefined, out entity)) { entity = dbContext.Meetings.FirstOrDefault(o => o.Name.ToLower( ) == nameRefined && o.Date == date); if (entity == null) { entity = new Meeting( ) { Name = meetingName, Date = date, Organisation = organisation }; dbContext.Meetings.Add(entity); } meetingCache.Add(nameRefined, entity); } return(entity); }
public void TransformAndInsert(List <MeetingMetaData> meetingAttendances) { using (creo_dbEntities dbContext = new creo_dbEntities( )) { int i = 0; foreach (MeetingMetaData meetingAttendance in meetingAttendances) { i++; Console.WriteLine($"Processing {i} / {meetingAttendances.Count}"); // 1. Get or create organization if (string.IsNullOrEmpty(meetingAttendance.Organisation)) { Console.WriteLine("Ignoring line in file...."); continue; } Organisation org = new ConverterHelper( ).GetOrCreateOrganisation(dbContext, meetingAttendance.Organisation); // 2. Get or create meeting Meeting meeting = new ConverterHelper( ).GetOrCreateMeeting(dbContext, meetingAttendance.Meeting, meetingAttendance.Date.Date, org); // 2. Get or create official if (string.IsNullOrEmpty(meetingAttendance.Official)) { continue; } Official official = new ConverterHelper( ).GetOrCreateOfficial(dbContext, meetingAttendance.Official, org); Attendance att = new Attendance { Meeting = meeting, Official = official }; dbContext.Attendances.Add(att); dbContext.SaveChanges( ); } } }