Beispiel #1
0
 protected void HandleInvalidModelState <T, TPersisted>(ContentItemDisplayBase <T, TPersisted> display)
     where TPersisted : IContentBase
     where T : ContentPropertyBasic
 {
     //lasty, if it is not valid, add the modelstate to the outgoing object and throw a 403
     if (!ModelState.IsValid)
     {
         display.Errors = ModelState.ToErrorDictionary();
         throw new HttpResponseException(Request.CreateValidationErrorResponse(display));
     }
 }
        /// <summary>
        /// Maps properties on to the generic properties tab
        /// </summary>
        /// <param name="content"></param>
        /// <param name="display"></param>
        /// <param name="customProperties">
        /// Any additional custom properties to assign to the generic properties tab.
        /// </param>
        /// <param name="onGenericPropertiesMapped"></param>
        /// <remarks>
        /// The generic properties tab is mapped during AfterMap and is responsible for
        /// setting up the properties such as Created date, updated date, template selected, etc...
        /// </remarks>
        public static void MapGenericProperties <TPersisted>(
            TPersisted content,
            ContentItemDisplayBase <ContentPropertyDisplay, TPersisted> display,
            IEnumerable <ContentPropertyDisplay> customProperties             = null,
            Action <List <ContentPropertyDisplay> > onGenericPropertiesMapped = null)
            where TPersisted : IContentBase
        {
            var genericProps = display.Tabs.Single(x => x.Id == 0);

            //store the current props to append to the newly inserted ones
            var currProps = genericProps.Properties.ToArray();

            var labelEditor = PropertyEditorResolver.Current.GetByAlias(Constants.PropertyEditors.NoEditAlias).ValueEditor.View;

            var contentProps = new List <ContentPropertyDisplay>
            {
                new ContentPropertyDisplay
                {
                    Alias = string.Format("{0}id", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
                    Label = "Id",
                    Value = Convert.ToInt32(display.Id).ToInvariantString() + "<br/><small class='muted'>" + display.Key + "</small>",
                    View  = labelEditor
                },
                new ContentPropertyDisplay
                {
                    Alias       = string.Format("{0}creator", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
                    Label       = ui.Text("content", "createBy"),
                    Description = ui.Text("content", "createByDesc"), //TODO: Localize this
                    Value       = display.Owner.Name,
                    View        = labelEditor
                },
                new ContentPropertyDisplay
                {
                    Alias       = string.Format("{0}createdate", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
                    Label       = ui.Text("content", "createDate"),
                    Description = ui.Text("content", "createDateDesc"),
                    Value       = display.CreateDate.ToIsoString(),
                    View        = labelEditor
                },
                new ContentPropertyDisplay
                {
                    Alias       = string.Format("{0}updatedate", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
                    Label       = ui.Text("content", "updateDate"),
                    Description = ui.Text("content", "updateDateDesc"),
                    Value       = display.UpdateDate.ToIsoString(),
                    View        = labelEditor
                },
                new ContentPropertyDisplay
                {
                    Alias = string.Format("{0}doctype", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
                    Label = ui.Text("content", "documentType"),
                    Value = TranslateItem(display.ContentTypeName, CreateDictionary()),
                    View  = labelEditor
                }
            };

            if (customProperties != null)
            {
                //add the custom ones
                contentProps.AddRange(customProperties);
            }

            //now add the user props
            contentProps.AddRange(currProps);

            //callback
            if (onGenericPropertiesMapped != null)
            {
                onGenericPropertiesMapped(contentProps);
            }

            //re-assign
            genericProps.Properties = contentProps;
        }