예제 #1
0
        public virtual async Task <IEntityViewModel <TViewModel> > ListViewModel <TViewModel>([FromService] IDatabaseContext database, [FromService] IAuthenticationProvider authenticationProvider, [FromOptions] EntityDomainAuthorizeOption authorizeOption, [FromOptions(true)] EntityQuerySelectOption <T, TViewModel> selectOption)
        {
            var auth = authenticationProvider.GetAuthentication();

            if (authorizeOption == null)
            {
                authorizeOption = EntityDomainAuthorizeOption.View;
            }
            authorizeOption.Validate(Metadata, auth);
            var context   = database.GetContext <T>();
            var queryable = context.Query();
            var e         = new EntityQueryEventArgs <T>(queryable);

            await RaiseAsyncEvent(EntityQueryEvent, e);

            queryable = e.Queryable;
            var convertQueryable = selectOption.Select(queryable);
            EntityViewModel <TViewModel> model       = new EntityViewModel <TViewModel>(convertQueryable);
            EntityPagerOption            pagerOption = Context.DomainContext.Options.GetOption <EntityPagerOption>();

            if (pagerOption != null)
            {
                model.CurrentSize    = pagerOption.CurrentSize;
                model.CurrentPage    = pagerOption.CurrentPage;
                model.PageSizeOption = pagerOption.PageSizeOption;
            }
            await model.UpdateTotalPageAsync();

            await model.UpdateItemsAsync();

            return(model);
        }
예제 #2
0
        public virtual async Task <IEntityViewModel <T> > List([FromService] IDatabaseContext database, [FromService] IAuthenticationProvider authenticationProvider, [FromOptions] EntityDomainAuthorizeOption authorizeOption)
        {
            var auth = authenticationProvider.GetAuthentication();

            if (authorizeOption == null)
            {
                authorizeOption = EntityDomainAuthorizeOption.View;
            }
            authorizeOption.Validate(Metadata, auth);
            var context   = database.GetContext <T>();
            var queryable = context.Query();

            foreach (var propertyMetadata in Metadata.Properties.Where(t => t.CustomType == "Entity"))
            {
                queryable = context.Include(queryable, propertyMetadata.ClrName);
            }
            var e = new EntityQueryEventArgs <T>(queryable);

            await RaiseAsyncEvent(EntityQueryEvent, e);

            queryable = e.Queryable;
            if (!e.IsOrdered)
            {
                queryable = context.Order(queryable);
            }
            EntityViewModel <T> model = new EntityViewModel <T>(queryable);

            model.Properties = authorizeOption.GetProperties(Metadata, auth);
            EntityPagerOption pagerOption = Context.DomainContext.Options.GetOption <EntityPagerOption>();

            if (pagerOption != null)
            {
                model.CurrentSize    = pagerOption.CurrentSize;
                model.CurrentPage    = pagerOption.CurrentPage;
                model.PageSizeOption = pagerOption.PageSizeOption;
            }
            await model.UpdateTotalPageAsync();

            await model.UpdateItemsAsync();

            return(model);
        }