public iNote SaveNote(Note myNote) { //We will do this within a single Context using (var ctx = new JobLeadContext()) { //Currently we have no sub-entities that we need to find and attach if (myNote.NoteID == 0) { //New note ctx.Notes.Add(myNote); ctx.SaveChanges(); //Having saved the note, we pass it back so we can add it to whatever class requested it to be made. return(myNote); } else { //Update existing note (will this ever happen?) var contextNoteEntity = ctx.Notes.Where(s => s.NoteID == myNote.NoteID).FirstOrDefault <Note>(); contextNoteEntity.NoteDate = myNote.NoteDate; contextNoteEntity.NoteText = myNote.NoteText; ctx.SaveChanges(); return(contextNoteEntity); } } }
public iAddress SaveAddress(Address myAddress) { //We will do this within a single Context using (var ctx = new JobLeadContext()) { //Currently we have no sub-entities that we need to find and attach if (myAddress.AddressID == 0) { //New address ctx.Addresses.Add(myAddress); ctx.SaveChanges(); //Having saved the address, we pass it back so we can add it to whatever class requested it to be made. return(myAddress); } else { //Update existing address var contextAddressEntity = ctx.Addresses.Where(s => s.AddressID == myAddress.AddressID).FirstOrDefault <Address>(); contextAddressEntity.BodyText = myAddress.BodyText; contextAddressEntity.City = myAddress.City; contextAddressEntity.Region = myAddress.Region; contextAddressEntity.Country = myAddress.Country; contextAddressEntity.Postcode = myAddress.Postcode; ctx.SaveChanges(); return(contextAddressEntity); } } }
public iName SaveName(Name myName) { //We will do this within a single Context using (var ctx = new JobLeadContext()) { //Currently we have no sub-entities that we need to find and attach if (myName.NameID == 0) { //New address ctx.Names.Add(myName); ctx.SaveChanges(); //Having saved the address, we pass it back so we can add it to whatever class requested it to be made. return(myName); } else { //Update existing name var contextNameEntity = ctx.Names.Where(s => s.NameID == myName.NameID).FirstOrDefault <Name>(); contextNameEntity.Title = myName.Title; contextNameEntity.FirstName = myName.FirstName; contextNameEntity.MiddleName = myName.MiddleName; contextNameEntity.Surname = myName.Surname; ctx.SaveChanges(); return(contextNameEntity); } } }
public iJobLead GetJobLead(int myJobLeadID) { //Here is where we decide the depth of information extracted for a Job Lead instance using (var ctx = new JobLeadContext()) { iJobLead thisFullJobLead = ctx.JobLeads .Include("AgencyBroker") .Include("AgencyBroker.Brokers") .Include("AgencyBroker.Address") .Include("AgencyBroker.BrokerNotes") .Include("AgencyBroker.Contacts.Address") .Include("AgencyBroker.Contacts.Name") .Include("AgencyBroker.Contacts.ContactNotes") .Include("EmployerBroker") .Include("EmployerBroker.Brokers") .Include("EmployerBroker.Address") .Include("EmployerBroker.BrokerNotes") .Include("EmployerBroker.Contacts.Address") .Include("EmployerBroker.Contacts.Name") .Include("EmployerBroker.Contacts.ContactNotes") .Include("JobLeadNotes") .Where(s => s.JobLeadID == myJobLeadID) .FirstOrDefault <iJobLead>(); //Apparently it is OK to return in a Using block. The finalising code will still be called. return(thisFullJobLead); } }
public object GetJobLeadGridDatasource() { using (var ctx = new JobLeadContext()) { var allLeadsTable = from m in ctx.JobLeads orderby m.JobLeadID descending select new { m.JobLeadID, m.JobTitle, m.Date, m.Status, m.Ref_One, m.Ref_Two, m.Ref_Three, Employer = m.EmployerBroker.Name, Agency = m.AgencyBroker.Name, Contact = m.AgencyContact.Name.FirstName + " " + m.AgencyContact.Name.Surname, Notes = m.JobLeadNotes.Count }; return(allLeadsTable.ToList()); } }
public object GetAgencyContactsDatasource() { using (var ctx = new JobLeadContext()) { var allAgencyContactsTable = from m in ctx.Contacts orderby m.Name.Surname ascending select new { m.ContactID, Agency = m.Broker.Name, Name = m.Name.FirstName + " " + m.Name.Surname, m.LandLineTelNo, m.MobileTelNo, m.ContactNotes.Count }; return(allAgencyContactsTable.ToList()); } }
public List <Broker> GetAllUnassociatedBrokers(List <Broker> currentAssociatedBrokers, bool isAgency) { using (var ctx = new JobLeadContext()) { var brokerIDs = currentAssociatedBrokers.Select(x => x.BrokerID).ToArray(); //We invert the isAgency value so that we only find Employer brokers if this is am Agency broker, and vice versa (that's your actual Latin) var allUnassociatedBrokers = ctx.Brokers.Where(x => !brokerIDs.Contains(x.BrokerID) && x.IsAgency == !isAgency).OrderBy(x => x.Name); return(allUnassociatedBrokers.ToList()); } }
public object GetAgencyBrokersDatasource() { using (var ctx = new JobLeadContext()) { var allAgencyTable = from m in ctx.Brokers where m.IsAgency == true orderby m.Name ascending select new { m.BrokerID, m.Name, Address = m.Address.BodyText.Replace(",", ", ") + ", " + m.Address.City + ", " + m.Address.Postcode, Phone = m.LandLineTelNo, Notes = m.BrokerNotes.Count }; return(allAgencyTable.ToList()); } }
public object GetAllBrokers(bool isAgency) { using (var ctx = new JobLeadContext()) { var allBrokersList = from m in ctx.Brokers where m.IsAgency == isAgency orderby m.Name select m; return(allBrokersList.ToList()); } }
public object GetJobTitleFilteredJobLeadGridDataSource(string jobTitleToSearchFor) { using (var ctx = new JobLeadContext()) { var allLeadsTable = from m in ctx.JobLeads where m.JobTitle.Contains(jobTitleToSearchFor) orderby m.JobLeadID descending //select new { m.JobLeadID, m.JobTitle, m.Date, m.Status, m.Ref_One, m.Ref_Two, m.Ref_Three, Agency = m.AgencyBroker.Name }; select new { m.JobLeadID, m.JobTitle, m.Date, m.Status, m.Ref_One, m.Ref_Two, m.Ref_Three, Employer = m.EmployerBroker.Name, Agency = m.AgencyBroker.Name, Contact = m.AgencyContact.Name.FirstName + " " + m.AgencyContact.Name.Surname, Notes = m.JobLeadNotes.Count }; return(allLeadsTable.ToList()); } }
public Contact GetContact(int thisContactID) { using (var ctx = new JobLeadContext()) { Contact thisContact = ctx.Contacts .Include("Address") .Include("Name") .Include("ContactNotes") .Where(m => m.ContactID == thisContactID) .FirstOrDefault <Contact>(); return(thisContact); } }
public Broker GetBroker(int thisBrokerID) { using (var ctx = new JobLeadContext()) { Broker thisBroker = ctx.Brokers .Include("Address") .Include("Contacts.Address") .Include("Contacts.Name") .Include("Contacts.ContactNotes") .Include("Brokers") .Include("BrokerNotes") .Where(m => m.BrokerID == thisBrokerID) .FirstOrDefault <Broker>(); return(thisBroker); } }
public iContact SaveContact(Contact myContact) { using (var ctx = new JobLeadContext()) { //If we have a ContactID of 0 (zero), then this is a new job. if (myContact.ContactID == 0) { if (myContact.Name.NameID != 0) { var newNameEntity = ctx.Names.Where(s => s.NameID == myContact.Name.NameID).FirstOrDefault <Name>(); myContact.Name = newNameEntity; } if (myContact.Address.AddressID != 0) { var newAddressEntity = ctx.Addresses.Where(s => s.AddressID == myContact.Address.AddressID).FirstOrDefault <Address>(); myContact.Address = newAddressEntity; } //Add it to the context. ctx.Contacts.Add((Contact)myContact); ctx.SaveChanges(); return(myContact); } else //Otherwise we update the existing one. { //Get the Contact entity we are updating var contextContactEntity = ctx.Contacts.Include("Name").Include("Address").Where(s => s.ContactID == myContact.ContactID).FirstOrDefault <Contact>(); //Set all the JobLead entity level values. contextContactEntity.Position = myContact.Position; contextContactEntity.Email = myContact.Email; contextContactEntity.LandLineTelNo = myContact.LandLineTelNo; contextContactEntity.MobileTelNo = myContact.MobileTelNo; //Now we attach the Name and Address sub entities if (myContact.Name.NameID != 0) { var newNameEntity = ctx.Names.Where(s => s.NameID == myContact.Name.NameID).FirstOrDefault <Name>(); contextContactEntity.Name = newNameEntity; } if (myContact.Address.AddressID != 0) { var newAddressEntity = ctx.Addresses.Where(s => s.AddressID == myContact.Address.AddressID).FirstOrDefault <Address>(); contextContactEntity.Address = newAddressEntity; } //Now to iterate through the ContactNotes and add in any new ones foreach (Note thisNote in myContact.ContactNotes) { //Get the context version of the current note var newNoteEntity = ctx.Notes.Where(s => s.NoteID == thisNote.NoteID).FirstOrDefault <Note>(); //See if it is already attached to the context version of this contact if (!contextContactEntity.ContactNotes.Contains(newNoteEntity)) { contextContactEntity.ContactNotes.Add(newNoteEntity); } } ctx.SaveChanges(); return(contextContactEntity); } } }
//public void SaveBroker(Broker myBroker) public Broker SaveBroker(Broker myBroker) { //We will do this within a single Context using (var ctx = new JobLeadContext()) { if (myBroker.BrokerID == 0) { //Extract and attach the Address from the context if (myBroker.Address != null) { var contextAddressEntity = ctx.Addresses.Where(s => s.AddressID == myBroker.Address.AddressID).FirstOrDefault <Address>(); myBroker.Address = contextAddressEntity; } //Extract and add all the Contacts from the context List <Contact> newContactList = new List <Contact>(); foreach (Contact thisContact in myBroker.Contacts) { var contextContactEntity = ctx.Contacts.Include("Name").Include("Address").Where(s => s.ContactID == thisContact.ContactID).FirstOrDefault <Contact>(); newContactList.Add(contextContactEntity); } myBroker.Contacts = newContactList; //Extract and add all the Brokers from the context List <Broker> newBrokerList = new List <Broker>(); foreach (Broker thisBroker in myBroker.Brokers) { var newBrokerEntity = ctx.Brokers.Include("Brokers").Where(s => s.BrokerID == thisBroker.BrokerID).FirstOrDefault <Broker>(); newBrokerList.Add(newBrokerEntity); //Create the reverse Broker<->Broker connection newBrokerEntity.Brokers.Add(myBroker); } myBroker.Brokers = newBrokerList; //Add this broker to the context ctx.Brokers.Add((Broker)myBroker); ctx.SaveChanges(); //We can get the generated id now myBroker.BrokerID. //Or we can pass myBroker back? return(myBroker); } else { var contextBrokerEntity = ctx.Brokers.Include("Address").Include("Contacts").Include("Brokers").Where(s => s.BrokerID == myBroker.BrokerID).FirstOrDefault <Broker>(); //We need to re-attach the Address, all the Contacts and all the Brokers //Everything else if at the entity level, and so does not need refound. //The address //Extract and attach the Address from the context if (myBroker.Address != null) { var contextAddressEntity = ctx.Addresses.Where(s => s.AddressID == myBroker.Address.AddressID).FirstOrDefault <Address>(); contextBrokerEntity.Address = contextAddressEntity; } //The contacts foreach (Contact thisContact in myBroker.Contacts) { var newContactEntity = ctx.Contacts.Where(s => s.ContactID == thisContact.ContactID).FirstOrDefault <Contact>(); if (!contextBrokerEntity.Contacts.Contains(newContactEntity)) { contextBrokerEntity.Contacts.Add(newContactEntity); } } //The brokers foreach (Broker thisBroker in myBroker.Brokers) { //As we don't (currently) allow the removal of brokers, we just need to handle the addition of new brokers //Get the context version of the current associated broker var newBrokerEntity = ctx.Brokers.Include("Brokers").Where(s => s.BrokerID == thisBroker.BrokerID).FirstOrDefault <Broker>(); //See if it is already attached to the context version of this broker if (!contextBrokerEntity.Brokers.Contains(newBrokerEntity)) { contextBrokerEntity.Brokers.Add(newBrokerEntity); } //See if the connection between brokers in the other direction is also present if (!newBrokerEntity.Brokers.Contains(contextBrokerEntity)) { newBrokerEntity.Brokers.Add(contextBrokerEntity); } } //Now to iterate through the JobLeadNotes and add in any new ones foreach (Note thisNote in myBroker.BrokerNotes) { //Get the context version of the current note var newNoteEntity = ctx.Notes.Where(s => s.NoteID == thisNote.NoteID).FirstOrDefault <Note>(); //See if it is already attached to the context version of this broker if (!contextBrokerEntity.BrokerNotes.Contains(newNoteEntity)) { contextBrokerEntity.BrokerNotes.Add(newNoteEntity); } } ctx.SaveChanges(); return(contextBrokerEntity); } } }
public void SaveJobLead(JobLead myJobLead) { //We will do this within a single Context using (var ctx = new JobLeadContext()) { //If we have a JobLeadID of 0 (zero), then this is a new job. if (myJobLead.JobLeadID == 0) { var contextJobLeadEntity = ctx.JobLeads.Include("AgencyBroker").Include("AgencyContact").Include("EmployerBroker").Include("EmployerBroker").Where(s => s.JobLeadID == myJobLead.JobLeadID).FirstOrDefault <JobLead>(); if (myJobLead.AgencyBrokerID != 0) { var newBrokerEntity = ctx.Brokers.Where(s => s.BrokerID == myJobLead.AgencyBrokerID).FirstOrDefault <Broker>(); myJobLead.AgencyBroker = newBrokerEntity; } if (myJobLead.EmployerBrokerID != 0) { var newBrokerEntity = ctx.Brokers.Where(s => s.BrokerID == myJobLead.EmployerBrokerID).FirstOrDefault <Broker>(); myJobLead.EmployerBroker = newBrokerEntity; } if (myJobLead.AgencyContactID != 0) { var newContactEntity = ctx.Contacts.Where(s => s.ContactID == myJobLead.AgencyContactID).FirstOrDefault <Contact>(); myJobLead.AgencyContact = newContactEntity; } if (myJobLead.EmployerContactID != 0) { var newContactEntity = ctx.Contacts.Where(s => s.ContactID == myJobLead.EmployerContactID).FirstOrDefault <Contact>(); myJobLead.EmployerContact = newContactEntity; } //I AM NOT SURE THIS WORKS PROPERLY YET //Now to iterate through the JobLeadNotes and add in any new ones List <Note> contextNotesList = new List <Note>(); foreach (Note thisNote in myJobLead.JobLeadNotes) { //Get the context version of the current note if (thisNote.NoteID != 0) { var newNoteEntity = ctx.Notes.Where(s => s.NoteID == thisNote.NoteID).FirstOrDefault <Note>(); contextNotesList.Add(newNoteEntity); } } if (myJobLead.JobLeadNotes.Count() != 0) { myJobLead.JobLeadNotes = contextNotesList; } //END OF CODE I AM UNSURE ABOUT //Add it to the context. ctx.JobLeads.Add((JobLead)myJobLead); //As this requires the form to know what the actual class is, we definitely need to move this out of the form. } else //Otherwise we update the existing one. { //First, get the whole job lead entity var contextJobLeadEntity = ctx.JobLeads.Include("AgencyBroker").Include("AgencyContact").Include("EmployerBroker").Include("EmployerBroker").Where(s => s.JobLeadID == myJobLead.JobLeadID).FirstOrDefault <JobLead>(); //Set all the JobLead entity level values. contextJobLeadEntity.Status = myJobLead.Status; contextJobLeadEntity.JobTitle = myJobLead.JobTitle; contextJobLeadEntity.Source = myJobLead.Source; contextJobLeadEntity.CVOrApplicationLocation = myJobLead.CVOrApplicationLocation; contextJobLeadEntity.CoverLetterLocation = myJobLead.CoverLetterLocation; contextJobLeadEntity.Ref_One = myJobLead.Ref_One; contextJobLeadEntity.Ref_Two = myJobLead.Ref_Two; contextJobLeadEntity.Ref_Three = myJobLead.Ref_Three; contextJobLeadEntity.JobLeadImage = myJobLead.JobLeadImage; //Now we attach the AgentBroker, AgentContact, EmployerBroker and EmployerContact sub entities if (myJobLead.AgencyBrokerID != 0) { var newBrokerEntity = ctx.Brokers.Where(s => s.BrokerID == myJobLead.AgencyBrokerID).FirstOrDefault <Broker>(); contextJobLeadEntity.AgencyBroker = newBrokerEntity; } if (myJobLead.EmployerBrokerID != 0) { var newBrokerEntity = ctx.Brokers.Where(s => s.BrokerID == myJobLead.EmployerBrokerID).FirstOrDefault <Broker>(); contextJobLeadEntity.EmployerBroker = newBrokerEntity; } if (myJobLead.AgencyContactID != 0) { var newContactEntity = ctx.Contacts.Where(s => s.ContactID == myJobLead.AgencyContactID).FirstOrDefault <Contact>(); contextJobLeadEntity.AgencyContact = newContactEntity; } if (myJobLead.EmployerContactID != 0) { var newContactEntity = ctx.Contacts.Where(s => s.ContactID == myJobLead.EmployerContactID).FirstOrDefault <Contact>(); contextJobLeadEntity.EmployerContact = newContactEntity; } //Now to iterate through the JobLeadNotes and add in any new ones foreach (Note thisNote in myJobLead.JobLeadNotes) { //Get the context version of the current note var newNoteEntity = ctx.Notes.Where(s => s.NoteID == thisNote.NoteID).FirstOrDefault <Note>(); //See if it is already attached to the context version of this job lead if (!contextJobLeadEntity.JobLeadNotes.Contains(newNoteEntity)) { contextJobLeadEntity.JobLeadNotes.Add(newNoteEntity); } } } //Finally, we save the changes to the changes made in the context. ctx.SaveChanges(); } }
private void btnDoSomething_Click(object sender, EventArgs e) { #region OldTestDataGeneration //using (var ctx = new JobLeadContext()) //{ // ///* // Name2 newName = new Name2(); // newName.FirstName = "James"; // newName.MiddleName = "Mark"; // newName.Surname = "McDonald"; // newName.Title = "Dr"; // //ctx.Names.Add(newName); // Address2 newAddress = new Address2(); // newAddress.BodyText = "Suite 5,\n2 Constitution Street,\nLeith"; // newAddress.City = "Edinburgh"; // newAddress.Region = "East Lothian"; // newAddress.Country = "Scotland"; // newAddress.Postcode = "EH6 6JA"; // //ctx.Addresses.Add(newAddress); // Contact2 newContact = new Contact2(); // newContact.Address = newAddress; // newContact.Name = newName; // newContact.Email = "*****@*****.**"; // newContact.Position = "Worker"; // newContact.LandLineTelNo = "0131 444 7642"; // newContact.MobileTelNo = "0773355667"; // Broker2 newBroker = new Broker2(); // //newBroker.myContact = newContact; // newBroker.Contacts.Add(newContact); // newBroker.Name = "New Broker Name"; // Address2 newAddress2 = new Address2(); // newAddress2.BodyText = "4 Kittle Yards,\n2 Causewayside,\nNewington"; // newAddress2.City = "Edinburgh"; // newAddress2.Region = "East Lothian"; // newAddress2.Country = "Scotland"; // newAddress2.Postcode = "EH9 1PJ"; // newBroker.Address = newAddress2; // newBroker.LandLineTelNo = "0131 668 8010"; // newBroker.Website = "WWW.NewBroker.CO.UK"; // newBroker.IsAgency = true; // //Test adding a broker to a broker. // Broker2 newBroker2 = new Broker2(); // newBroker2.Name = "Broker's Broker1"; // newBroker.Brokers.Add(newBroker2); // Broker2 newBroker3 = new Broker2(); // newBroker3.Name = "Broker's Broker2"; // newBroker.Brokers.Add(newBroker3); // JobLead2 newJobLead = new JobLead2(); // newJobLead.AgencyBroker = newBroker; // newJobLead.AgencyContact = newContact; // newJobLead.CoverLetterLocation = @"C:\CoverLetterDir\CoverLetter.doc"; // newJobLead.CVOrApplicationLocation = @"C:\CVLocationDir\cv.doc"; // newJobLead.Date = DateTime.Now; // newJobLead.Ref_One = "WID001/0034"; // newJobLead.Ref_Two = "AgID-23-12345/002"; // newJobLead.Source = @"http://www.bbc.co.uk/news"; // newJobLead.Status = newJobLead.StatusList[2]; // Broker2 newEmployerBroker = new Broker2(); // newEmployerBroker.Name = "Employer Broker"; // newEmployerBroker.Address = newAddress; // newEmployerBroker.IsAgency = false; // newJobLead.EmployerBroker = newEmployerBroker; // Name2 newName2 = new Name2(); // newName2.FirstName = "Edward"; // newName2.MiddleName = "Paul"; // newName2.Surname = "Innes"; // newName2.Title = "Mr"; // Contact2 newContact2 = new Contact2(); // newContact2.Address = newAddress2; // newContact2.Name = newName2; // newContact2.Email = "*****@*****.**"; // newContact2.Position = "Advisor"; // newContact2.LandLineTelNo = "0131 222 6238"; // newContact2.MobileTelNo = "07766114488"; // newJobLead.EmployerContact = newContact2; // //ctx.Names.Add(newName); // //ctx.Addresses.Add(newAddress); // //ctx.Contacts.Add(newContact); // //ctx.Brokers.Add(newBroker); // ctx.JobLeads.Add(newJobLead); // ctx.SaveChanges(); // //*/ //} #endregion #region NewTestDataGeneration //12 Names Name name_01 = new Name("Mr", "Andrew", "John", "McDonald"); Name name_02 = new Name("Professor", "William", "Henry", "Maitland"); Name name_03 = new Name("Miss", "Fiona", "Shirley", "Edwards"); Name name_04 = new Name("Mr", "Brian", "Ian", "Jones"); Name name_05 = new Name("Dr", "Mary", "Edith", "Fforbes"); Name name_06 = new Name("Miss", "July", "Margret", "Denby"); Name name_07 = new Name("Mr", "Oliver", "Peter", "Henrikson"); Name name_08 = new Name("Ms", "Audrey", "Louise", "Monks"); Name name_09 = new Name("Mr", "Malcolm", "Frank", "Noble"); Name name_10 = new Name("Miss", "Edith", "Veronica", "Simons"); Name name_11 = new Name("Dr", "James", "Scott"); Name name_12 = new Name("Professor", "Kate", "Leslie", "Brown"); //8 Addresses Address address_01 = new Address("38/2 Prince Regent Street,\nLeith", "Edinburgh", "Lothian", "UK", "EH6 4AT"); Address address_02 = new Address("Suite 5,\n2Commercial Street,\nLeith", "Edinburgh", "Lothan", "Scotland", "EH6 6JA"); Address address_03 = new Address("4 Kittle Yards,\nCausewayside,\nNewington", "Edinburgh", "Lothian", "Britain", "EH9 1PJ"); Address address_04 = new Address("23/23a Dalmeny Street", "Edinburgh", "East Lothian", "UK", "EH6 8PJ"); Address address_05 = new Address("113 West Regent Street", "Glasgow", "Strathclyde", "Scotland", "G2 2RU"); Address address_06 = new Address("7 Castle Street", "Edinburgh", "Lothian", "UK", "EH2 3AP"); Address address_07 = new Address("9 Colme Street", "Edinburgh", "West Lothian", "Britain", "EH3 6AA"); Address address_08 = new Address("17A South Gyle Crescent", "Edinburgh", "Scotland", "Mid Lothian", "EH12 9FL"); //12 Contacts Contact contact_01 = new Contact(name_01, address_01, "Associate", "*****@*****.**", "077739614", "0131 652 7359"); Contact contact_02 = new Contact(name_02, address_02, "Department Head", "[email protected],uk", "", "0131 391 2519"); Contact contact_03 = new Contact(name_03, address_03, "Recruiter", "*****@*****.**", "077183962", "0131 724 2975"); Contact contact_04 = new Contact(name_04, address_04, "Manager", "*****@*****.**", "077163615", "0131 272 4725"); Contact contact_05 = new Contact(name_05, address_05, "Development Director", "*****@*****.**", "077253951", "0141 263 2748"); Contact contact_06 = new Contact(name_06, address_06, "HR Director", "*****@*****.**", "077451835", "0131 263 1462"); Contact contact_07 = new Contact(name_07, address_07, "Placement Officer", "*****@*****.**", "", ""); Contact contact_08 = new Contact(name_08, address_08, "Consultant", "*****@*****.**", "077253194", ""); Contact contact_09 = new Contact(name_09, address_04, "Lead Recruiter", "*****@*****.**", "077451736", "0131 272 4720"); Contact contact_10 = new Contact(name_10, address_07); Contact contact_11 = new Contact(name_11, address_04, ".NET Recruiter", "*****@*****.**", "077369643", "0131 272 4722"); Contact contact_12 = new Contact(name_12, address_05, "Team Leader", "*****@*****.**", "077254951", "0141 263 2724"); //2 Employer Brokers Broker employerBroker_01 = new Broker(); employerBroker_01.IsAgency = false; employerBroker_01.Name = "Bleeding Edge Development."; employerBroker_01.Address = address_02; employerBroker_01.LandLineTelNo = "0131 391 2500"; employerBroker_01.Website = @"www.NewOps.co.uk"; employerBroker_01.Contacts.Add(contact_02); Broker employerBroker_02 = new Broker(); employerBroker_02.IsAgency = false; employerBroker_02.Name = "Blue Sky Solutions."; employerBroker_02.Address = address_05; employerBroker_02.LandLineTelNo = "0141 263 2700"; employerBroker_02.Website = @"www.BlueSkySolutions.com"; employerBroker_02.Contacts.Add(contact_05); employerBroker_02.Contacts.Add(contact_12); //4 Agency Brokers Broker agencyBroker_01 = new Broker(); agencyBroker_01.IsAgency = true; agencyBroker_01.Name = "New Doors."; agencyBroker_01.Address = address_01; agencyBroker_01.LandLineTelNo = "0131 652 7300"; agencyBroker_01.Website = @"www.NewDoorsLtd.co.uk"; agencyBroker_01.Contacts.Add(contact_01); Broker agencyBroker_02 = new Broker(); agencyBroker_02.IsAgency = true; agencyBroker_02.Name = "First Chance."; agencyBroker_02.Address = address_03; agencyBroker_02.LandLineTelNo = "0131 724 2900"; agencyBroker_02.Website = @"www.FirstChance.co.uk"; agencyBroker_02.Contacts.Add(contact_03); Broker agencyBroker_03 = new Broker(); agencyBroker_03.IsAgency = true; agencyBroker_03.Name = "Finnly & Associates."; agencyBroker_03.Address = address_04; agencyBroker_03.LandLineTelNo = "0131 272 4700"; agencyBroker_03.Website = @"www.FinnlyAndAssociates.com"; agencyBroker_03.Contacts.Add(contact_04); agencyBroker_03.Contacts.Add(contact_09); agencyBroker_03.Contacts.Add(contact_11); Broker agencyBroker_04 = new Broker(); agencyBroker_04.IsAgency = true; agencyBroker_04.Name = "IT Solutions Limited."; agencyBroker_04.Address = address_06; agencyBroker_04.LandLineTelNo = "0131 263 1462"; agencyBroker_04.Website = @"www.ITSolutionsLtd.co.uk"; agencyBroker_04.Contacts.Add(contact_06); //As we are connecting brokers to brokers, we could not join them until after they have all been created. employerBroker_01.Brokers.Add(agencyBroker_01); employerBroker_01.Brokers.Add(agencyBroker_03); employerBroker_02.Brokers.Add(agencyBroker_02); employerBroker_02.Brokers.Add(agencyBroker_03); employerBroker_02.Brokers.Add(agencyBroker_04); agencyBroker_01.Brokers.Add(employerBroker_01); agencyBroker_02.Brokers.Add(employerBroker_02); agencyBroker_03.Brokers.Add(employerBroker_01); agencyBroker_03.Brokers.Add(employerBroker_02); agencyBroker_04.Brokers.Add(employerBroker_02); //2 Job Leads JobLead jobLead_01 = new JobLead(); jobLead_01.JobTitle = ".NET Software Engineer"; jobLead_01.AgencyBroker = agencyBroker_01; jobLead_01.AgencyContact = contact_01; jobLead_01.EmployerBroker = employerBroker_01; jobLead_01.EmployerContact = contact_02; jobLead_01.CoverLetterLocation = @"C:\Jobs\Applications\JobLeadOneCover.doc"; jobLead_01.CVOrApplicationLocation = @"C:\Jobs\CV\CV.Doc"; jobLead_01.Ref_One = @"Job01\0023"; jobLead_01.Ref_Two = @"ABC-xyz-123"; jobLead_01.Ref_Three = @"JobOne Ref 3"; jobLead_01.Source = @"www.JobsNow.co.uk\002345\abc.aspx"; jobLead_01.Status = jobLead_01.StatusList[2]; JobLead jobLead_02 = new JobLead(); jobLead_02.JobTitle = "C# Developer"; jobLead_02.AgencyBroker = agencyBroker_03; jobLead_02.AgencyContact = contact_09; jobLead_02.EmployerBroker = employerBroker_02; jobLead_02.EmployerContact = contact_05; jobLead_02.CoverLetterLocation = @"C:\Jobs\Applications\JobLeadTwoCover.doc"; jobLead_02.CVOrApplicationLocation = @"C:\Jobs\Applications\JobLeadTwoApplication.doc"; jobLead_02.Ref_One = @"Job Two Ref One"; jobLead_02.Ref_Two = @"JKL\004\TRW\09-34"; jobLead_02.Ref_Three = @"Job34-0034"; jobLead_02.Source = @"www.jobFinder.com\flax0034\job23.aspx"; jobLead_02.Status = jobLead_01.StatusList[4]; using (var ctx = new JobLeadContext()) { ctx.JobLeads.Add(jobLead_01); ctx.JobLeads.Add(jobLead_02); ctx.SaveChanges(); } /* * JobLead currentJobLead; * * using (var ctx = new JobLeadContext()) * { * currentJobLead = ctx.JobLeads.Include("AgencyContact").Where(s => s.JobLeadID == 1).FirstOrDefault<JobLead>(); * } * * if (currentJobLead != null) * { * currentJobLead.JobTitle = "Changed Title"; * currentJobLead.AgencyContact = contact_11; * } * * using (var ctx = new JobLeadContext()) * { * ctx.Entry(currentJobLead).State = System.Data.Entity.EntityState.Modified; * * ctx.SaveChanges(); * } */ #endregion }