Пример #1
0
        public DocumentTypeInfo SelectByCode(string Code)
        {
            try
            {
                using (var item = new IGDDemoEntities())
                {
                    var documentType = item.DocumentTypes.FirstOrDefault(d => d.Code == Code);

                    if (documentType == null)
                    {
                        return(null);
                    }

                    DocumentTypeInfo documentTypeInfo = new DocumentTypeInfo
                    {
                        Id    = documentType.Id,
                        Title = documentType.Title,
                        Code  = documentType.Code
                    };

                    return(documentTypeInfo);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Пример #2
0
        public DocumentTypeInfo SelectById(int documentTypeId)
        {
            try
            {
                using (var item = new IGDDemoEntities())
                {
                    var documentType = item.DocumentTypes.Find(documentTypeId);

                    if (documentType == null)
                    {
                        return(null);
                    }

                    DocumentTypeInfo documentTypeInfo = new DocumentTypeInfo
                    {
                        Id    = documentType.Id,
                        Title = documentType.Title,
                        Code  = documentType.Code
                    };

                    return(documentTypeInfo);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Пример #3
0
        public bool Update(DocumentTypeInfo documentTypeInfo)
        {
            try
            {
                using (var scope = new TransactionScope())
                {
                    using (var item = new IGDDemoEntities())
                    {
                        // Un tercer parámetro del FirstOrDefault recibe un predicado que es una función que me devuelve un valor.
                        var documentTypeData = item.DocumentTypes.FirstOrDefault(d => d.Id == documentTypeInfo.Id);

                        if (documentTypeData != null)
                        {
                            documentTypeData.Title = documentTypeInfo.Title;
                            documentTypeData.Code  = documentTypeInfo.Code;

                            item.Entry(documentTypeData).State = System.Data.Entity.EntityState.Modified;
                            item.Entry(documentTypeData).CurrentValues.SetValues(documentTypeData);
                            item.SaveChanges();
                            scope.Complete();
                            return(true);
                        }

                        scope.Dispose();
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Пример #4
0
        public bool Insert(DocumentTypeInfo documentType)
        {
            try
            {
                using (var scope = new TransactionScope())
                {
                    using (var item = new IGDDemoEntities())
                    {
                        DocumentTypes igdDocumentTypes = new DocumentTypes()
                        {
                            Title = documentType.Title,
                            Code  = documentType.Code
                        };

                        item.DocumentTypes.Add(igdDocumentTypes);

                        if (item.SaveChanges().Equals(1))
                        {
                            scope.Complete();
                            return(true);
                        }

                        scope.Dispose();
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Пример #5
0
 public void SetUp()
 {
     Configuration = new CodeGeneratorConfiguration().MediaTypes;
     Parser        = new DocumentTypeInfoParser(Configuration);
     ContentType   = new DocumentType();
     Info          = ContentType.Info;
     typedInfo     = (DocumentTypeInfo)Info;
 }
        public DocumentTypeInfo ToModel()
        {
            var document = new DocumentTypeInfo();

            CopyCstor.Copy <IDocumentTypeWritable> (this, document);

            return(document);
        }
Пример #7
0
 private static void MapDocumentTypeInfo(IContentType umbracoContentType, DocumentTypeInfo info)
 {
     MapInfo(umbracoContentType, info);
     info.AllowedTemplates = umbracoContentType.AllowedTemplates.Select(t => t.Alias).ToList();
     info.DefaultTemplate  = umbracoContentType.DefaultTemplate != null ? umbracoContentType.DefaultTemplate.Alias : null;
     info.Master           = umbracoContentType.ParentId > -1
                 ? umbracoContentType.ContentTypeComposition.First(cmp => cmp.Id == umbracoContentType.ParentId).Alias
                 : "";
 }
 public void SetUp()
 {
     Configuration = CodeGeneratorConfiguration.Create().MediaTypes;
     Candidate     = Type = new CodeTypeDeclaration();
     generator     = new DocumentTypeInfoGenerator(Configuration);
     documentType  = new DocumentType {
         Info = { Alias = "aClass" }
     };
     info = (DocumentTypeInfo)documentType.Info;
 }
            public void TestDocumentTypesDelete()
            {
                Assert.IsTrue(DocumentTypesRepository.GetInstance().Insert(new DocumentTypeInfo()
                {
                    Title = "Tipo Documento Prueba", Code = "TDP001"
                }));

                DocumentTypeInfo temp = DocumentTypesRepository.GetInstance().SelectByCode("TDP001");

                Assert.IsTrue(DocumentTypesRepository.GetInstance().Delete(temp.Id));
            }
Пример #10
0
 public void SetUp()
 {
     Configuration = CodeGeneratorConfiguration.Create().MediaTypes;
     attribute     = new CodeAttributeDeclaration("DocumentType");
     generator     = new DocumentTypeInfoGenerator(Configuration);
     documentType  = new DocumentType
     {
         Info = info = new DocumentTypeInfo {
             Alias = "aClass"
         }
     };
 }
        private static void AddAllowedTemplates(CodeTypeDeclaration type, DocumentTypeInfo info)
        {
            if (info.AllowedTemplates.All(String.IsNullOrWhiteSpace))
            {
                return;
            }
            var field = new CodeMemberField(
                typeof(string[]),
                "allowedTemplates"
                );
            var expressions =
                info.AllowedTemplates
                .NonNullOrWhiteSpace()
                .AsPrimitiveExpressions();

            field.InitExpression = new CodeArrayCreateExpression(
                typeof(string[]),
                expressions
                );
            type.Members.Add(field);
        }
Пример #12
0
 public DocumentType()
 {
     Info = new DocumentTypeInfo();
 }
Пример #13
0
        /// <summary>
        /// Creates mappings for Persistence/Hive to/from Cms View Models
        /// </summary>
        public void ConfigurePersistenceToModelMappings()
        {
            #region File -> FileEditorModel

            this.CreateMap <File, FileEditorModel>()
            .CreateUsing(x => new FileEditorModel(x.Id, x.Name, x.UtcCreated, x.UtcModified, () => Encoding.UTF8.GetString(x.ContentBytes)));
            //NOTE: currently parent Id isn't being used for the file editor, but if we want to enable it, this is what we'd do:
            //.ForMember(x => x.UtcModified, opt => opt.MapFrom(x => x.Relations.Parent<File>(FixedRelationTypes.DefaultRelationType).Id));

            #endregion

            #region UserGroup -> UserGroupPermissionsModel

            this.CreateMap <UserGroup, UserGroupPermissionsModel>()
            .CreateUsing(x => new UserGroupPermissionsModel())
            .MapMemberFrom(x => x.UserGroupId, y => y.Id)
            .MapMemberFrom(x => x.UserGroupHtmlId, y => y.Id.GetHtmlId())
            .MapMemberFrom(x => x.UserGroupName, y => y.Name)
            .AfterMap((s, t) =>
            {
            });

            #endregion

            #region PermissionMetadata -> PermissionStatusModel

            this.CreateMap <PermissionMetadata, PermissionStatusModel>()
            .CreateUsing(x => new PermissionStatusModel())
            .MapMemberFrom(x => x.PermissionId, y => y.Id)
            .MapMemberFrom(x => x.PermissionName, y => y.Name);

            #endregion

            #region AttributeGroup -> Tab

            this.CreateMap <AttributeGroup, Tab>()
            .MapMemberFrom(x => x.SortOrder, x => x.Ordinal)
            .AfterMap((from, to) =>
            {
                if (from is InheritedAttributeGroup)
                {
                    to.SchemaId = ((InheritedAttributeGroup)from).Schema.Id;
                }
            });

            #endregion

            #region AttributeType -> DataTypeEditorModel

            this.CreateMap <AttributeType, DataTypeEditorModel>()
            .CreateUsing(x => new DataTypeEditorModel())
            .MapMemberUsing(x => x.PropertyEditorId, new AttributeTypeToPropertyEditorId(this, _resolverContext))
            .MapMemberUsing(x => x.PropertyEditorPackage, new AttributeTypeToPropertyEditorPackageName(this, _resolverContext))
            .AfterMap((source, dest) =>
            {
                var dataType             = Map <AttributeType, DataType>(source);
                dest.PreValueEditorModel = dataType.GetPreValueModel();
            });

            #endregion

            #region AttributeType -> DataType

            this.CreateMap <AttributeType, DataType>()
            .CreateUsing(x =>
            {
                if ((x.Name == null || x.Name.Value.IsNullOrWhiteSpace()) && string.IsNullOrEmpty(x.Alias))
                {
                    throw new ArgumentNullException("Cannot create a DataType when the incoming Name and Alias are both null or empty");
                }
                if (string.IsNullOrEmpty(x.Alias))
                {
                    x.Alias = x.Name.Value.ToRebelAlias();
                }
                return(new DataType(x.Id, x.Name, x.Alias, null, x.RenderTypeProviderConfig));
            })
            .AfterMap((source, dest) =>
            {
                //need to set this manually since MapUsing doesn't work with internal members
                dest.Prevalues = source.RenderTypeProviderConfig;

                //need to set this manually since MapUsing doesn't work with internal members
                Guid output;
                var guid = Guid.TryParse(source.RenderTypeProvider, out output) ? output : Guid.Empty;
                if (guid != Guid.Empty)
                {
                    var editor = _resolverContext.PropertyEditorFactory.GetPropertyEditor(guid);
                    if (editor != null)
                    {
                        dest.InternalPropertyEditor = editor.Value;
                        //set the package name if it is available
                        if (editor.Metadata.PluginDefinition != null)
                        {
                            dest.PropertyEditorPackage = editor.Metadata.PluginDefinition.PackageName;
                        }
                    }
                }
            });

            #endregion

            #region TypedAttribute -> ContentProperty

            this.CreateMap <TypedAttribute, ContentProperty>()
            .CreateUsing(x =>

                         new ContentProperty(x.Id,
                                             Map <AttributeDefinition, DocumentTypeProperty>(x.AttributeDefinition),
                                             x.Values))
            //need to make sure the Id is ignored since we set it in the ctor!
            .ForMember(x => x.Id, opt => opt.Ignore())
            .MapMemberFrom(x => x.TabId, x => x.AttributeDefinition.AttributeGroup.Id)
            .MapMemberFrom(x => x.TabAlias, x => x.AttributeDefinition.AttributeGroup.Alias)
            .MapMemberFrom(x => x.SortOrder, x => x.AttributeDefinition.Ordinal)
            .MapMemberFrom(x => x.Name, x => x.AttributeDefinition.Name.ToString())
            .MapMemberFrom(x => x.Alias, x => x.AttributeDefinition.Alias)
            .AfterMap((source, dest) =>
            {
                //set the property editor context if it needs it
                if (dest.DocTypeProperty.DataType.InternalPropertyEditor != null &&
                    dest.DocTypeProperty.DataType.InternalPropertyEditor is IContentAwarePropertyEditor)
                {
                    ((IContentAwarePropertyEditor)dest.DocTypeProperty.DataType.InternalPropertyEditor).SetContentProperty(dest);
                }
            });

            #endregion

            #region AttributeDefinition -> DocumentTypeProperty

            this.CreateMap <AttributeDefinition, DocumentTypeProperty>()
            .CreateUsing(
                x => new DocumentTypeProperty(Map <AttributeType, DataType>(x.AttributeType)))
            .MapMemberFrom(x => x.SortOrder, x => x.Ordinal)
            .MapMemberFrom(x => x.TabId, x => x.AttributeGroup.Id)
            .MapMemberFrom(x => x.TabAlias, x => x.AttributeGroup.Alias)
            .AfterMap((source, dest) =>
            {
                if (source.AttributeType != null)
                {
                    //we need to check if this prevalue model has been overridden!
                    if (!string.IsNullOrEmpty(source.RenderTypeProviderConfigOverride))
                    {
                        var tmpDataType1       = Map <AttributeType, DataType>(source.AttributeType);
                        tmpDataType1.Prevalues = source.RenderTypeProviderConfigOverride;

                        var tmpDataType2       = Map <AttributeType, DataType>(source.AttributeType);
                        tmpDataType2.Prevalues = dest.DataType.Prevalues;

                        var tmpPreValueModel1 = tmpDataType1.GetPreValueModel();
                        var tmpPreValueModel2 = tmpDataType2.GetPreValueModel();

                        //copy overridable prevalues over
                        if (tmpPreValueModel1 != null && tmpPreValueModel2 != null)
                        {
                            foreach (var prop in tmpPreValueModel2.GetType().GetProperties().Where(p => p.GetCustomAttributes <AllowDocumentTypePropertyOverrideAttribute>(false).Any()))
                            {
                                var overriddenValue = prop.GetValue(tmpPreValueModel1, null);
                                prop.SetValue(tmpPreValueModel2, overriddenValue, null);
                            }

                            //re-set the pre-value string on the data type, so now we can get the pre-value model with the overridden values
                            dest.DataType.Prevalues = tmpPreValueModel2.GetSerializedValue();
                        }
                    }
                }


                var inherited = source as InheritedAttributeDefinition;
                if (inherited != null)
                {
                    dest.SchemaId   = inherited.Schema.Id;
                    dest.SchemaName = inherited.Schema.Name;
                }
            });

            #endregion

            #region EntitySchema -> DocumentTypeInfo

            this.CreateMap <EntitySchema, DocumentTypeInfo>()
            .CreateUsing(x =>
            {
                var documentTypeInfo = new DocumentTypeInfo()
                {
                    Thumbnail   = x.GetXmlConfigProperty("thumb"),
                    Name        = x.Name,
                    Icon        = x.GetXmlConfigProperty("icon"),
                    Description = x.GetXmlConfigProperty("description")
                };
                return(documentTypeInfo);
            });

            #endregion

            #region EntitySchema -> DocumentTypeEditorModel

            this.CreateMap(new EntitySchemaToSchemaEditorModel <DocumentTypeEditorModel>(this,
                                                                                         x => new DocumentTypeEditorModel(),
                                                                                         (f, t) =>
            {
                t.DefaultTemplateId = f.GetXmlConfigProperty <HiveId>("default-template");
                //get the stored allowed tempaltes
                var allowedItems     = f.GetXmlPropertyAsList <HiveId>("allowed-templates") ?? new List <HiveId>();
                t.AllowedTemplateIds = new HashSet <HiveId>(allowedItems);
            }));

            #endregion

            #region EntitySchema -> MediaTypeEditorModel

            this.CreateMap(new EntitySchemaToSchemaEditorModel <MediaTypeEditorModel>(this, x => new MediaTypeEditorModel()));

            #endregion

            #region EntitySchema -> ProfileTypeEditorModel

            this.CreateMap(new EntitySchemaToSchemaEditorModel <ProfileTypeEditorModel>(this, x => new ProfileTypeEditorModel()));

            #endregion

            #region TypedEntity -> ContentEditorModel

            this.CreateMap(new TypedEntityToContentEditorModel <TypedEntity, ContentEditorModel>(this, _resolverContext))
            .CreateUsing(x => new ContentEditorModel());

            #endregion

            #region TypedEntity -> MediaEditorModel

            this.CreateMap(new TypedEntityToContentEditorModel <TypedEntity, MediaEditorModel>(this, _resolverContext))
            .CreateUsing(x => new MediaEditorModel());

            #endregion

            #region TypedEntity -> DictionaryItemEditorModel

            this.CreateMap(new TypedEntityToContentEditorModel <TypedEntity, DictionaryItemEditorModel>(this, _resolverContext))
            .CreateUsing(x => new DictionaryItemEditorModel());

            #endregion

            #region User -> UserEditorModel

            this.CreateMap(new TypedEntityToContentEditorModel <User, UserEditorModel>(this, _resolverContext))
            .CreateUsing(x => new UserEditorModel())
            .ForMember(x => x.LastLoginDate, x => x.MapFrom(y => y.LastLoginDate.UtcDateTime))
            .ForMember(x => x.LastActivityDate, x => x.MapFrom(y => y.LastActivityDate.UtcDateTime))
            .ForMember(x => x.LastPasswordChangeDate, x => x.MapFrom(y => y.LastPasswordChangeDate.UtcDateTime));

            #endregion

            #region Member -> MemberEditorModel

            this.CreateMap(new TypedEntityToContentEditorModel <Member, MemberEditorModel>(this, _resolverContext))
            .CreateUsing(x => new MemberEditorModel())
            .ForMember(x => x.LastLoginDate, x => x.MapFrom(y => y.LastLoginDate.UtcDateTime))
            .ForMember(x => x.LastActivityDate, x => x.MapFrom(y => y.LastActivityDate.UtcDateTime))
            .ForMember(x => x.LastPasswordChangeDate, x => x.MapFrom(y => y.LastPasswordChangeDate.UtcDateTime));

            #endregion

            #region UserGroup -> UserGroupEditorModel

            this.CreateMap(new TypedEntityToContentEditorModel <UserGroup, UserGroupEditorModel>(this, _resolverContext))
            .CreateUsing(x => new UserGroupEditorModel())
            //ignore all custom properties as these need to be mapped by the underlying attributes
            .ForMember(x => x.Name, opt => opt.Ignore());

            #endregion

            #region User -> UserData

            this.CreateMap <User, UserData>()
            .CreateUsing(x => new UserData())
            .ForMember(x => x.Id, x => x.MapFrom(y => y.Id.ToString()))
            .ForMember(x => x.RealName, x => x.MapFrom(y => y.Name))
            .ForMember(x => x.Username, x => x.MapFrom(y => y.Username))
            .ForMember(x => x.StartContentNode, x => x.MapFrom(y => y.StartContentHiveId.IsNullValueOrEmpty() ? HiveId.Empty.ToString() : y.StartContentHiveId.ToString()))
            .ForMember(x => x.StartMediaNode, x => x.MapFrom(y => y.StartMediaHiveId.IsNullValueOrEmpty() ? HiveId.Empty.ToString() : y.StartMediaHiveId.ToString()))
            .ForMember(x => x.AllowedApplications, x => x.MapFrom(y => y.Applications.ToArray()))
            .AfterMap((s, t) =>
            {
                var groupHive = _resolverContext.Hive.GetReader <ISecurityStore>();
                using (var uow = groupHive.CreateReadonly())
                {
                    var groups = uow.Repositories.Get <TypedEntity>(true, s.Groups.ToArray());
                    t.Roles    = groups.Select(x => (string)x.Attributes[NodeNameAttributeDefinition.AliasValue].DynamicValue).ToArray();
                }
            });

            #endregion

            #region EntitySnapshot<T> > ContentEditorModel

            this.CreateMap(new EntitySnapshotToContentEditorModel <ContentEditorModel>(this));

            #endregion

            #region EntitySnapshot<T> > MediaEditorModel

            this.CreateMap(new EntitySnapshotToContentEditorModel <MediaEditorModel>(this));

            #endregion

            #region EntitySnapshot<T> > DictionaryItemEditorModel

            this.CreateMap(new EntitySnapshotToContentEditorModel <DictionaryItemEditorModel>(this));

            #endregion

            #region Revision<TypedEntity> -> ContentEditorModel

            this.CreateMap(new RevisionToContentEditorModel <ContentEditorModel>(this));

            #endregion

            #region Revision<TypedEntity> -> MediaEditorModel

            this.CreateMap(new RevisionToContentEditorModel <MediaEditorModel>(this));

            #endregion

            #region Revision<TypedEntity> -> DictionaryItemEditorModel

            this.CreateMap(new RevisionToContentEditorModel <DictionaryItemEditorModel>(this));

            #endregion

            #region LanguageElement -> LanguageEditorModel

            this.CreateMap <LanguageElement, LanguageEditorModel>()
            .ForMember(x => x.Fallbacks, opts => opts.MapFrom(x => x.Fallbacks.Select(y => y.IsoCode)));

            #endregion

            #region StylesheetRule -> StylesheetRuleEditorModel

            this.CreateMap <StylesheetRule, StylesheetRuleEditorModel>()
            .CreateUsing(x => new StylesheetRuleEditorModel())
            .MapMemberFrom(x => x.Id, x => x.RuleId)
            .ForMember(x => x.ParentId, x => x.MapFrom(y => y.StylesheetId));

            #endregion

            #region PackageDefinition -> PackageDefinitionEditorModel

            this.CreateMap <PackageDefinition, PackageDefinitionEditorModel>()
            .CreateUsing(x => new PackageDefinitionEditorModel());

            #endregion
        }
        public DocumentTypeInfo ToModel ()
        {
            var document = new DocumentTypeInfo ();
            CopyCstor.Copy<IDocumentType> (this, document);

            return document;
        }