예제 #1
0
        public void Visit(ITableDataAdapter tableDataAdapter)
        {
            if (tableDataAdapter is CollectionTableDataAdapter <TItem> collectionTableDataAdapter)
            {
                var selectedItemType      = _masterDetailRowArguments.SelectedItem.GetType();
                var detailAdapterItemType = _masterDetailRowArguments.DataAdapter.UnderlyingTypeOfItem;

                var constantValue = _propertyValueAccessorCache
                                    .GetPropertyAccesor(selectedItemType)
                                    .GetValue(_masterDetailRowArguments.SelectedItem, _masterDetailRelationship.MasterDetailConnection.MasterPropertyName);

                var parameter = Expression.Parameter(detailAdapterItemType, "x");
                var member    = Expression.Property(parameter, _masterDetailRelationship.MasterDetailConnection.ForeignPropertyName);

                //If the type of the member expression is a nullable,
                //the call to Expression.Equal will fail
                Expression constant;
                if (member.Type.IsGenericType && member.Type.GetGenericTypeDefinition() == typeof(Nullable <>))
                {
                    constant = Expression.Constant(constantValue, member.Type);
                }
                else
                {
                    constant = Expression.Constant(constantValue);
                }

                var body = Expression.Equal(member, constant);

                collectionTableDataAdapter.Filter = Expression.Lambda <Func <TItem, bool> >(body, parameter);
            }
        }
예제 #2
0
        public CreateItemRendererContext(ICreateItemFormViewModel <TItem> createItemFormViewModel, ITypePropertyAccessorCache typePropertyAccessorCache)
        {
            this.typePropertyAccessor = typePropertyAccessorCache?.GetPropertyAccesor(typeof(TItem))
                                        ?? throw new ArgumentNullException(nameof(typePropertyAccessorCache));

            this.ViewModel = createItemFormViewModel ?? throw new ArgumentNullException(nameof(createItemFormViewModel));
        }
        public CreateItemRendererContext(
            ICreateItemFormViewModel <TModel> createItemFormViewModel,
            ITypePropertyAccessorCache typePropertyAccessorCache,
            CreateFormCssClasses createFormCssClasses)
        {
            this.typePropertyAccessor = typePropertyAccessorCache?.GetPropertyAccesor(typeof(TModel))
                                        ?? throw new ArgumentNullException(nameof(typePropertyAccessorCache));

            this.ViewModel            = createItemFormViewModel ?? throw new ArgumentNullException(nameof(createItemFormViewModel));
            this.CreateFormCssClasses = createFormCssClasses ?? new DefaultCreateFormCssClasses();
        }
예제 #4
0
        public ITableDataAdapter CreateCollectionTableDataAdapter(object selectedItem, PropertyInfo propertyInfo)
        {
            var propertyType        = propertyInfo.PropertyType.GenericTypeArguments[0];
            var propertyValueGetter = propertyValueAccessorCache.GetPropertyAccesor(selectedItem.GetType());
            var collectionValue     = propertyValueGetter.GetValue(selectedItem, propertyInfo.Name);

            var dataAdapterType = typeof(CollectionTableDataAdapter <>).MakeGenericType(propertyType);
            var dataAdapter     = Activator.CreateInstance(dataAdapterType,
                                                           new object[] { collectionValue }) as ITableDataAdapter;

            return(dataAdapter);
        }
예제 #5
0
        public IFormLayout <TModel> GetLayoutBuilder()
        {
            var modelType            = typeof(TModel);
            var typePropertyAccessor = _typePropertyAccessorCache.GetPropertyAccesor(modelType);
            var fieldsCount          = typePropertyAccessor.Properties.Count(p => p.CanWrite);

            if (MaximumFieldsForSingleColumnLayout >= fieldsCount)
            {
                return(new SingleColumnLayout <TModel>());
            }

            return(new TwoColumnsLayout <TModel>());
        }
예제 #6
0
        public CreateItemRendererContext(
            ICreateItemFormViewModel <TModel> createItemFormViewModel,
            ITypePropertyAccessorCache typePropertyAccessorCache,
            CreateFormCssClasses createFormCssClasses,
            IEntityType entityConfiguration)
        {
            _typePropertyAccessor = typePropertyAccessorCache?.GetPropertyAccesor(typeof(TModel))
                                    ?? throw new ArgumentNullException(nameof(typePropertyAccessorCache));

            ViewModel         = createItemFormViewModel ?? throw new ArgumentNullException(nameof(createItemFormViewModel));
            _annotationLookup = entityConfiguration.GetProperties()
                                .ToDictionary(p => p.Name, p => (INewItemAnnotations) new NewItemAnnotations(p));
            CreateFormCssClasses = createFormCssClasses ?? new DefaultCreateFormCssClasses();
        }
        public void Visit(ITableDataAdapter tableDataAdapter)
        {
            if (tableDataAdapter is ILazyLoadedTableDataAdapter lazyLoadedTableDataAdapter)
            {
                var selectedItemType = _masterDetailRowArguments.SelectedItem.GetType();

                var constantValue = _propertyValueAccessorCache
                                    .GetPropertyAccesor(selectedItemType)
                                    .GetValue(_masterDetailRowArguments.SelectedItem, _masterDetailRelationship.MasterDetailConnection.MasterPropertyName);

                lazyLoadedTableDataAdapter.AddRequestParamsAction = reqParams => reqParams
                                                                    .Add(_masterDetailRelationship.MasterDetailConnection.ForeignPropertyName, constantValue.ToString());
            }
        }
        public async Task <TItem> DeleteItem(TItem item, ILazyLoadingOptions lazyLoadingOptions)
        {
            if (string.IsNullOrWhiteSpace(lazyLoadingOptions.DeleteUri))
            {
                throw new ArgumentNullException($"When you are using {nameof(LazyTableDataSet<TItem>)} you must specify url for deleteing item. " +
                                                $"If you are using {nameof(LazyTableDataSet<TItem>)} as detail GridView you must configure url by calling method HasDeleteUrl");
            }

            var match = Regex.Match(lazyLoadingOptions.DeleteUri, DeleteUrlPattern);

            if (!match.Success)
            {
                throw new InvalidOperationException("The DeleteUri must contains {} with name of property with key value.");
            }

            var realDeleteUri = lazyLoadingOptions.DeleteUri;

            try
            {
                var keyPropertyNames      = match.Groups["prop"].Captures;
                var propertyValueAccessor = _propertyValueAccessorCache.GetPropertyAccesor(typeof(TItem));
                var query = new QueryBuilder();
                foreach (Capture keyPropertyName in keyPropertyNames)
                {
                    var keyValue = propertyValueAccessor.GetValue(item, keyPropertyName.Value);
                    query.Add(keyPropertyName.Value, keyValue.ToString());
                }
                realDeleteUri = Regex.Replace(lazyLoadingOptions.DeleteUri, DeleteUrlPattern, query.ToString());

                var response = await _httpClient.DeleteAsync(realDeleteUri);

                if (response.IsSuccessStatusCode)
                {
                    return(item);
                }

                return(null);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error during deleting item for uri [{realDeleteUri}]. Ex: {ex}");

                return(null);
            }
        }
예제 #9
0
        public void Visit(ITableDataAdapter tableDataAdapter)
        {
            if (tableDataAdapter is CollectionTableDataAdapter <TItem> collectionTableDataAdapter)
            {
                var selectedItemType      = masterDetailRowArguments.SelectedItem.GetType();
                var detailAdapterItemType = masterDetailRowArguments.DataAdapter.UnderlyingTypeOfItem;

                var constantValue = propertyValueAccessorCache
                                    .GetPropertyAccesor(selectedItemType)
                                    .GetValue(masterDetailRowArguments.SelectedItem, masterDetailRelationship.MasterDetailConnection.MasterPropertyName);

                var parameter = Expression.Parameter(detailAdapterItemType, "x");
                var member    = Expression.Property(parameter, masterDetailRelationship.MasterDetailConnection.ForeignPropertyName);
                var constant  = Expression.Constant(constantValue);
                var body      = Expression.Equal(member, constant);

                collectionTableDataAdapter.Filter = Expression.Lambda <Func <TItem, bool> >(body, parameter);;
            }
        }
예제 #10
0
        private ImutableGridRendererContext GetImutableGridRendererContext(Type dataSetItemType)
        {
            if (imutableRendererContextCache.TryGetValue(dataSetItemType, out var imutableGridRendererContext))
            {
                return(imutableGridRendererContext);
            }

            var gridConfiguration = GridConfigurationProvider.FindGridEntityConfigurationByType(dataSetItemType);

            propertyValueAccessorCache.AddPropertyAccessor(dataSetItemType, new TypeWrapper(dataSetItemType, logger));

            imutableGridRendererContext = new ImutableGridRendererContext(
                gridConfiguration,
                propertyValueAccessorCache.GetPropertyAccesor(dataSetItemType),
                currentUserPermission);

            imutableGridRendererContext.InitializeGridProperties(dataSetItemType.GetProperties().ToList());
            imutableRendererContextCache.Add(dataSetItemType, imutableGridRendererContext);

            return(imutableGridRendererContext);
        }