Setting a contact Represents field
Moderator: Phil Barton
-
- Posts: 22
- Joined: Tue Dec 11, 2018 10:03 am
Setting a contact Represents field
Hello
I set the contact represents field to order.Buyers or order.Sellers without issue. But I run in the following error when I try to set it as order.AllBuyers.
{"Cannot implicitly convert type 'AllBuyers' to 'System.Collections.IEnumerable'. An explicit conversion exists (are you missing a cast?)"}
Any help would be great.
I set the contact represents field to order.Buyers or order.Sellers without issue. But I run in the following error when I try to set it as order.AllBuyers.
{"Cannot implicitly convert type 'AllBuyers' to 'System.Collections.IEnumerable'. An explicit conversion exists (are you missing a cast?)"}
Any help would be great.
-
- Posts: 1382
- Joined: Wed Jan 15, 2014 3:50 pm
- Location: Raleigh, NC
- Contact:
Re: Setting a contact Represents field
Please show your code for this issue. It seems that "order.AllBuyers" should work.
Bob Richards, Senior Software Developer, SoftPro
-
- Posts: 22
- Joined: Tue Dec 11, 2018 10:03 am
Re: Setting a contact Represents field
Lets start here
Code: Select all
dynamic dAttorney = TranslateAttorney(party, tState);
Action<dynamic> setClients = clients =>
{
foreach (dynamic client in clients) { dAttorney.Represents = client; }
};
if (party.Type == Constants.PartyTypes.BUYERS_ATTORNEY)
setClients(tState.SelectOrder.AllBuyers);
Code: Select all
protected virtual dynamic TranslateAttorney(Local.IContact lender, TranslateState tState)
{
try
{
dynamic dAttorney = TranslateContact(lender, tState, Constants.ObjectTypes.ATTORNEY);
return dAttorney;
}
catch (Exception ex)
{
Logging.WriteLog("TranslateAttorney", ex);
throw ex;
}
}
Code: Select all
protected virtual dynamic TranslateContact(Local.IContact contact, TranslateState tState, string contactType)
{
try
{
dynamic dContact = null;
if (contact == null) return dContact;
dContact = CreateNewObject(contactType, tState);
tState.SelectOrder.Contacts.Add(dContact);
dContact.Name = Truncate(contact.Company, 150);
dContact.Email = contact.EMail;
TranslateAddress(contact.Address, dContact.Address, tState);
TranslatePhones(contact, dContact, tState);
if (contact.Name == null || string.IsNullOrEmpty(contact.Name.First) && contactType != Constants.ObjectTypes.ATTORNEY) return dContact;
dynamic person = CreateNewObject(Constants.ObjectTypes.PERSON, tState);
dContact.People.Add(person);
TranslateIndividual(contact, person, tState);
TranslateAddress(contact.Address, dContact.Address, tState);
return dContact;
}
catch (Exception ex)
{
Logging.WriteLog("TranslateContact", ex);
throw;
}
}
-
- Posts: 1382
- Joined: Wed Jan 15, 2014 3:50 pm
- Location: Raleigh, NC
- Contact:
Re: Setting a contact Represents field
Your code fails because "AllBuyers" is an instance of a "Contact". Since it is not a collection, it cannot be used in this context. This is why the compiler error was "Cannot implicitly convert type 'AllBuyers' to 'System.Collections.IEnumerable".
The collection of all of the order buyers (implements IEnumerable) is order.Buyers.
Code: Select all
// ***** FAILS *****
foreach (dynamic client in tState.SelectOrder.AllBuyers)
{
...
}
Code: Select all
// ***** WORKS *****
foreach (dynamic client in tState.SelectOrder.Buyers)
{
...
}
Bob Richards, Senior Software Developer, SoftPro
-
- Posts: 22
- Joined: Tue Dec 11, 2018 10:03 am
Re: Setting a contact Represents field
But my tState.SelectOrder.AllBuyers is an instance of the AllBuyers at the top level of the select Order.
SO how do I change the Represents to "All Buyers"
SO how do I change the Represents to "All Buyers"
-
- Posts: 1382
- Joined: Wed Jan 15, 2014 3:50 pm
- Location: Raleigh, NC
- Contact:
Re: Setting a contact Represents field
I agree that the "Represents" property can be set to "AllBuyers" since it is a Contact type.
But your compiler error is with the "foreach" loop and has nothing to do with setting the property (look at the stack trace to get the line number for the actual error). Ignore the content in the body of the loop.
Your code sets "clients" to "AllBuyers". The "foreach" keyword requires "clients" to be a collection (something it can iterate). A Contact is not a collection. Examples of a Contact are order.Buyers[0] or order.Abstractors[2]. Examples of a collections are order.Buyers or order.Abstractors.
Code: Select all
dAttorney.Represents = order.AllBuyers;
Code: Select all
foreach (dynamic client in clients)
Bob Richards, Senior Software Developer, SoftPro
-
- Posts: 22
- Joined: Tue Dec 11, 2018 10:03 am
Re: Setting a contact Represents field
Right, my bad. thanks.