public async Task AddContact(Ride item, Employee employee) { if (item == null) throw new ArgumentNullException("item"); if (employee == null) throw new ArgumentNullException("employee"); var client = await GetForceClient(); var resultQueryExist = await client .QueryAsync<Contact>(string.Format(@" SELECT Id, IsDeleted, FirstName, LastName, CreatedDate, LastModifiedDate, Email, AccountId From Contact Where Email='{0}'", employee.Email)); if (!resultQueryExist.records.Any()) { await client.CreateAsync("Contact", GetContact(employee)); Trace.TraceInformation("Contact created successfully"); } }
Contact GetContact(Employee employee) { var contact = new Contact(); string[] sName = employee.Name.Split(null); if (sName.Length > 1) { contact.FirstName = sName[0]; contact.LastName = sName[1]; } else { contact.FirstName = string.Empty; contact.LastName = sName[0]; } contact.Email = employee.Email; contact.AccountId = _accountId; // In this demo the accoundId is always the same return contact; }