Exemplo n.º 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env,
                              DataContext context, UserManager <User> userManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                app.UseHsts();
            }

            app.UseMiddleware <ApiDiagnosticsMiddleware>();
            app.UseCors();
            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseAuthentication();

            ModelBuilderExtensions.Seed(context, userManager);

            app.UseMvc();
        }
Exemplo n.º 2
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            new GameConfig(modelBuilder.Entity <Game>());

            ///seed
            ModelBuilderExtensions.Seed(modelBuilder);
        }
Exemplo n.º 3
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            //Seeden
            _modelBuilder = modelBuilder;
            base.OnModelCreating(_modelBuilder);

            ModelBuilderExtensions.modelBuilder = _modelBuilder;
            ModelBuilderExtensions.Seed();
        }
Exemplo n.º 4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, DataContext dataContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                ModelBuilderExtensions.Seed(dataContext);
            }

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Exemplo n.º 5
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            _modelBuilder = modelBuilder;
            base.OnModelCreating(_modelBuilder);


            //modelBuilder.Entity<MovieRoom>().HasKey(mr => new { mr.MovieID, mr.RoomID});


            //default veel op veel is cascade delete!
            foreach (var relationship in modelBuilder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys()))
            {
                relationship.DeleteBehavior = DeleteBehavior.Restrict;
            }

            ModelBuilderExtensions.modelBuilder = _modelBuilder;

            ModelBuilderExtensions.Seed();
        }
Exemplo n.º 6
0
    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity <Invoice>()
        .HasMany(p => p.InvoiceDetails)
        .WithOne(d => d.Invoice).OnDelete(DeleteBehavior.Restrict);
        modelBuilder.Entity <Language>().HasIndex(x => x.Code).IsUnique();
        modelBuilder.Entity <Language>().HasKey(x => x.Code).HasName("Code");
        modelBuilder.Entity <Product>()
        .HasMany(p => p.Taxes)
        .WithOne(d => d.Product).OnDelete(DeleteBehavior.Restrict);

        modelBuilder.Entity <Product>()
        .HasMany(p => p.ProductUnits)
        .WithOne(d => d.Product).OnDelete(DeleteBehavior.Restrict);

        modelBuilder.Entity <Product>()
        .HasMany(p => p.BaseCompositeProducts)
        .WithOne(d => d.Product).OnDelete(DeleteBehavior.Restrict);

        modelBuilder.Entity <User>().Property(x => x.UserId).HasDefaultValueSql("NEWID()");

        modelBuilder.Entity <LanguageKey>().HasKey(o => new { o.LanguageCode, o.Key });


        foreach (var property in modelBuilder.Model.GetEntityTypes()
                 .SelectMany(t => t.GetProperties())
                 .Where(p => p.ClrType == typeof(decimal)))
        {
            property.SetColumnType("decimal(18, 2)");
        }

        var cascadeFKs = modelBuilder.Model.GetEntityTypes().SelectMany(t => t.GetForeignKeys())
                         .Where(fk => !fk.IsOwnership && fk.DeleteBehavior == DeleteBehavior.Cascade);

        foreach (var fk in cascadeFKs)
        {
            fk.DeleteBehavior = DeleteBehavior.Restrict;
        }
        ModelBuilderExtensions.Seed(modelBuilder);
        base.OnModelCreating(modelBuilder);
    }
Exemplo n.º 7
0
    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity <Invoice>()
        .HasMany(p => p.InvoiceLeads)
        .WithOne(d => d.Invoice).OnDelete(DeleteBehavior.Restrict);

        modelBuilder.Entity <InvoiceLead>()
        .HasMany(p => p.LeadDetails)
        .WithOne(d => d.Lead).OnDelete(DeleteBehavior.NoAction);

        modelBuilder.Entity <Invoice>()
        .HasMany(p => p.InvoiceDetails)
        .WithOne(d => d.Invoice).OnDelete(DeleteBehavior.Restrict);

        modelBuilder.Entity <InvoiceDetail>()
        .HasOne(p => p.Invoice)
        .WithMany(d => d.InvoiceDetails).OnDelete(DeleteBehavior.NoAction);

        modelBuilder.Entity <Section>()
        .HasMany(p => p.Operations)
        .WithOne(d => d.Section).OnDelete(DeleteBehavior.Restrict);

        modelBuilder.Entity <Role>()
        .HasMany(p => p.SectionOperations)
        .WithOne(d => d.Role).OnDelete(DeleteBehavior.Restrict);


        modelBuilder.Entity <Language>().HasIndex(x => x.Code).IsUnique();
        modelBuilder.Entity <Language>().HasKey(x => x.Code).HasName("Code");
        modelBuilder.Entity <Product>()
        .HasMany(p => p.Taxes)
        .WithOne(d => d.Product).OnDelete(DeleteBehavior.Restrict);

        modelBuilder.Entity <BranchOffice>()
        .HasMany(x => x.Warehouses)
        .WithOne(x => x.BranchOffice)
        .OnDelete(DeleteBehavior.Restrict);

        modelBuilder.Entity <CashRegisterOpening>()
        .HasMany(x => x.Details)
        .WithOne(x => x.CashRegisterOpening)
        .OnDelete(DeleteBehavior.Restrict);

        modelBuilder.Entity <CashRegisterOpeningDetail>()
        .HasOne(x => x.CashRegisterOpening)
        .WithMany(x => x.Details)
        .OnDelete(DeleteBehavior.NoAction);

        modelBuilder.Entity <BranchOffice>()
        .HasMany(x => x.CashRegisters)
        .WithOne(x => x.BranchOffice)
        .OnDelete(DeleteBehavior.Restrict);

        modelBuilder.Entity <BranchOffice>()
        .HasMany(x => x.Users)
        .WithOne(x => x.BranchOffice)
        .OnDelete(DeleteBehavior.Restrict);

        modelBuilder.Entity <PaymentType>()
        .HasMany(x => x.ExpensesPayments)
        .WithOne(x => x.PaymentType)
        .OnDelete(DeleteBehavior.Restrict);

        modelBuilder.Entity <PaymentType>()
        .HasMany(x => x.Expenses)
        .WithOne(x => x.PaymentType)
        .OnDelete(DeleteBehavior.Restrict);

        modelBuilder.Entity <PaymentType>()
        .HasMany(x => x.InvoicesPayments)
        .WithOne(x => x.PaymentType)
        .OnDelete(DeleteBehavior.Restrict);

        modelBuilder.Entity <User>()
        .HasMany(x => x.CashRegisterOpeningClosings)
        .WithOne(x => x.User)
        .OnDelete(DeleteBehavior.Restrict);


        modelBuilder.Entity <CompositeProduct>()
        .HasOne(x => x.UnitProductEquivalence)
        .WithMany(y => y.CompositeProducts)
        .OnDelete(DeleteBehavior.SetNull);

        modelBuilder.Entity <Expense>()
        .HasOne(x => x.PaymentType)
        .WithMany(y => y.Expenses)
        .OnDelete(DeleteBehavior.Restrict);

        modelBuilder.Entity <ExpensesPayment>()
        .HasOne(x => x.PaymentType)
        .WithMany(y => y.ExpensesPayments)
        .OnDelete(DeleteBehavior.Restrict);

        modelBuilder.Entity <Payment>()
        .HasOne(x => x.PaymentType)
        .WithMany(y => y.InvoicesPayments)
        .OnDelete(DeleteBehavior.Restrict);

        modelBuilder.Entity <Warehouse>()
        .HasOne(x => x.BranchOffice)
        .WithMany(x => x.Warehouses);

        modelBuilder.Entity <SectionOperation>()
        .HasOne(x => x.Section)
        .WithMany(x => x.Operations)
        .OnDelete(DeleteBehavior.NoAction);

        modelBuilder.Entity <SectionOperation>()
        .HasOne(x => x.Operation)
        .WithMany(x => x.Sections)
        .OnDelete(DeleteBehavior.NoAction);

        modelBuilder.Entity <Product>()
        .HasMany(p => p.ProductUnits)
        .WithOne(d => d.Product).OnDelete(DeleteBehavior.Restrict);

        modelBuilder.Entity <Product>()
        .HasMany(p => p.BaseCompositeProducts)
        .WithOne(d => d.Product).OnDelete(DeleteBehavior.Restrict);

        modelBuilder.Entity <Product>()
        .HasMany(p => p.Taxes)
        .WithOne(d => d.Product).OnDelete(DeleteBehavior.Restrict);

        modelBuilder.Entity <Product>()
        .HasMany(p => p.SuppliersCosts)
        .WithOne(d => d.Product).OnDelete(DeleteBehavior.Restrict);

        modelBuilder.Entity <Supplier>()
        .HasMany(p => p.ProductsCosts)
        .WithOne(d => d.Supplier).OnDelete(DeleteBehavior.Restrict);

        modelBuilder.Entity <User>().Property(x => x.UserId).HasDefaultValueSql("NEWID()");

        modelBuilder.Entity <LanguageKey>().HasKey(o => new { o.LanguageCode, o.Key });
        modelBuilder.Entity <Section>().HasMany(x => x.Operations).WithOne(x => x.Section).OnDelete(DeleteBehavior.Restrict);
        modelBuilder.Entity <Operation>().HasMany(x => x.Sections).WithOne(x => x.Operation).OnDelete(DeleteBehavior.Restrict);
        modelBuilder.Entity <SectionOperation>().HasOne(y => y.Operation).WithMany(y => y.Sections).OnDelete(DeleteBehavior.Cascade);
        modelBuilder.Entity <SectionOperation>().HasOne(y => y.Section).WithMany(x => x.Operations).OnDelete(DeleteBehavior.Cascade);


        foreach (var property in modelBuilder.Model.GetEntityTypes()
                 .SelectMany(t => t.GetProperties())
                 .Where(p => p.ClrType == typeof(decimal)))
        {
            property.SetColumnType("decimal(18, 2)");
        }

        var cascadeFKs = modelBuilder.Model.GetEntityTypes().SelectMany(t => t.GetForeignKeys())
                         .Where(fk => !fk.IsOwnership && fk.DeleteBehavior == DeleteBehavior.Cascade);

        foreach (var fk in cascadeFKs)
        {
            fk.DeleteBehavior = DeleteBehavior.Restrict;
        }
        ModelBuilderExtensions.Seed(modelBuilder);
        base.OnModelCreating(modelBuilder);
    }