Ejemplo n.º 1
0
        public DynamicIndexPageViewModel Build(DynamicEntityMetadata dynamicEntityMetadata)
        {
            var dynamicIndexPageViewModel = new DynamicIndexPageViewModel();

            var routeValuesDictionary = _requestManager.QueryStringDictionary;

            _requestManager.CorrectQuerystringTypes(dynamicEntityMetadata);
            var dynamicFilterViewModels = _dynamicFilterManager.GetFilterPropertyViewModels(dynamicEntityMetadata, routeValuesDictionary);
            var filters = dynamicFilterViewModels.Select(x => (Func <IQueryable, IQueryable>)x.FilterModel.Filter).ToList();

            _pagingManager.SetFilters(dynamicEntityMetadata, filters);
            _pagingManager.ValidatePagingParameters(routeValuesDictionary);
            var models = _pagingManager.GetItems(dynamicEntityMetadata, routeValuesDictionary);


            dynamicIndexPageViewModel.RouteValueDictionaryWrapper = routeValuesDictionary;

            dynamicIndexPageViewModel.RouteValueDictionaryWrapper.SetValue("ReturnUrl", _returnUrlManager.GetReturnUrl("Index", dynamicEntityMetadata.TypeName(), routeValuesDictionary, true));

            dynamicIndexPageViewModel.NextClassName     = _pagingManager.NextClassName(routeValuesDictionary);
            dynamicIndexPageViewModel.PreviousClassName = _pagingManager.PreviousClassName(routeValuesDictionary);
            dynamicIndexPageViewModel.PagingMessage     = _pagingManager.PagingMessage(routeValuesDictionary);

            dynamicIndexPageViewModel.ShowCreate  = dynamicEntityMetadata.ShowCreate();
            dynamicIndexPageViewModel.ShowEdit    = dynamicEntityMetadata.ShowEdit();
            dynamicIndexPageViewModel.ShowDelete  = dynamicEntityMetadata.ShowDelete();
            dynamicIndexPageViewModel.ShowDetails = dynamicEntityMetadata.ShowDetails();

            dynamicIndexPageViewModel.TypeName = dynamicEntityMetadata.TypeName();

            dynamicIndexPageViewModel.DynamicPropertyIndexViewModels = GetDynamicPropertyViewModels(dynamicEntityMetadata, null).ToList();

            var defaultpropertyName    = dynamicEntityMetadata.DefaultProperty().PropertyName();
            var defaultDynamicProperty = dynamicIndexPageViewModel.DynamicPropertyIndexViewModels.SingleOrDefault(x => x.PropertyName == defaultpropertyName);

            if (defaultDynamicProperty != null)
            {
                dynamicIndexPageViewModel.AllowSort                     = true;
                dynamicIndexPageViewModel.DefaultPropertyName           = defaultpropertyName;
                dynamicIndexPageViewModel.DefaultPropertySortExpression = defaultDynamicProperty.SortExpression;
            }

            //table header items
            foreach (var dynamicPropertyIndexViewModel in dynamicIndexPageViewModel.DynamicPropertyIndexViewModels)
            {
                var dynamicTableHeaderViewModel = new DynamicTableHeaderViewModel(dynamicPropertyIndexViewModel, routeValuesDictionary, dynamicEntityMetadata.TypeName());
                dynamicIndexPageViewModel.DynamicTableHeaderViewModels.Add(dynamicTableHeaderViewModel);
            }

            //new view model items
            foreach (var model in models)
            {
                var itemViewModel = BuildItemViewModel(dynamicEntityMetadata, routeValuesDictionary, model);
                dynamicIndexPageViewModel.DynamicIndexItemViewModels.Add(itemViewModel);
                var mobileItemViewModel = BuildMobileItemViewModel(dynamicEntityMetadata, routeValuesDictionary, model);
                dynamicIndexPageViewModel.DynamicIndexMobileItemViewModels.Add(mobileItemViewModel);
            }

            return(dynamicIndexPageViewModel);
        }
 public ParamBuilder ReturnUrl()
 {
     return(ReturnUrl(_returnUrlManager.GetReturnUrl()));
 }