コード例 #1
0
        public virtual ActionResult BatchEdit(UpdateListPageModel items)
        {
            if (items is null)
            {
                throw new ArgumentNullException(nameof(items));
            }

            //This will be used to hold the returned entities while we build our return object
            List <object> Entities = this.GetEntitiesByGuids(items.Guids.Select(s => Guid.Parse(s)).ToList());

            //We're gonna use this to determine the eventual return type of the list
            Type commonType = Entities.GetCommonType();

            DynamicRenderer renderer = new DynamicRenderer(new DynamicRendererSettings(commonType, this.FileProvider)
            {
                ExactOnly = true
            });

            BatchEditModelPageModel BEmodel = new BatchEditModelPageModel
            {
                Guids    = items.Guids,
                Template = Activator.CreateInstance(commonType)
            };

            MetaObject model = new MetaObject(BEmodel, Constructor);

            model.Hydrate();

            return(this.View(model));
        }
        /// <summary>
        /// Converts an IEnumerable to an IEnumerable of MetObjects
        /// </summary>
        /// <typeparam name="T">The type of the list to convert</typeparam>
        /// <param name="source">The source IEnumerable</param>
        /// <param name="c">A constructor to use during the generation</param>
        /// <param name="Hydrate">Should the return objects be hydrated?</param>
        /// <returns>And IEnumerable of converted objects</returns>
        public static IEnumerable <IMetaObject> ToMetaList <T>(this IEnumerable <T> source, MetaConstructor c, bool Hydrate = false)
        {
            if (source is null)
            {
                throw new System.ArgumentNullException(nameof(source));
            }

            c = c ?? new MetaConstructor();

            foreach (T o in source)
            {
                MetaObject m = new MetaObject(o, c);

                if (Hydrate)
                {
                    m.Hydrate();
                }

                yield return(m);
            }
        }
コード例 #3
0
        // GET: Form
        public ActionResult ViewByName(string Name)
        {
            Form thisForm = this.FormRepository.GetByName(Name);

            if (thisForm is null)
            {
                return(this.Redirect("/Error/NotFound"));
            }

            if (thisForm.IsJsonForm)
            {
                return(this.View("ViewJsonForm", thisForm));
            }
            else
            {
                MetaConstructor c = AdminController.Constructor;

                MetaObject mo = new MetaObject(thisForm, c);
                mo.Hydrate();
                return(this.View("ViewForm", mo));
            }
        }
コード例 #4
0
        public ActionResult ListEntries(string TypeName = "", Guid?Target = null, int count = 20, int page = 0)
        {
            bool typeSelected = !string.IsNullOrWhiteSpace(TypeName);

            IQueryable <AuditEntry> FilterQuery(IQueryable <AuditEntry> toQuery)
            {
                return(toQuery.Where(a => (!typeSelected || a.TypeName == TypeName) && (Target == null || a.Target == Target)));
            }

            MetaConstructor c = Constructor;

            PagedListContainer <IMetaObject> model = new PagedListContainer <IMetaObject>
            {
                TotalCount = FilterQuery(AuditEntryRepository.All).Count(),
                Page       = page,
                Count      = count
            };

            model.Items.AddRange(FilterQuery(AuditEntryRepository.All).OrderByDescending(a => a.Logged).Skip(page * count).Take(count).ToList().Select(o => { MetaObject me = new MetaObject(o, c); me.Hydrate(); return(me); }));

            if (Target.HasValue)
            {
                model.HiddenColumns.Add(nameof(Target));
                model.HiddenColumns.Add(nameof(TypeName));
            }
            else if (!string.IsNullOrWhiteSpace(TypeName))
            {
                model.HiddenColumns.Add(nameof(TypeName));
            }

            return(this.View(model));
        }