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)); } }