public bool CreateContactFromRegistration(Contact contact) { //contact does not exist - create in CRM and in Portal //contact exists in both CRM and in the Portal - return contact already exists try { //before creating check if the contact already exists in CRM using the email as a key //if the contact does exist, return false otherwise, continue to create contact var contactObj = new Entity("contact"); contactObj["firstname"] = contact.FirstName; contactObj["lastname"] = contact.LastName; contactObj["address1_city"] = contact.Address1_City; contactObj["emailaddress1"] = contact.EmailAddress1; _service.Create(contactObj); return true; } catch { return false; } }
public void CreateAccountAndContactFromFirstLogin(Contact contact, Account account) { var contactObj = new Entity("contact"); contactObj["firstname"] = contact.FirstName; contactObj["lastname"] = contact.LastName; contactObj["address1_city"] = contact.Address1_City; //_contactId = _service.Create(contactObj); contactObj.Id = Guid.NewGuid(); contactObj.Id = _contactId; _orgContext.AddObject(contactObj); var accountObj = new Entity("account"); accountObj["name"] = account.Name; accountObj["address1_city"] = account.Address1_City; accountObj.Id = account.Id; _orgContext.AddRelatedObject( contactObj, new Relationship("account_primary_contact"), accountObj); SaveChangesHelper(contactObj, accountObj); }
public async Task<IHttpActionResult> Register(RegisterBindingModel model) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var user = new ApplicationUser() { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName }; IdentityResult result = await UserManager.CreateAsync(user, model.Password); if (!result.Succeeded) { return GetErrorResult(result); } var contact = new Contact() { EmailAddress1 = model.Email, FirstName = user.FirstName, LastName = user.LastName, Address1_Line1 = "23 Market St.", Address1_City = "Sammamish", Address1_StateOrProvince = "MT", Address1_PostalCode = "99999", Telephone1 = "12345678", Id = Guid.NewGuid() }; //_crmContext.CreateAccountAndContactFromFirstLogin(contact, account); if (!_crmContext.CreateContactFromRegistration(contact)) { return InternalServerError(); } return Ok(); }