public override void UpdateUser(MembershipUser user)
        {
            Assert.ArgumentNotNull(user, "user");

            if (!this.Initialized)
            {
                throw new NotSupportedException(string.Format("Salesforce provider isn't initialized. Provider name: {0}", this.Name));
            }

            if (this.ReadOnly)
            {
                throw new NotSupportedException(string.Format("Couldn't update user as Salesforce provider is in Read-Only mode. Provider name: {0}", this.Name));
            }

            var salesforceContact = new SalesforceContact(this.FieldMapping, user);

            if (string.IsNullOrEmpty(salesforceContact.Email) && this.RequiresUniqueEmail)
            {
                var contacts = this.ContactsApi.FindByFieldValue(this.FieldMapping.Email, user.Email, ComparisonOperator.Contains, 0, 2);
                if (contacts.Count > 1)
                {
                    throw new NotSupportedException(string.Format("Couldn't update Salesforce user. Salesforce provider requires a unique email. User name: {0}", user.UserName));
                }
            }

            if (this.ContactsApi.Update(salesforceContact))
            {
                this.Cache.Users.RemoveByKey(user.ProviderUserKey as string);
                LogHelper.Info(string.Format("Salesforce user has been updated. User name: {0}", user.UserName), this);
            }
            else
            {
                LogHelper.Warn(string.Format("Could not update Salesforce user. User name: {0}", user.UserName), this);
            }
        }
        public void UpdateTest()
        {
            var newContactProperties = new Dictionary <string, object>
            {
                { "LastName", Environment.UserName + "_UpdateTest" },
                { "Email", Environment.UserName + "*****@*****.**" },
                { "SC_Password__c", "123" },
                { "SC_PasswordQuestion__c", "How are you?" },
                { "SC_PasswordAnswer__c", "Ok" },
                { "SC_IsApproved__c", true }
            };

            var createResult = this.ContactsApi.Create(newContactProperties);

            ISalesforceContact contact = new SalesforceContact(this.FieldMapping, new Dictionary <string, object>(0))
            {
                Id    = createResult.Id,
                Login = newContactProperties["LastName"] as string,
                Email = "*****@*****.**"
            };

            var result = this.ContactsApi.Update(contact);

            var updated = this.ContactsApi.Get(contact.Login);

            Assert.IsTrue(result);
            Assert.IsTrue(updated.Email == contact.Email);

            Assert.IsTrue(this.ContactsApi.Delete(contact.Login));
        }
        public async Task <ActionResult> Edit(SalesforceContact contact)
        {
            if (ModelState.IsValid)
            {
                var salesforceService = new SalesforceService((ClaimsPrincipal)User, SignInManager);
                await salesforceService.UpdateContactAsync(contact);

                return(RedirectToAction("Index"));
            }

            return(View(contact));
        }
Example #4
0
        /// <summary>
        /// Demonstrates updating a contact Contact in a client's Salesforce instance
        /// </summary>
        public async Task UpdateContactAsync(SalesforceContact contact)
        {
            var updatedContact = new
            {
                FirstName = contact.FirstName,
                LastName  = contact.LastName,
                Email     = contact.Email,
                Phone     = contact.Phone,
            };

            await GetClientWithRefresh(async client =>
            {
                var success = await client.UpdateAsync("Contact", contact.Id, updatedContact);

                if (!success.Success)
                {
                    throw new HttpException((int)HttpStatusCode.InternalServerError, "Update Failed!");
                }
            });
        }
        public void FixAllContactsLoginNames()
        {
            var clientContacts = this.ContactsApi.GetAll(0, int.MaxValue);

            foreach (ISalesforceContact contact in clientContacts)
            {
                if (string.IsNullOrEmpty(contact.Login))
                {
                    ISalesforceContact updateContact = new SalesforceContact(this.FieldMapping)
                    {
                        Id    = contact.Id,
                        Login = string.IsNullOrEmpty(contact.Email) ? contact.GetProperty <string>("Name") : contact.Email
                    };

                    updateContact.SetProperty("SC_Password__c", "123".GetSHA1Hash());

                    var result = this.ContactsApi.Update(updateContact);
                    Assert.IsTrue(result);
                }
            }
        }
 public ActionResult Get(SalesforceContact contact)
 {
     return(View("Edit", contact));
 }
        public override void UpdateUser(MembershipUser user)
        {
            Assert.ArgumentNotNull(user, "user");

              if (!this.Initialized)
              {
            throw new NotSupportedException(string.Format("Salesforce provider isn't initialized. Provider name: {0}", this.Name));
              }

              if (this.ReadOnly)
              {
            throw new NotSupportedException(string.Format("Couldn't update user as Salesforce provider is in Read-Only mode. Provider name: {0}", this.Name));
              }

              var salesforceContact = new SalesforceContact(this.FieldMapping, user);

              if (string.IsNullOrEmpty(salesforceContact.Email) && this.RequiresUniqueEmail)
              {
            var contacts = this.ContactsApi.FindByFieldValue(this.FieldMapping.Email, user.Email, ComparisonOperator.Contains, 0, 2);
            if (contacts.Count > 1)
            {
              throw new NotSupportedException(string.Format("Couldn't update Salesforce user. Salesforce provider requires a unique email. User name: {0}", user.UserName));
            }
              }

              if (this.ContactsApi.Update(salesforceContact))
              {
            this.Cache.Users.RemoveByKey(user.ProviderUserKey as string);
            LogHelper.Info(string.Format("Salesforce user has been updated. User name: {0}", user.UserName), this);
              }
              else
              {
            LogHelper.Warn(string.Format("Could not update Salesforce user. User name: {0}", user.UserName), this);
              }
        }
        public void UpdateTest()
        {
            var newContactProperties = new Dictionary<string, object>
            {
              { "LastName", Environment.UserName + "_UpdateTest" },
              { "Email", Environment.UserName + "*****@*****.**" },
              { "SC_Password__c", "123" },
              { "SC_PasswordQuestion__c", "How are you?" },
              { "SC_PasswordAnswer__c", "Ok" },
              { "SC_IsApproved__c", true }
            };

              var createResult = this.ContactsApi.Create(newContactProperties);

              ISalesforceContact contact = new SalesforceContact(this.FieldMapping, new Dictionary<string, object>(0))
              {
            Id = createResult.Id,
            Login = newContactProperties["LastName"] as string,
            Email = "*****@*****.**"
              };

              var result = this.ContactsApi.Update(contact);

              var updated = this.ContactsApi.Get(contact.Login);

              Assert.IsTrue(result);
              Assert.IsTrue(updated.Email == contact.Email);

              Assert.IsTrue(this.ContactsApi.Delete(contact.Login));
        }
        public void FixAllContactsLoginNames()
        {
            var clientContacts = this.ContactsApi.GetAll(0, int.MaxValue);

              foreach (ISalesforceContact contact in clientContacts)
              {
            if (string.IsNullOrEmpty(contact.Login))
            {
              ISalesforceContact updateContact = new SalesforceContact(this.FieldMapping)
              {
            Id = contact.Id,
            Login = string.IsNullOrEmpty(contact.Email) ? contact.GetProperty<string>("Name") : contact.Email
              };

              updateContact.SetProperty("SC_Password__c", "123".GetSHA1Hash());

              var result = this.ContactsApi.Update(updateContact);
              Assert.IsTrue(result);
            }
              }
        }