public void Initialise(dynamic viewBag, SceneCRM context, IEnumerable<VolunteerAllocation> currentVolunteers) { var volunteers = context.Volunteers .ToArray() .OrderBy(v => v.IsEligible) .Select(v => new { Id = v.VolunteerId.ToString(), Name = string.Format("{0}, {1}{2}", v.Surname, v.FirstName, v.IsEligible ? string.Empty : " (NOT ELIGIBLE)") }) .ToDictionary(v => v.Id, v => v.Name); var jobs = context.Jobs .Select(j => new { Id = j.JobId, Name = j.Description }) .ToDictionary(j => j.Id.ToString(), j => j.Name); var currentVolunteerModel = currentVolunteers .Select(cv => new { jobId = cv.JobId.ToString(), volunteerId = cv.VolunteerId.ToString(), notes = cv.Notes }) .OrderBy(cv => cv.jobId); viewBag.CurrentVolunteers = currentVolunteerModel; viewBag.PossibleVolunteers = volunteers; viewBag.PossibleJobs = jobs; }
static void WipeDatabase(SceneCRM context) { throw new NotImplementedException("Needs chaning over to context.*.Remove"); /* context.Courses.ToList().ForEach(context.Courses.DeleteObject); context.CourseAttendances.ToList().ForEach(context.CourseAttendances.DeleteObject); context.CourseTypes.ToList().ForEach(context.CourseTypes.DeleteObject); context.CourseVolunteers.ToList().ForEach(context.CourseVolunteers.DeleteObject); context.CrbChecks.ToList().ForEach(context.CrbChecks.DeleteObject); context.Jobs.ToList().ForEach(context.Jobs.DeleteObject); context.Performances.ToList().ForEach(context.Performances.DeleteObject); context.Plays.ToList().ForEach(context.Plays.DeleteObject); context.PlayVolunteers.ToList().ForEach(context.PlayVolunteers.DeleteObject); context.Productions.ToList().ForEach(context.Productions.DeleteObject); context.ProductionVolunteers.ToList().ForEach(context.ProductionVolunteers.DeleteObject); context.Students.ToList().ForEach(context.Students.DeleteObject); context.Terms.ToList().ForEach(context.Terms.DeleteObject); context.Volunteers.ToList().ForEach(context.Volunteers.DeleteObject); */ context.SaveChanges(); }
static void PopulateJobTypes(SceneCRM context) { context.Jobs.FindOrMake(Jobs.Actor, context); context.Jobs.FindOrMake(Jobs.Class, context); context.Jobs.FindOrMake(Jobs.Costume, context); context.Jobs.FindOrMake(Jobs.CostumePropMaker, context); context.Jobs.FindOrMake(Jobs.CourseLeader, context); context.Jobs.FindOrMake(Jobs.Designer, context); context.Jobs.FindOrMake(Jobs.Director, context); context.Jobs.FindOrMake(Jobs.Dramaturg, context); context.Jobs.FindOrMake(Jobs.Mailout, context); context.Jobs.FindOrMake(Jobs.ProdAsst, context); context.Jobs.FindOrMake(Jobs.SoundDesigner, context); context.Jobs.FindOrMake(Jobs.StageMan, context); context.Jobs.FindOrMake(Jobs.TechAsst, context); context.Jobs.FindOrMake(Jobs.Technician, context); }
static void Main(string[] args) { HibernatingRhinos.Profiler.Appender.EntityFramework.EntityFrameworkProfiler.Initialize(); using (var context = new SceneCRM()) { WipeDatabase(context); oneOnOne = context.CourseTypes.FindOrMake("OO", "One on One", context); pm1 = context.CourseTypes.FindOrMake("PM1", "Playmaking One", context); rp = context.CourseTypes.FindOrMake("RP", "Replay", context); s1 = context.CourseTypes.FindOrMake("S1", "Stage One", context); pb = context.CourseTypes.FindOrMake("PB", "Playback", context); PopulateJobTypes(context); var ss = new ChildrenProductionsSpreadsheet(@"C:\Users\dylan.beattie\Documents\Scene & Heard\Children and Productions.xls"); foreach (var row in ss.Rows) { var student = context.Students.FindOrMake(row.MembershipNumber, row.Forename, row.Surname, context); student.QuestionnaireResponse = row.QuestionnaireResponses; ImportPlaymakingOne(context, student, row); ImportPlayback(context, student, row); ImportReplay(context, student, row); ImportStageOne(context, student, row); ImportOneOnOne(context, student, row); Console.WriteLine("Added " + student.Forename + " " + student.Surname); context.SaveChanges(); } ImportVolunteerDataFromAccessDatabase(context, @"C:\Users\dylan.beattie\Documents\Scene & Heard\Volunteers.mdb", "giraffe"); } Console.ReadKey(false); }
static void ImportVolunteerDataFromAccessDatabase(SceneCRM context, string fullPathToMdbFile, string databasePassword) { AccessVolunteers av = new AccessVolunteers(); var adapter = new LegacyData.AccessVolunteersTableAdapters.AddressTableAdapter(); var data = adapter.GetData(); foreach (LegacyData.AccessVolunteers.AddressRow row in data.Rows) { var volunteer = context.Volunteers.FindOrMake(row.First_Name, row.Last_Name, context); Console.WriteLine("Volunteer {0} {1} (#{2})", volunteer.FirstName, volunteer.Surname, volunteer.VolunteerId); volunteer.AccessPersonId = row.Person_ID; var address = row.IsAddressNull() ? String.Empty : row.Address; if (!(row.IsAddress_1Null() || String.IsNullOrWhiteSpace(row.Address_1))) address += Environment.NewLine + row.Address_1; if (!(row.IsAddress_2Null() || String.IsNullOrWhiteSpace(row.Address_2))) address += Environment.NewLine + row.Address_2; volunteer.PerformanceAttended = "(imported from Access DB)"; volunteer.Address = address; volunteer.AgentName = row.IsAgent_NameNull() ? null : row.Agent_Name; volunteer.CvWebUrl = row.IsCVNull() ? null : row.CV; volunteer.Deadwood = row.IsDeadwoodNull() ? false : row.Deadwood; volunteer.EEDirectDebit = row.Is_E_E_Direct_DebitNull() ? false : row._E_E_Direct_Debit; volunteer.EmailAddress = row.IsEmail_AddressNull() ? null : row.Email_Address; volunteer.EmailAddress2 = row.IsEmail_Address_2Null() ? null : row.Email_Address_2; volunteer.EyesEars = row.Is_Eyes___EarsNull() ? false : row._Eyes___Ears; volunteer.MobilePhone = row.IsMobile_telephoneNull() ? null : row.Mobile_telephone; volunteer.NoMailout = row.IsNo_MailoutNull() ? false : row.No_Mailout; volunteer.Notes = row.IsNotesNull() ? null : row.Notes; volunteer.Organisation = row.IsOrganisationNull() ? null : row.Organisation; volunteer.OtherProfession = row.IsOther_ProfessionNull() ? null : row.Other_Profession; volunteer.PartnerFirstName = row.IsSecond_Person_1st_NameNull() ? null : row.Second_Person_1st_Name; volunteer.PartnerSurname = row.IsSecond_Person_Last_NameNull() ? null : row.Second_Person_Last_Name; volunteer.Postcode = row.IsPostcodeNull() ? null : row.Postcode; volunteer.SpotlightNumber = row.IsSpotlight_NumberNull() ? false : row.Spotlight_Number; volunteer.Trustee = row.Is_Trustee_Board_MemberNull() ? false : row._Trustee_Board_Member; volunteer.CrbChecks.Clear(); if (!(row.IsCRB_NumberNull() && row.IsDate_applied_CRBNull() && row.IsCRB_appliedNull() && row.IsCRB_ApprovedNull())) { volunteer.CrbChecks.Add(new CrbCheck() { Volunteer = volunteer, CrbNumber = row.IsCRB_NumberNull() ? null : row.CRB_Number, ApplicationDate = row.IsDate_applied_CRBNull() ? (DateTime?)null : row.Date_applied_CRB, ApplicationSent = row.IsCRB_appliedNull() ? false : row.CRB_applied, Approved = row.IsCRB_ApprovedNull() ? false : row.CRB_Approved, ApprovalDate = row.IsCRB_DateNull() ? (DateTime?)null : row.CRB_Date }); } volunteer.Jobs.Clear(); AddJob(context, volunteer, ((!(row.IsActorNull())) && row.Actor), Jobs.Actor); AddJob(context, volunteer, ((!(row.IsDirectorNull())) && row.Director), Jobs.Director); AddJob(context, volunteer, ((!(row.IsTechnicianNull())) && row.Technician), Jobs.Technician); AddJob(context, volunteer, ((!(row.Is_Costume_Prop_MakerNull())) && row._Costume_Prop_Maker), Jobs.CostumePropMaker); } }
static void ImportStageOne(SceneCRM context, Student student, ChildrenProductionsSpreadsheet.Row row) { if (row.AttendedStageOne) { ImportPlay(context, student, s1, row.StageOneTerm, row.StageOneYear, String.Empty, String.Empty, String.Empty, String.Empty, row.StageOneActor); } }
static void ImportReplay(SceneCRM context, Student student, ChildrenProductionsSpreadsheet.Row row) { if (row.AttendedReplay) { ImportPlay(context, student, rp, row.ReplayTerm, row.ReplayYear, row.ReplayProduction, row.ReplayPlay, row.ReplayDramaturg, row.ReplayDirector, row.ReplayActor1, row.ReplayActor2, row.ReplayActor3); } }
static void ImportPlaymakingOne(SceneCRM context, Student student, ChildrenProductionsSpreadsheet.Row row) { if (row.AttendedPm1) { ImportPlay(context, student, pm1, row.PlaymakingOneTerm, row.PlaymakingOneYear, row.PlaymakingOneProduction, row.PlaymakingOnePlay, row.PlaymakingOneDramaturg, row.PlaymakingOneDirector, row.PlaymakingOneActor1, row.PlaymakingOneActor2, row.PlaymakingOneActor3); //var term = context.Terms.FindOrMake(row.PlaymakingOneTerm); //var course = context.Courses.FindOrMake(pm1, term, row.PlaymakingOneYear); //if (course != null) { // var attendance = new CourseAttendance() { // Student = student, // Course = course, // Completed = true // }; // Production production = context.Productions.FindOrMake(row.PlaymakingOneProduction); // if (!String.IsNullOrWhiteSpace(row.PlaymakingOnePlay)) { // var play = new Play() { // Student = student, // Title = row.PlaymakingOnePlay // }; // if (production != null) play.Production = production; // attendance.Play = play; // student.Plays.Add(play); // AddPlayVolunteer(context, play, row.PlaymakingOneDramaturg, Jobs.Dramaturg); // AddPlayVolunteer(context, play, row.PlaymakingOneDirector, Jobs.Director); // AddPlayVolunteer(context, play, row.PlaymakingOneActor1, Jobs.Actor); // AddPlayVolunteer(context, play, row.PlaymakingOneActor2, Jobs.Actor); // AddPlayVolunteer(context, play, row.PlaymakingOneActor3, Jobs.Actor); // } else { // AddCourseVolunteer(context, course, row.PlaymakingOneDramaturg, Jobs.Dramaturg); // AddCourseVolunteer(context, course, row.PlaymakingOneActor1, Jobs.Actor); // AddCourseVolunteer(context, course, row.PlaymakingOneActor2, Jobs.Actor); // AddCourseVolunteer(context, course, row.PlaymakingOneActor3, Jobs.Actor); // AddCourseVolunteer(context, course, row.PlaymakingOneDirector, Jobs.Director); // } // student.CourseAttendances.Add(attendance); } }
static void ImportPlayback(SceneCRM context, Student student, ChildrenProductionsSpreadsheet.Row row) { if (row.AttendedPlayback) { ImportPlay(context, student, pb, "Playback", row.PlaybackYear, row.PlaybackProduction, row.PlaybackPlay, row.PlaybackDramaturg, row.PlaybackDirector, row.PlaybackActor ); } }
static object ImportPlay(SceneCRM context, Student student, CourseType courseType, string termName, string termYear, string productionName, string playName, string dramaturg, string director, params string[] actors) { object returnValue = null; var term = context.Terms.FindOrMake(termName, context); var course = context.Courses.FindOrMake(courseType, term, termYear, context); if (course != null) { var attendance = new CourseAttendance() { Student = student, Course = course, Completed = true }; Production production = context.Productions.FindOrMake(productionName, context); if (!String.IsNullOrWhiteSpace(playName)) { var play = new Play() { Student = student, Title = playName }; if (production != null) play.Production = production; attendance.Play = play; student.Plays.Add(play); AddPlayVolunteer(context, play, dramaturg, Jobs.Dramaturg); AddPlayVolunteer(context, play, director, Jobs.Director); foreach (var actor in actors) { AddPlayVolunteer(context, play, actor, Jobs.Actor); } returnValue = play; } else { AddCourseVolunteer(context, course, dramaturg, Jobs.Dramaturg); AddCourseVolunteer(context, course, director, Jobs.Director); foreach (var actor in actors) { AddCourseVolunteer(context, course, actor, Jobs.Actor); } returnValue = course; } student.CourseAttendances.Add(attendance); } return(returnValue); }
static void ImportOneOnOne(SceneCRM context, Student student, ChildrenProductionsSpreadsheet.Row row) { if (row.AttendedOneOnOne) { ImportPlay(context, student, oneOnOne, row.OneonOneTerm, row.OneonOneYear, row.OneonOneProduction, row.OneonOnePlay, row.OneonOneWriter, row.OneonOneDirector, row.OneonOneActor); } }
static void AddPlayVolunteer(SceneCRM context, Play play, string volunteerName, string jobTitle) { var vol = context.Volunteers.FindOrMake(volunteerName, context); if (vol == null) return; var job = context.Jobs.FindOrMake(jobTitle, context); if (!vol.PlayVolunteers.Any(cv => cv.Job == job && cv.Play == play)) { context.PlayVolunteers.Add(new PlayVolunteer() { Play = play, Volunteer = vol, Job = job }); } context.SaveChanges(); }
static void AddJob(SceneCRM context, Volunteer volunteer, bool condition, string jobTitle) { if (!condition) return; var job = context.Jobs.FindOrMake(jobTitle, context); if (!volunteer.Jobs.Contains(job)) { Console.WriteLine("Marking {0} as a {1}", volunteer.Name, job.Description); volunteer.Jobs.Add(job); } context.SaveChanges(); }
static void AddCourseVolunteer(SceneCRM context, Course course, string volunteerName, string jobTitle) { var vol = context.Volunteers.FindOrMake(volunteerName, context); if (vol == null) return; var job = context.Jobs.FindOrMake(jobTitle, context); if (!vol.CourseVolunteers.Any(cv => cv.Job == job && cv.Course == course)) { context.CourseVolunteers.Add(new CourseVolunteer() { Course = course, Volunteer = vol, Job = job }); } context.SaveChanges(); }
public void Initialise(dynamic viewBag, SceneCRM context) { Initialise(viewBag, context, new VolunteerAllocation[0]); }