public virtual IEnumerable <IAnnotation> SelectNotes() { var serviceContext = Dependencies.GetServiceContext(); IAnnotationDataAdapter annotationDataAdapter = new AnnotationDataAdapter(Dependencies); return(serviceContext.CreateQuery("annotation") .Where(e => e.GetAttributeValue <EntityReference>("objectid") == Incident && e.GetAttributeValue <string>("objecttypecode") == Incident.LogicalName && e.GetAttributeValue <string>("notetext").Contains(AnnotationHelper.WebAnnotationPrefix)) .ToArray() .Select(entity => annotationDataAdapter.GetAnnotation(entity)) .OrderBy(e => e.CreatedOn) .ToArray()); }
protected void Speakers_OnItemDataBound(object sender, ListViewItemEventArgs e) { var dataItem = e.Item as ListViewDataItem; if (dataItem == null || dataItem.DataItem == null) { return; } var speaker = dataItem.DataItem as Entity; if (speaker == null) { return; } var repeaterControl = (Repeater)e.Item.FindControl("SpeakerAnnotations"); if (repeaterControl == null) { return; } var dataAdapterDependencies = new PortalConfigurationDataAdapterDependencies(requestContext: Request.RequestContext, portalName: PortalName); var dataAdapter = new AnnotationDataAdapter(dataAdapterDependencies); var annotations = XrmContext.CreateQuery("annotation") .Where(a => a.GetAttributeValue <EntityReference>("objectid") == speaker.ToEntityReference() && a.GetAttributeValue <bool?>("isdocument").GetValueOrDefault(false)) .OrderBy(a => a.GetAttributeValue <DateTime>("createdon")) .Select(entity => dataAdapter.GetAnnotation(entity)); repeaterControl.DataSource = annotations; repeaterControl.DataBind(); }
public ActionResult DeleteNote(string id) { Guid annotationId; Guid.TryParse(id, out annotationId); string portalName = null; var portalContext = PortalCrmConfigurationManager.CreatePortalContext(); var languageCodeSetting = portalContext.ServiceContext.GetSiteSettingValueByName(portalContext.Website, "Language Code"); if (!string.IsNullOrWhiteSpace(languageCodeSetting)) { int languageCode; if (int.TryParse(languageCodeSetting, out languageCode)) { portalName = languageCode.ToString(CultureInfo.InvariantCulture); } } var dataAdapterDependencies = new PortalConfigurationDataAdapterDependencies(requestContext: Request.RequestContext, portalName: portalName); var dataAdapter = new AnnotationDataAdapter(dataAdapterDependencies); var annotation = dataAdapter.GetAnnotation(annotationId); var result = dataAdapter.DeleteAnnotation(annotation, new AnnotationSettings(dataAdapterDependencies.GetServiceContext(), true)); if (!result.PermissionsExist) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, ResourceManager.GetString("Entity_Permissions_Have_Not_Been_Defined_Message"))); } if (!result.PermissionGranted) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, string.Format(ResourceManager.GetString("No_Entity_Permissions"), "delete this record"))); } return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
public ActionResult DeleteNote(string id) { Guid annotationId; Guid.TryParse(id, out annotationId); string portalName = null; var portalContext = PortalCrmConfigurationManager.CreatePortalContext(); var languageCodeSetting = portalContext.ServiceContext.GetSiteSettingValueByName(portalContext.Website, "Language Code"); if (!string.IsNullOrWhiteSpace(languageCodeSetting)) { int languageCode; if (int.TryParse(languageCodeSetting, out languageCode)) { portalName = languageCode.ToString(CultureInfo.InvariantCulture); } } var dataAdapterDependencies = new PortalConfigurationDataAdapterDependencies(requestContext: Request.RequestContext, portalName: portalName); var dataAdapter = new AnnotationDataAdapter(dataAdapterDependencies); var annotation = dataAdapter.GetAnnotation(annotationId); var result = dataAdapter.DeleteAnnotation(annotation, new AnnotationSettings(dataAdapterDependencies.GetServiceContext(), true)); if (!result.PermissionsExist) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, "Entity Permissions have not been defined. Your request could not be completed.")); } if (!result.CanDelete) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, "Permission Denied. You do not have the appropriate Entity Permissions to delete this record.")); } return(new HttpStatusCodeResult(HttpStatusCode.NoContent)); }
public ActionResult UpdateNote(string id, string text, string subject, bool isPrivate = false, HttpPostedFileBase file = null, string attachmentSettings = null) { if (string.IsNullOrWhiteSpace(text) || string.IsNullOrWhiteSpace(StringHelper.StripHtml(text))) { return(new HttpStatusCodeResult(HttpStatusCode.ExpectationFailed, ResourceManager.GetString("Required_Field_Error").FormatWith(ResourceManager.GetString("Note_DefaultText")))); } Guid annotationId; Guid.TryParse(id, out annotationId); string portalName = null; var portalContext = PortalCrmConfigurationManager.CreatePortalContext(); var languageCodeSetting = portalContext.ServiceContext.GetSiteSettingValueByName(portalContext.Website, "Language Code"); if (!string.IsNullOrWhiteSpace(languageCodeSetting)) { int languageCode; if (int.TryParse(languageCodeSetting, out languageCode)) { portalName = languageCode.ToString(CultureInfo.InvariantCulture); } } var dataAdapterDependencies = new PortalConfigurationDataAdapterDependencies(requestContext: Request.RequestContext, portalName: portalName); var dataAdapter = new AnnotationDataAdapter(dataAdapterDependencies); var settings = GetAnnotationSettings(dataAdapterDependencies.GetServiceContext(), attachmentSettings); var annotation = dataAdapter.GetAnnotation(annotationId); annotation.AnnotationId = annotationId; annotation.NoteText = string.Format("{0}{1}", AnnotationHelper.WebAnnotationPrefix, text); if (!isPrivate && !string.IsNullOrWhiteSpace(subject) && subject.Contains(AnnotationHelper.PrivateAnnotationPrefix)) { annotation.Subject = subject.Replace(AnnotationHelper.PrivateAnnotationPrefix, string.Empty); } if (isPrivate && !string.IsNullOrWhiteSpace(subject) && !subject.Contains(AnnotationHelper.PrivateAnnotationPrefix)) { annotation.Subject = subject + AnnotationHelper.PrivateAnnotationPrefix; } if (file != null && file.ContentLength > 0) { annotation.FileAttachment = AnnotationDataAdapter.CreateFileAttachment(file, settings.StorageLocation); } try { var result = dataAdapter.UpdateAnnotation(annotation, settings); if (!result.PermissionsExist) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, ResourceManager.GetString("Entity_Permissions_Have_Not_Been_Defined_Message"))); } if (!result.PermissionGranted) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, string.Format(ResourceManager.GetString("No_Entity_Permissions"), "update notes"))); } return(new HttpStatusCodeResult(HttpStatusCode.OK)); } catch (AnnotationException ex) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, ex.Message)); } }
public ActionResult UpdateNote(string id, string text, string subject, bool isPrivate = false, HttpPostedFileBase file = null, string attachmentSettings = null) { Guid annotationId; Guid.TryParse(id, out annotationId); string portalName = null; var portalContext = PortalCrmConfigurationManager.CreatePortalContext(); var languageCodeSetting = portalContext.ServiceContext.GetSiteSettingValueByName(portalContext.Website, "Language Code"); if (!string.IsNullOrWhiteSpace(languageCodeSetting)) { int languageCode; if (int.TryParse(languageCodeSetting, out languageCode)) { portalName = languageCode.ToString(CultureInfo.InvariantCulture); } } var dataAdapterDependencies = new PortalConfigurationDataAdapterDependencies(requestContext: Request.RequestContext, portalName: portalName); var dataAdapter = new AnnotationDataAdapter(dataAdapterDependencies); var settings = JsonConvert.DeserializeObject <AnnotationSettings>(attachmentSettings) ?? new AnnotationSettings(dataAdapterDependencies.GetServiceContext(), true); var annotation = dataAdapter.GetAnnotation(annotationId); annotation.AnnotationId = annotationId; annotation.NoteText = string.Format("{0}{1}", AnnotationHelper.WebAnnotationPrefix, text); if (!isPrivate && !string.IsNullOrWhiteSpace(subject) && subject.Contains(AnnotationHelper.PrivateAnnotationPrefix)) { annotation.Subject = subject.Replace(AnnotationHelper.PrivateAnnotationPrefix, string.Empty); } if (isPrivate && !string.IsNullOrWhiteSpace(subject) && !subject.Contains(AnnotationHelper.PrivateAnnotationPrefix)) { annotation.Subject = subject + AnnotationHelper.PrivateAnnotationPrefix; } if (file != null && file.ContentLength > 0) { annotation.FileAttachment = AnnotationDataAdapter.CreateFileAttachment(file, settings.StorageLocation); } try { var result = dataAdapter.UpdateAnnotation(annotation, settings); if (!result.PermissionsExist) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, "Entity Permissions have not been defined. Your request could not be completed.")); } if (!result.CanWrite) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, "Permission Denied. You do not have the appropriate Entity Permissions to update notes.")); } return(new HttpStatusCodeResult(HttpStatusCode.NoContent)); } catch (AnnotationException ex) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, ex.Message)); } }