protected void btnGo_Click(object sender, EventArgs e) { var country = _Countries[ddlCountry.SelectedValue]; var role = _Roles[ddlRole.SelectedValue]; var prospect = new Prospect { CompanyName = txtCompanyName.Text, EmailAddress = txtEmail.Text, FirstName = txtFirstName.Text, LastName = txtLastName.Text, Country = country, Role = role }; using (var context = new ProductLaunchContext()) { //reload child objects: prospect.Country = context.Countries.Single(x => x.CountryCode == prospect.Country.CountryCode); prospect.Role = context.Roles.Single(x => x.RoleCode == prospect.Role.RoleCode); context.Prospects.Add(prospect); context.SaveChanges(); } Server.Transfer("ThankYou.aspx"); }
public void Insert() { using (var context = new ProductLaunchContext()) { var country = new Country { CountryCode = "GBR", CountryName = "United Kingdom" }; context.Countries.Add(country); var role = new Role { RoleCode = "DM", RoleName = "Decision Maker" }; context.Roles.Add(role); var prospect = new Prospect { FirstName = "A", LastName = "Prospect", CompanyName = "Docker, Inc.", EmailAddress = "*****@*****.**", Country = country, Role = role }; context.Prospects.Add(prospect); context.SaveChanges(); } }
private static void SaveProspect(object sender, MsgHandlerEventArgs e) { Console.WriteLine($"Received message, subject: {e.Message.Subject}"); var eventMessage = MessageHelper.FromData <ProspectSignedUpEvent>(e.Message.Data); Console.WriteLine($"Saving new prospect, signed up at: {eventMessage.SignedUpAt}; event ID: {eventMessage.CorrelationId}"); var prospect = eventMessage.Prospect; using (var context = new ProductLaunchContext()) { //reload child objects: prospect.Country = context.Countries.Single(x => x.CountryCode == prospect.Country.CountryCode); prospect.Role = context.Roles.Single(x => x.RoleCode == prospect.Role.RoleCode); context.Prospects.Add(prospect); context.SaveChanges(); } Console.WriteLine($"Prospect saved. Prospect ID: {eventMessage.Prospect.ProspectId}; event ID: {eventMessage.CorrelationId}"); }
protected void btnGo_Click(object sender, EventArgs e) { var country = _Countries[ddlCountry.SelectedValue]; var role = _Roles[ddlRole.SelectedValue]; var prospect = new Prospect { CompanyName = txtCompanyName.Text, EmailAddress = txtEmail.Text, FirstName = txtFirstName.Text, LastName = txtLastName.Text, Country = country, Role = role }; //v1.0: using (var context = new ProductLaunchContext()) { //reload child objects: prospect.Country = context.Countries.Single(x => x.CountryCode == prospect.Country.CountryCode); prospect.Role = context.Roles.Single(x => x.RoleCode == prospect.Role.RoleCode); context.Prospects.Add(prospect); context.SaveChanges(); } //v1.3: /* * var eventMessage = new ProspectSignedUpEvent * { * Prospect = prospect, * SignedUpAt = DateTime.UtcNow * }; * * MessageQueue.Publish(eventMessage); */ Server.Transfer("ThankYou.aspx"); }