Beispiel #1
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            #region SeedData

            var detail1 = new Detail
            {
                Id               = 1,
                Name             = "Detail 1",
                CreationTime     = DateTime.Now.AddDays(-1),
                DetailTemplateId = 1
            };

            var detail2 = new Detail
            {
                Id               = 2,
                Name             = "Detail 2",
                CreationTime     = DateTime.Now.AddDays(-2),
                DetailTemplateId = 1
            };

            var detailTemplate = new DetailTemplate
            {
                Id             = 1,
                ProductionId   = 1,
                OutputDetailId = 2
            };
            var production = new Production
            {
                Id         = 1,
                CategoryId = 1,
                Name       = "Production1"
            };

            var cat1 = new Category
            {
                Id   = 1,
                Name = "Some category",
                Type = "Some type"
            };

            modelBuilder.Entity <Detail>().HasData(detail1, detail2);
            modelBuilder.Entity <DetailTemplate>().HasData(detailTemplate);
            modelBuilder.Entity <Production>().HasData(production);
            modelBuilder.Entity <Category>().HasData(cat1);

            #endregion
        }
Beispiel #2
0
        public override void VerifySettings()
        {
            base.VerifySettings();

            this.ThrowIfClassIsPresent("k-grid-rtl", Exceptions.Rtl);

            if (!IsClientBinding && Scrollable.Enabled && Scrollable.Virtual)
            {
                throw new NotSupportedException(Exceptions.CannotUseVirtualScrollWithServerBinding);
            }

            if (AutoBind.HasValue)
            {
                if (!IsClientBinding || (IsClientBinding && DataSource.Data != null))
                {
                    throw new NotSupportedException(Exceptions.CannotSetAutoBindIfBoundDuringInitialization);
                }
            }

            if (Columns.Any(c => c.Locked) && !IsClientBinding)
            {
                throw new NotSupportedException(Exceptions.CannotUseLockedColumnsAndServerBinding);
            }

            if (IsClientBinding)
            {
                if (Columns.OfType <IGridTemplateColumn <T> >().Where(c => c.Template != null && string.IsNullOrEmpty(c.ClientTemplate)).Any())
                {
                    throw new NotSupportedException(Exceptions.CannotUseTemplatesInAjaxOrWebService);
                }

                if (DetailTemplate != null && DetailTemplate.HasValue() && string.IsNullOrEmpty(ClientDetailTemplateId))
                {
                    throw new NotSupportedException(Exceptions.CannotUseTemplatesInAjaxOrWebService);
                }

                if (Columns.Any(c => c.Locked))
                {
                    if (DetailTemplate != null && DetailTemplate.HasValue() || ClientDetailTemplateId.HasValue())
                    {
                        throw new NotSupportedException(Exceptions.CannotUseDetailTemplateAndLockedColumns);
                    }

                    if (ClientRowTemplate.HasValue() || RowTemplate != null && RowTemplate.HasValue())
                    {
                        throw new NotSupportedException(Exceptions.CannotUseRowTemplateAndLockedColumns);
                    }
                }

                if (Columns.OfType <IGridActionColumn>().Any(c => c.Commands.OfType <GridCustomActionCommand <T> >().Any(command => command.HasValue())))
                {
                    throw new NotSupportedException(Exceptions.CustomCommandRoutesWithAjaxBinding);
                }
            }

            if (!DataKeys.Any() && (Editable.Enabled || (Selectable.Enabled && !IsClientBinding)))
            {
                throw new NotSupportedException(Exceptions.DataKeysEmpty);
            }

            if (Editable.Enabled)
            {
                if (DataSource.Type != DataSourceType.Custom)
                {
                    if (HasCommandOfType <GridEditActionCommand>())
                    {
                        if (!DataSource.Transport.Update.HasValue())
                        {
                            throw new NotSupportedException(Exceptions.EditCommandRequiresUpdate);
                        }
                    }

                    if (HasCommandOfType <GridDestroyActionCommand>())
                    {
                        if (!DataSource.Transport.Destroy.HasValue() && Editable.Mode != GridEditMode.InCell)
                        {
                            throw new NotSupportedException(Exceptions.DeleteCommandRequiresDelete);
                        }
                    }

                    if (HasCommandOfType <GridToolBarCreateCommand <T> >())
                    {
                        if (!DataSource.Transport.Create.HasValue() && Editable.Mode != GridEditMode.InCell)
                        {
                            throw new NotSupportedException(Exceptions.InsertCommandRequiresInsert);
                        }
                    }
                }

                if (HasCommandOfType <GridToolBarSaveCommand <T> >())
                {
                    if (Editable.Mode != GridEditMode.InCell)
                    {
                        throw new NotSupportedException(Exceptions.BatchUpdatesRequireInCellMode);
                    }

                    if (DataSource.Type != DataSourceType.Custom)
                    {
                        if (!DataSource.Transport.Update.HasValue())
                        {
                            throw new NotSupportedException(Exceptions.BatchUpdatesRequireUpdate);
                        }
                    }
                }

                if (Editable.Mode == GridEditMode.InCell)
                {
                    if (!IsClientBinding)
                    {
                        throw new NotSupportedException(Exceptions.InCellModeNotSupportedInServerBinding);
                    }

                    if (ClientRowTemplate.HasValue() || ClientAltRowTemplate.HasValue() || RowTemplate.HasValue())
                    {
                        throw new NotSupportedException(Exceptions.InCellModeNotSupportedWithRowTemplate);
                    }
                }

                if (typeof(T) == typeof(System.Data.DataRowView) && Editable.Mode == GridEditMode.InLine &&
                    Columns.OfType <IGridBoundColumn>().Where(c => c.EditorTemplateName.HasValue()).Any())
                {
                    throw new NotSupportedException(Exceptions.DataTableInLineEditingWithCustomEditorTemplates);
                }

                if (typeof(T) == typeof(System.Data.DataRowView) && Editable.Mode == GridEditMode.PopUp &&
                    !Editable.TemplateName.HasValue())
                {
                    throw new NotSupportedException(Exceptions.DataTablePopUpTemplate);
                }
            }
        }