/// <summary> /// Add a note to an entity. /// </summary> /// <param name="context">The service context</param> /// <param name="entity">The entity to which a note will be attached.</param> /// <param name="noteTitle"></param> /// <param name="noteText">The text of the note.</param> /// <param name="file">The file to attach with this note.</param> /// <returns>True if successful; otherwise, false.</returns> /// <remarks> /// <para>The provided <paramref name="entity"/> must already be persisted to the CRM for this operation to succeed.</para> /// <para>It it not necessary to SaveChanges after this operation--this operation fully persists this note to CRM.</para> /// </remarks> public static bool AddNoteAndSave(this OrganizationServiceContext context, Entity entity, string noteTitle, string noteText, HttpPostedFile file) { if (context == null) { throw new ArgumentNullException("context"); } if (file == null || file.ContentLength <= 0) { return(context.AddNoteAndSave(entity, noteTitle, noteText, null, null, null)); } var fileContent = new byte[file.ContentLength]; file.InputStream.Read(fileContent, 0, fileContent.Length); return(context.AddNoteAndSave(entity, noteTitle, noteText, file.FileName, file.ContentType, fileContent)); }
/// <summary> /// Add a Note to an entity. /// </summary> /// <param name="context">The service context</param> /// <param name="entity">The entity to which a note will be attached.</param> /// <param name="noteTitle"></param> /// <param name="noteText">The text of the note.</param> /// <returns>True if successful; otherwise, false.</returns> /// <remarks> /// <para>The provided <paramref name="entity"/> must already be persisted to the CRM for this operation to succeed.</para> /// <para>It it not necessary to SaveChanges after this operation--this operation fully persists this note to CRM.</para> /// </remarks> public static bool AddNoteAndSave(this OrganizationServiceContext context, Entity entity, string noteTitle, string noteText) { if (context == null) { throw new ArgumentNullException("context"); } return(context.AddNoteAndSave(entity, noteTitle, noteText, null, null, null)); }
public void AttachFile(OrganizationServiceContext context, Entity entity, HttpPostedFile postedFile) { context.ThrowOnNull("context"); entity.ThrowOnNull("entity"); postedFile.ThrowOnNull("postedFile"); var securityProvider = PortalCrmConfigurationManager.CreateCrmEntitySecurityProvider(PortalName); securityProvider.Assert(context, entity, CrmEntityRight.Change); if (!context.AddNoteAndSave(entity, string.Empty, string.Empty, postedFile)) { throw new InvalidOperationException("Failed to attach file to entity {0}.".FormatWith(entity)); } }
public static void ReportPostAbuseAndSave(this OrganizationServiceContext context, Entity post, string text) { post.AssertEntityName("adx_communityforumpost"); context.AddNoteAndSave(post, string.Empty, text); }