예제 #1
0
        internal void RegisterMappings()
        {
            ConfigureFilterMaps();
            ConfigureEntityMaps();
            ConfigureAuditMaps();
            ConfigureFileMaps(this._imageConverter);

            DataMapper.CreateMap <Vocabulary, VocabularyViewModel>().AfterMap((vocabulary, model) =>
            {
                model.CanEdit = StrixPlatform.User.IsInRole(CmsRoleNames.EDITORROLES);
            });

            DataMapper.CreateMap <Term, TermViewModel>();
            var tagConfig = new MapConfig <IContent, EntityViewModel>();

            tagConfig.MembersToMap.Add(d => d.Tags, s => s.Entity.Tags);
            DataMapper.RegisterMapConfig(tagConfig);

            DataMapper.CreateMap <Comment, CommentViewModel>()
            .ForMember(cv => cv.CreatedBy, ce => ce.MapFrom(co => StrixCms.GetUserName(co.CreatedByUserId)))
            .ForMember(cv => cv.CreatedByEmail, ce => ce.MapFrom(co => StrixCms.GetUserEmail(co.CreatedByUserId)))
            .ForMember(cv => cv.UpdatedBy, ce => ce.MapFrom(co => StrixCms.GetUserName(co.UpdatedByUserId)));
            DataMapper.CreateMap <CommentViewModel, Comment>()
            .ForMember(co => co.CreatedByUserId, ce => ce.Ignore())
            .ForMember(co => co.CreatedOn, ce => ce.Ignore());

            DataMapper.CreateMap <File, FileDisplayModel>();
            DataMapper.CreateMap <FileDisplayModel, File>().ForAllMembers(mem => mem.Ignore());
            DataMapper.CreateMap <MailContentTemplate, MailContentTemplateViewModel>();

            ConfigureHtmlEncoding();
        }
예제 #2
0
        private static void ConfigureAuditMaps()
        {
            Action <object, object> auditAction = (x, y) =>
            {
                var audit = x as IAudit;
                var model = y as AuditViewModel;
                model.CanEdit   = StrixPlatform.User.IsInRole(CmsRoleNames.EDITORROLES) || model.CreatedByUserId == StrixPlatform.User.Id;
                model.UpdatedBy = StrixCms.GetUserName(audit.UpdatedByUserId);
                model.CreatedBy = StrixCms.GetUserName(audit.CreatedByUserId);

                var content = x as IContent;

                if (content != null)
                {
                    if (model is EntityViewModel && content.PublishedByUserId.HasValue)
                    {
                        ((EntityViewModel)model).PublishedBy = StrixCms.GetUserName(content.PublishedByUserId.Value);
                    }
                }
            };

            var listAuditConfig = new MapConfig <AuditViewModel, AuditViewModel>();

            listAuditConfig.AfterMapAction = auditAction;
            DataMapper.RegisterMapConfig(listAuditConfig);

            var entityAuditConfig = new MapConfig <IContent, AuditViewModel>();

            entityAuditConfig.AfterMapAction = auditAction;
            DataMapper.RegisterMapConfig(entityAuditConfig);

            var auditReturnConfig = new MapConfig <EntityViewModel, IContent>();

            auditReturnConfig.MembersToIgnore.Add(d => d.IsCurrentVersion);
            auditReturnConfig.MembersToIgnore.Add(d => d.CreatedByUserId);
            auditReturnConfig.MembersToIgnore.Add(d => d.CreatedOn);
            auditReturnConfig.MembersToIgnore.Add(d => d.UpdatedByUserId);
            auditReturnConfig.MembersToIgnore.Add(d => d.UpdatedOn);
            DataMapper.RegisterMapConfig(auditReturnConfig);
        }
예제 #3
0
        public IList <VersionViewModel> GetVersionList(Guid id, string culture, FilterOptions filter)
        {
            var result = new List <VersionViewModel>();
            var map    = EntityHelper.GetObjectMap(typeof(TModel));

            culture = string.IsNullOrWhiteSpace(culture) ? StrixPlatform.CurrentCultureCode : culture;

            if (filter == null || filter.Sort.IsEmpty())
            {
                if (filter == null)
                {
                    filter = new FilterOptions();
                }

                filter.Sort.Add(new SortField {
                    Field = "VersionNumber", Dir = "desc"
                });
            }

            IQueryable query      = this.Manager.Query(map.ContentType).Where("EntityId.Equals(@0) AND Culture.ToLower().Equals(@1)", id, culture).Filter(filter);
            var        projection = query.Select("new ( CreatedByUserId, CreatedOn, VersionNumber, VersionLog, IsCurrentVersion )");

            foreach (var item in projection)
            {
                result.Add(new VersionViewModel
                {
                    EntityId         = id,
                    VersionNumber    = (int)item.GetPropertyValue("VersionNumber"),
                    IsCurrentVersion = (bool)item.GetPropertyValue("IsCurrentVersion"),
                    CreatedBy        = StrixCms.GetUserName((Guid)item.GetPropertyValue("CreatedByUserId")),
                    CreatedOn        = (DateTime)item.GetPropertyValue("CreatedOn"),
                    Log = (string)item.GetPropertyValue("VersionLog"),
                });
            }

            return(result);
        }