Is there a way to create a file using the .NET toolkit ?
I can't find it when configuring my data services in visual studio 2015.
I found Attachment and Document but I heard Attachment will be deprecated soon and Document can't be directly linked to an opportunity.
Below is the code I use today :
public bool AttachProjectDocuments(string siren, string description, IEnumerable<DocumentWithDataDto> projectDocuments)
{
var account = Query<Account>("SELECT ID FROM Account WHERE SIREN__c = " + siren);
if (account != null && account.Records.Any())
{
var opportunity = Query<Opportunity>("SELECT ID, Name, CreatedDate, eligibility_rating__c, loan_duration_request__c, loan_reason__c, Loan_amount_request__c FROM Opportunity WHERE AccountId = '" + account.Records[0].Id + "'");
if (opportunity != null && opportunity.Records.Any())
{
var lastOpportunity = opportunity.Records.OrderByDescending(x => x.CreatedDate).First();
Update("Opportunity", lastOpportunity.Id,
new Opportunity
{
Id = lastOpportunity.Id,
AccountId = account.Records[0].Id,
Loan_amount_request__c = lastOpportunity.Loan_amount_request__c,
loan_duration_request__c = lastOpportunity.loan_duration_request__c,
loan_reason__c = lastOpportunity.loan_reason__c,
eligibility_rating__c = lastOpportunity.eligibility_rating__c,
LeadSource = lastOpportunity.LeadSource,
Loan_request_details__c = description,
CloseDate = DateTime.UtcNow,
Request_submission__c = DateTime.UtcNow,
StageName = "Needs Analysis",
Name = lastOpportunity.Name,
Year_N_accounts__c = true,
Year_N_1_accounts__c = true,
Year_N_2_accounts__c = true
});
foreach (var doc in projectDocuments)
{
var attachment = new Attachment
{
ParentId = lastOpportunity.Id,
BodyLength = doc.Data.Length,
Name = doc.Name,
ContentType = doc.MimeType,
Body = doc.Data
};
Create("Attachment", attachment);
}
return true;
}
}
return false;
}