Page 1 of 1
Setting a contact Represents field
Posted: Wed Jul 31, 2019 3:27 pm
by shawnregan
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.
Re: Setting a contact Represents field
Posted: Thu Aug 01, 2019 12:07 pm
by BobRichards
Please show your code for this issue. It seems that "order.AllBuyers" should work.
Re: Setting a contact Represents field
Posted: Thu Aug 01, 2019 12:47 pm
by shawnregan
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;
}
}
Re: Setting a contact Represents field
Posted: Thu Aug 01, 2019 3:24 pm
by BobRichards
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".
Code: Select all
// ***** FAILS *****
foreach (dynamic client in tState.SelectOrder.AllBuyers)
{
...
}
The collection of all of the order buyers (implements IEnumerable) is order.Buyers.
Code: Select all
// ***** WORKS *****
foreach (dynamic client in tState.SelectOrder.Buyers)
{
...
}
Re: Setting a contact Represents field
Posted: Fri Aug 02, 2019 9:46 am
by shawnregan
But my tState.SelectOrder.AllBuyers is an instance of the AllBuyers at the top level of the select Order.
- 2019-08-02_0645.png (6.38 KiB) Viewed 4732 times
SO how do I change the Represents to "All Buyers"
- 2019-08-02_0647.png (12.48 KiB) Viewed 4731 times
Re: Setting a contact Represents field
Posted: Fri Aug 02, 2019 10:58 am
by BobRichards
I agree that the "Represents" property can be set to "AllBuyers" since it is a Contact type.
Code: Select all
dAttorney.Represents = order.AllBuyers;
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.
Code: Select all
foreach (dynamic client in clients)
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.
Re: Setting a contact Represents field
Posted: Fri Aug 02, 2019 12:35 pm
by shawnregan
Right, my bad.
thanks.