Exemplo n.º 1
0
        protected internal virtual PartialViewResult PartialView(ControllerBase controller, TypeContext tc, string partialViewName)
        {
            TypeContext cleanTC   = TypeContextUtilities.CleanTypeContext(tc);
            Type        cleanType = cleanTC.UntypedValue.GetType();

            if (!Navigator.IsViewable(cleanType, partialViewName))
            {
                throw new Exception(NormalControlMessage.ViewForType0IsNotAllowed.NiceToString().FormatWith(cleanType.Name));
            }

            controller.ViewData.Model = cleanTC;

            if (Navigator.IsReadOnly(cleanType))
            {
                cleanTC.ReadOnly = true;
            }

            cleanTC.ViewOverrides = Navigator.EntitySettings(cleanType).GetViewOverrides();

            return(new PartialViewResult
            {
                ViewName = partialViewName ?? Navigator.OnPartialViewName((ModifiableEntity)cleanTC.UntypedValue),
                ViewData = controller.ViewData,
                TempData = controller.TempData
            });
        }
Exemplo n.º 2
0
        protected internal virtual PartialViewResult PopupControl(ControllerBase controller, TypeContext typeContext, PopupOptionsBase popupOptions)
        {
            Type cleanType = typeContext.UntypedValue.GetType();

            ModifiableEntity entity = (ModifiableEntity)typeContext.UntypedValue;

            AssertViewableEntitySettings(entity);

            controller.ViewData.Model = typeContext;
            controller.ViewData[ViewDataKeys.PartialViewName] = popupOptions.PartialViewName ?? Navigator.OnPartialViewName(entity);
            typeContext.ViewOverrides = Navigator.EntitySettings(entity.GetType()).GetViewOverrides();

            bool isReadOnly = popupOptions.ReadOnly ?? Navigator.IsReadOnly(entity);

            if (isReadOnly)
            {
                typeContext.ReadOnly = true;
            }

            ViewMode mode = popupOptions.ViewMode;

            controller.ViewData[ViewDataKeys.ViewMode]       = mode;
            controller.ViewData[ViewDataKeys.ShowOperations] = popupOptions.ShowOperations;
            if (mode == ViewMode.View)
            {
                controller.ViewData[ViewDataKeys.RequiresSaveOperation] = ((PopupViewOptions)popupOptions).RequiresSaveOperation ?? EntityKindCache.RequiresSaveOperation(entity.GetType());
            }

            return(new PartialViewResult
            {
                ViewName = PopupControlView,
                ViewData = controller.ViewData,
                TempData = controller.TempData
            });
        }
Exemplo n.º 3
0
 internal static void AssertNotReadonly(Entity ident)
 {
     if (Navigator.IsReadOnly(ident))
     {
         throw new UnauthorizedAccessException("{0} is read-only".FormatWith(ident));
     }
 }
Exemplo n.º 4
0
        public void FillViewDataForViewing(ControllerBase controller, IRootEntity rootEntity, NavigateOptions options)
        {
            TypeContext tc = TypeContextUtilities.UntypedNew(rootEntity, "");

            controller.ViewData.Model = tc;

            var entity = (ModifiableEntity)rootEntity;

            controller.ViewData[ViewDataKeys.PartialViewName] = options.PartialViewName ?? Navigator.OnPartialViewName(entity);
            tc.ViewOverrides = Navigator.EntitySettings(entity.GetType()).GetViewOverrides();

            if (controller.ViewData[ViewDataKeys.TabId] == null)
            {
                controller.ViewData[ViewDataKeys.TabId] = GetOrCreateTabID(controller);
            }

            controller.ViewData[ViewDataKeys.ShowOperations] = options.ShowOperations;

            controller.ViewData[ViewDataKeys.WriteEntityState] = options.WriteEntityState || (bool?)controller.ViewData[ViewDataKeys.WriteEntityState] == true;

            AssertViewableEntitySettings(entity);

            tc.ReadOnly = options.ReadOnly ?? Navigator.IsReadOnly(entity);
        }