Exemplo n.º 1
0
            public NoteRecord(Entity annotation, DataAdapterDependencies dataAdapterDependencies) : base(annotation)
            {
                if (annotation == null)
                {
                    throw new ArgumentNullException("annotation");
                }

                SetPropertyValues(annotation, dataAdapterDependencies);
            }
            public NoteRecord(IAnnotation annotation, DataAdapterDependencies dataAdapterDependencies, CrmEntityPermissionProvider provider, EntityMetadata entityMetadata = null, bool readGranted = false, int?crmLcid = null)
                : base(annotation.Entity, dataAdapterDependencies.GetServiceContext(), provider, entityMetadata, readGranted, annotation.Regarding, crmLcid: crmLcid)
            {
                if (annotation == null)
                {
                    throw new ArgumentNullException("annotation");
                }

                SetPropertyValues(annotation, dataAdapterDependencies);
            }
Exemplo n.º 3
0
            public NoteRecord(Entity annotation, DataAdapterDependencies dataAdapterDependencies, CrmEntityPermissionProvider provider)
                : base(annotation, dataAdapterDependencies.GetServiceContext(), provider)
            {
                if (annotation == null)
                {
                    throw new ArgumentNullException("annotation");
                }
                if (annotation.LogicalName != "annotation")
                {
                    throw new ArgumentException(@"Value must have logical name ""annotation"".", "annotation");
                }

                SetPropertyValues(annotation, dataAdapterDependencies);
            }
            protected void SetPropertyValues(IAnnotation annotation, DataAdapterDependencies dataAdapterDependencies)
            {
                CreatedOn        = annotation.CreatedOn;
                CreatedOnDisplay = CreatedOn.ToString(DateTimeClientFormat);
                var text = annotation.NoteText;

                Text            = AnnotationHelper.FormatNoteText(text).ToString();
                UnformattedText = text.Replace(AnnotationHelper.WebAnnotationPrefix, string.Empty);
                if (annotation.FileAttachment != null)
                {
                    AttachmentFileName    = annotation.FileAttachment.FileName;
                    HasAttachment         = annotation.FileAttachment != null;
                    AttachmentContentType = annotation.FileAttachment.MimeType;
                    AttachmentUrl         = HasAttachment
                                                ? annotation.Entity.GetFileAttachmentUrl(dataAdapterDependencies.GetWebsite())
                                                : string.Empty;
                    AttachmentSize        = annotation.FileAttachment.FileSize;
                    AttachmentSizeDisplay = AttachmentSize.ToString();
                    AttachmentIsImage     = HasAttachment &&
                                            (new List <string> {
                        "image/jpeg", "image/gif", "image/png"
                    }).Contains(AttachmentContentType);
                }
                var subject = annotation.Subject;

                Subject   = subject;
                IsPrivate = AnnotationHelper.GetNotePrivacy(annotation);
                var noteContact = AnnotationHelper.GetNoteContact(subject);
                var user        = dataAdapterDependencies.GetPortalUser();

                IsPostedByCurrentUser = noteContact != null && user != null && noteContact.Id == user.Id;
                PostedByName          = noteContact == null?AnnotationHelper.GetNoteCreatedByName(annotation) : noteContact.Name;

                if (CanWrite)
                {
                    CanWrite = IsPostedByCurrentUser;
                }
                if (CanDelete)
                {
                    CanDelete = IsPostedByCurrentUser;
                }
                DisplayToolbar = CanWrite || CanDelete;
            }
Exemplo n.º 5
0
            private void SetPropertyValues(IActivity activity, DataAdapterDependencies dataAdapterDependencies)
            {
                var attributes = activity.Entity.Attributes;

                IsCustomActivity = false;

                ViewFields = attributes.SelectMany(FlattenAllPartiesAttribute).ToDictionary(attribute => attribute.Key, attribute =>
                {
                    var optionSetValue = attribute.Value as OptionSetValue;

                    if (optionSetValue != null)
                    {
                        return(optionSetValue.Value);
                    }

                    if (attribute.Key == "activitytypecode" && !predefinedTemplates.Contains((string)attribute.Value))
                    {
                        IsCustomActivity = true;
                    }

                    if (attribute.Key == "description")
                    {
                        string formattedValue = FormatViewFieldsValue(attribute.Value);
                        if (!String.IsNullOrWhiteSpace(formattedValue))
                        {
                            return(formattedValue);
                        }
                    }
                    return(attribute.Value);
                });

                CreatedOn        = activity.Entity.GetAttributeValue <DateTime>("createdon");
                CreatedOnDisplay = CreatedOn.ToString(DateTimeClientFormat);

                var noteContact = activity.Entity.GetAttributeValue <EntityReference>("from");

                PostedByName = noteContact == null
                                        ? activity.Entity.GetAttributeValue <EntityReference>("createdby").Name
                                        : noteContact.Name;

                DisplayToolbar = false;
            }
Exemplo n.º 6
0
            protected void SetPropertyValues(Entity annotation, DataAdapterDependencies dataAdapterDependencies)
            {
                var website = dataAdapterDependencies.GetWebsite();

                CreatedOn        = annotation.GetAttributeValue <DateTime?>("createdon").GetValueOrDefault();
                CreatedOnDisplay = CreatedOn.ToString(DateTimeClientFormat);
                var text = annotation.GetAttributeValue <string>("notetext");

                Text                  = AnnotationHelper.FormatNoteText(text).ToString();
                UnformattedText       = text.Replace(AnnotationHelper.WebAnnotationPrefix, string.Empty);
                AttachmentFileName    = annotation.GetAttributeValue <string>("filename");
                HasAttachment         = !string.IsNullOrEmpty(AttachmentFileName);
                AttachmentContentType = annotation.GetAttributeValue <string>("mimetype");
                AttachmentUrl         = HasAttachment ? annotation.GetFileAttachmentUrl(website) : string.Empty;
                var filesize = annotation.GetAttributeValue <int?>("filesize").GetValueOrDefault(0);

                AttachmentSize        = new FileSize(Convert.ToUInt64(filesize < 0 ? 0 : filesize));
                AttachmentSizeDisplay = AttachmentSize.ToString();
                AttachmentIsImage     = HasAttachment && (new List <string> {
                    "image/jpeg", "image/gif", "image/png"
                }).Contains(AttachmentContentType);
                var subject = annotation.GetAttributeValue <string>("subject");

                Subject   = subject;
                IsPrivate = AnnotationHelper.GetNotePrivacy(annotation);
                var noteContact = AnnotationHelper.GetNoteContact(subject);
                var user        = dataAdapterDependencies.GetPortalUser();

                IsPostedByCurrentUser = noteContact != null && user != null && noteContact.Id == user.Id;
                PostedByName          = noteContact == null?AnnotationHelper.GetNoteCreatedByName(annotation) : noteContact.Name;

                if (CanWrite)
                {
                    CanWrite = IsPostedByCurrentUser;
                }
                if (CanDelete)
                {
                    CanDelete = IsPostedByCurrentUser;
                }
                DisplayToolbar = CanWrite || CanDelete;
            }