Inheritance: ViewOptionsBase
Example #1
0
        private object _OnViewing(object entity, bool creating)
        {
            if (Viewing != null)
            {
                return(Viewing(entity));
            }

            var options = new ViewOptions
            {
                PropertyRoute = CleanType.IsEmbeddedEntity() ? GetEntityPropertyRoute() : null,
            };

            bool isReadOnly = (ReadonlyEntity ?? Common.GetIsReadOnly(this)) && !creating;

            if (isReadOnly)
            {
                options.ReadOnly = isReadOnly;
            }

            return(Navigator.ViewUntyped(entity, options));
        }
Example #2
0
 public static T View <T>(T entity, ViewOptions options = null)
     where T : ModifiableEntity
 {
     return((T)Manager.View(entity, options ?? new ViewOptions()));
 }
Example #3
0
 public static Lite <T> View <T>(Lite <T> entity, ViewOptions options = null)
     where T : class, IEntity
 {
     return((Lite <T>)Manager.View(entity, options ?? new ViewOptions()));
 }
Example #4
0
 public static object ViewUntyped(object entity, ViewOptions options = null)
 {
     return(Manager.View(entity, options ?? new ViewOptions()));
 }
Example #5
0
        public virtual object View(object entityOrLite, ViewOptions options)
        {
            if (entityOrLite == null)
            {
                throw new ArgumentNullException("entity");
            }

            ModifiableEntity entity   = entityOrLite as ModifiableEntity;
            Type             liteType = null;

            if (entity == null)
            {
                liteType = Lite.Extract(entityOrLite.GetType());
                entity   = Server.Retrieve((Lite <Entity>)entityOrLite);
            }

            EntitySettings es = AssertViewableEntitySettings(entity);

            if (!es.OnIsViewable())
            {
                throw new Exception("{0} is not viewable".FormatWith(entity));
            }

            Control ctrl = options.View ?? es.CreateView(entity, options.PropertyRoute);

            ctrl = es.OnOverrideView(entity, ctrl);

            NormalWindow win = CreateNormalWindow();

            SetNormalWindowEntity(win, (ModifiableEntity)entity, options, es, ctrl);

            if (options.AllowErrors != AllowErrors.Ask)
            {
                win.AllowErrors = options.AllowErrors;
            }

            bool?ok = win.ShowDialog();

            if (ok != true)
            {
                return(null);
            }

            object result = win.DataContext;

            if (liteType != null)
            {
                Entity ident = (Entity)result;

                bool saveProtected = ((ViewOptions)options).RequiresSaveOperation ?? EntityKindCache.RequiresSaveOperation(ident.GetType());

                if (GraphExplorer.HasChanges(ident))
                {
                    if (saveProtected)
                    {
                        throw new InvalidOperationException("The lite '{0}' of type '{1}' is SaveProtected but has changes. Consider setting SaveProtected = false in ViewOptions".FormatWith(entityOrLite, liteType.TypeName()));
                    }

                    return(ident.ToLiteFat());
                }

                return(ident.ToLite());
            }
            return(result);
        }
Example #6
0
        private object _OnViewing(object entity, bool creating)
        {
            if (Viewing != null)
                return Viewing(entity);

            var options = new ViewOptions
            {
                PropertyRoute = CleanType.IsEmbeddedEntity() ? GetEntityPropertyRoute() : null,
            };

            bool isReadOnly = (ReadonlyEntity ?? Common.GetIsReadOnly(this)) && !creating;
            if (isReadOnly)
                options.ReadOnly = isReadOnly;

            return Navigator.ViewUntyped(entity, options);
        }