Skip to content

Commit

Permalink
Merge pull request #9504 from abpframework/auto-merge/rel-4-4/466
Browse files Browse the repository at this point in the history
Merge branch dev with rel-4.4
  • Loading branch information
mehmet-erim committed Jul 5, 2021
2 parents 240f725 + 2138217 commit dcb2cb5
Show file tree
Hide file tree
Showing 16 changed files with 111 additions and 90 deletions.
28 changes: 18 additions & 10 deletions docs/en/Tutorials/Part-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,28 +142,36 @@ public class BookStoreMongoDbContext : AbpMongoDbContext

### Map the Book Entity to a Database Table

Open `BookStoreDbContextModelCreatingExtensions.cs` file in the `Acme.BookStore.EntityFrameworkCore` project and add the mapping code for the `Book` entity. The final class should be the following:
Locate to `OnModelCreating` method in the `BookStoreDbContext` class and add the mapping code for the `Book` entity:

````csharp
using Acme.BookStore.Books;
using Microsoft.EntityFrameworkCore;
using Volo.Abp;
using Volo.Abp.EntityFrameworkCore.Modeling;
...

namespace Acme.BookStore.EntityFrameworkCore
{
public static class BookStoreDbContextModelCreatingExtensions
public class BookStoreDbContext :
AbpDbContext<BookStoreDbContext>,
IIdentityDbContext,
ITenantManagementDbContext
{
public static void ConfigureBookStore(this ModelBuilder builder)
...

protected override void OnModelCreating(ModelBuilder builder)
{
Check.NotNull(builder, nameof(builder));
base.OnModelCreating(builder);

/* Include modules to your migration db context */

builder.ConfigurePermissionManagement();
...

/* Configure your own tables/entities inside here */

builder.Entity<Book>(b =>
{
b.ToTable(BookStoreConsts.DbTablePrefix + "Books",
BookStoreConsts.DbSchema);
BookStoreConsts.DbSchema);
b.ConfigureByConvention(); //auto configure for the base class props
b.Property(x => x.Name).IsRequired().HasMaxLength(128);
});
Expand All @@ -179,7 +187,7 @@ namespace Acme.BookStore.EntityFrameworkCore

The startup solution is configured to use [Entity Framework Core Code First Migrations](https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/). Since we've changed the database mapping configuration, we should create a new migration and apply changes to the database.

Open a command-line terminal in the directory of the `Acme.BookStore.EntityFrameworkCore.DbMigrations` project and type the following command:
Open a command-line terminal in the directory of the `Acme.BookStore.EntityFrameworkCore` project and type the following command:

```bash
dotnet ef migrations add Created_Book_Entity
Expand All @@ -189,7 +197,7 @@ This will add a new migration class to the project:

![bookstore-efcore-migration](./images/bookstore-efcore-migration.png)

> If you are using Visual Studio, you may want to use `Add-Migration Created_Book_Entity -c BookStoreMigrationsDbContext` and `Update-Database -c BookStoreMigrationsDbContext` commands in the *Package Manager Console (PMC)*. In this case, ensure that {{if UI=="MVC"}}`Acme.BookStore.Web`{{else if UI=="BlazorServer"}}`Acme.BookStore.Blazor`{{else if UI=="Blazor" || UI=="NG"}}`Acme.BookStore.HttpApi.Host`{{end}} is the startup project and `Acme.BookStore.EntityFrameworkCore.DbMigrations` is the *Default Project* in PMC.
> If you are using Visual Studio, you may want to use `Add-Migration Created_Book_Entity -c BookStoreMigrationsDbContext` and `Update-Database -c BookStoreMigrationsDbContext` commands in the *Package Manager Console (PMC)*. In this case, ensure that {{if UI=="MVC"}}`Acme.BookStore.Web`{{else if UI=="BlazorServer"}}`Acme.BookStore.Blazor`{{else if UI=="Blazor" || UI=="NG"}}`Acme.BookStore.HttpApi.Host`{{end}} is the startup project and `Acme.BookStore.EntityFrameworkCore` is the *Default Project* in PMC.
{{end}}

Expand Down
6 changes: 3 additions & 3 deletions docs/en/Tutorials/Part-10.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ We prefer to **delete the database** {{if DB=="EF"}}(you can run the `Drop-Datab

### Update the EF Core Mapping

Open the `BookStoreDbContextModelCreatingExtensions` class under the `EntityFrameworkCore` folder of the `Acme.BookStore.EntityFrameworkCore` project and change the `builder.Entity<Book>` part as shown below:
Locate to `OnModelCreating` method in the `BookStoreDbContext` class that under the `EntityFrameworkCore` folder of the `Acme.BookStore.EntityFrameworkCore` project and change the `builder.Entity<Book>` part as shown below:

````csharp
builder.Entity<Book>(b =>
Expand All @@ -88,7 +88,7 @@ builder.Entity<Book>(b =>

The startup solution is configured to use [Entity Framework Core Code First Migrations](https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/). Since we've changed the database mapping configuration, we should create a new migration and apply changes to the database.

Open a command-line terminal in the directory of the `Acme.BookStore.EntityFrameworkCore.DbMigrations` project and type the following command:
Open a command-line terminal in the directory of the `Acme.BookStore.EntityFrameworkCore` project and type the following command:

````bash
dotnet ef migrations add Added_AuthorId_To_Book
Expand Down Expand Up @@ -121,7 +121,7 @@ migrationBuilder.AddForeignKey(
* Creates an index on the `AuthorId` field.
* Declares the foreign key to the `AppAuthors` table.

> If you are using Visual Studio, you may want to use `Add-Migration Added_AuthorId_To_Book -c BookStoreMigrationsDbContext` and `Update-Database -c BookStoreMigrationsDbContext` commands in the *Package Manager Console (PMC)*. In this case, ensure that {{if UI=="MVC"}}`Acme.BookStore.Web`{{else if UI=="BlazorServer"}}`Acme.BookStore.Blazor`{{else if UI=="Blazor" || UI=="NG"}}`Acme.BookStore.HttpApi.Host`{{end}} is the startup project and `Acme.BookStore.EntityFrameworkCore.DbMigrations` is the *Default Project* in PMC.
> If you are using Visual Studio, you may want to use `Add-Migration Added_AuthorId_To_Book -c BookStoreMigrationsDbContext` and `Update-Database -c BookStoreMigrationsDbContext` commands in the *Package Manager Console (PMC)*. In this case, ensure that {{if UI=="MVC"}}`Acme.BookStore.Web`{{else if UI=="BlazorServer"}}`Acme.BookStore.Blazor`{{else if UI=="Blazor" || UI=="NG"}}`Acme.BookStore.HttpApi.Host`{{end}} is the startup project and `Acme.BookStore.EntityFrameworkCore` is the *Default Project* in PMC.
{{end}}

Expand Down
6 changes: 3 additions & 3 deletions docs/en/Tutorials/Part-7.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Open the `BookStoreDbContext` in the `Acme.BookStore.EntityFrameworkCore` projec
public DbSet<Author> Authors { get; set; }
````

Then open the `BookStoreDbContextModelCreatingExtensions` class in the same project and add the following lines to the end of the `ConfigureBookStore` method:
Then locate to the `OnModelCreating` method in `BookStoreDbContext` class in the same project and add the following lines to the end of the method:

````csharp
builder.Entity<Author>(b =>
Expand All @@ -72,7 +72,7 @@ This is just like done for the `Book` entity before, so no need to explain again

The startup solution is configured to use [Entity Framework Core Code First Migrations](https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/). Since we've changed the database mapping configuration, we should create a new migration and apply changes to the database.

Open a command-line terminal in the directory of the `Acme.BookStore.EntityFrameworkCore.DbMigrations` project and type the following command:
Open a command-line terminal in the directory of the `Acme.BookStore.EntityFrameworkCore` project and type the following command:

````bash
dotnet ef migrations add Added_Authors
Expand All @@ -88,7 +88,7 @@ You can apply changes to the database using the following command, in the same c
dotnet ef database update
````

> If you are using Visual Studio, you may want to use `Add-Migration Added_Authors -c BookStoreMigrationsDbContext` and `Update-Database -c BookStoreMigrationsDbContext` commands in the *Package Manager Console (PMC)*. In this case, ensure that {{if UI=="MVC"}}`Acme.BookStore.Web`{{else if UI=="BlazorServer"}}`Acme.BookStore.Blazor`{{else if UI=="Blazor" || UI=="NG"}}`Acme.BookStore.HttpApi.Host`{{end}} is the startup project and `Acme.BookStore.EntityFrameworkCore.DbMigrations` is the *Default Project* in PMC.
> If you are using Visual Studio, you may want to use `Add-Migration Added_Authors -c BookStoreMigrationsDbContext` and `Update-Database -c BookStoreMigrationsDbContext` commands in the *Package Manager Console (PMC)*. In this case, ensure that {{if UI=="MVC"}}`Acme.BookStore.Web`{{else if UI=="BlazorServer"}}`Acme.BookStore.Blazor`{{else if UI=="Blazor" || UI=="NG"}}`Acme.BookStore.HttpApi.Host`{{end}} is the startup project and `Acme.BookStore.EntityFrameworkCore` is the *Default Project* in PMC.
{{else if DB=="Mongo"}}

Expand Down
Binary file modified docs/en/Tutorials/images/bookstore-efcore-migration-authors.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/en/Tutorials/images/bookstore-efcore-migration.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using Microsoft.AspNetCore.Authorization;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Data;
using Volo.Abp.EventBus.Distributed;
using Volo.Abp.MultiTenancy;
using Volo.Abp.ObjectExtending;

namespace Volo.Abp.TenantManagement
Expand All @@ -14,15 +16,18 @@ public class TenantAppService : TenantManagementAppServiceBase, ITenantAppServic
protected IDataSeeder DataSeeder { get; }
protected ITenantRepository TenantRepository { get; }
protected ITenantManager TenantManager { get; }
protected IDistributedEventBus DistributedEventBus { get; }

public TenantAppService(
ITenantRepository tenantRepository,
ITenantManager tenantManager,
IDataSeeder dataSeeder)
IDataSeeder dataSeeder,
IDistributedEventBus distributedEventBus)
{
DataSeeder = dataSeeder;
TenantRepository = tenantRepository;
TenantManager = tenantManager;
DistributedEventBus = distributedEventBus;
}

public virtual async Task<TenantDto> GetAsync(Guid id)
Expand Down Expand Up @@ -63,10 +68,22 @@ public virtual async Task<TenantDto> CreateAsync(TenantCreateDto input)

await CurrentUnitOfWork.SaveChangesAsync();

await DistributedEventBus.PublishAsync(
new TenantCreatedEto
{
Id = tenant.Id,
Name = tenant.Name,
Properties =
{
{ "AdminEmail", input.AdminEmailAddress },
{ "AdminPassword", input.AdminPassword }
}
});

using (CurrentTenant.Change(tenant.Id, tenant.Name))
{
//TODO: Handle database creation?

// TODO: Seeder might be triggered via event handler.
await DataSeeder.SeedAsync(
new DataSeedContext(tenant.Id)
.WithProperty("AdminEmail", input.AdminEmailAddress)
Expand Down
6 changes: 1 addition & 5 deletions npm/ng-packs/apps/dev-app/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,14 @@ import { ThemeSharedModule } from '@abp/ng.theme.shared';
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { InspectorModule } from '@ngneat/inspector';
import { NgxsLoggerPluginModule } from '@ngxs/logger-plugin';
import { NgxsModule } from '@ngxs/store';
import { environment } from '../environments/environment';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { APP_ROUTE_PROVIDER } from './route.provider';

const INSPECTION_TOOLS = [
NgxsLoggerPluginModule.forRoot({ disabled: true }),
InspectorModule.forRoot(),
];
const INSPECTION_TOOLS = [NgxsLoggerPluginModule.forRoot({ disabled: true })];

@NgModule({
imports: [
Expand Down
2 changes: 1 addition & 1 deletion npm/ng-packs/apps/dev-app/src/app/home/home.component.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="container">
<div class="p-5 text-center">
<div class="badge badge-success h5 rounded mb-4" role="alert">
<div class="d-inline-block bg-success text-white p-1 h5 rounded mb-4" role="alert">
<h5 class="m-1">
<i class="fas fa-rocket"></i> Congratulations, <strong>MyProjectName</strong> is
successfully running!
Expand Down
4 changes: 2 additions & 2 deletions npm/ng-packs/apps/dev-app/src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export const environment = {
clientId: 'MyProjectName_App',
dummyClientSecret: '1q2w3e*',
scope: 'offline_access MyProjectName',
// responseType: 'code',
// redirectUri: baseUrl
responseType: 'code',
redirectUri: baseUrl,
},
apis: {
default: {
Expand Down
1 change: 0 additions & 1 deletion npm/ng-packs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
"@angular/router": "~11.1.0",
"@fortawesome/fontawesome-free": "^5.14.0",
"@ng-bootstrap/ng-bootstrap": "^7.0.0",
"@ngneat/inspector": "^1.0.0",
"@ngneat/spectator": "^5.13.0",
"@ngx-validate/core": "^0.0.13",
"@ngxs/devtools-plugin": "^3.7.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-12 col-md-3">
<div class="col-12 col-md-3 mb-2 mb-md-0">
<ul class="nav flex-column nav-pills" id="nav-tab" role="tablist">
<ng-container *abpFor="let setting of settings; trackBy: trackByFn">
<li
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="row justify-content-end mx-n1" id="AbpContentToolbar">
<div class="col-auto px-1 pt-2" *ngFor="let action of actionList; trackBy: trackByFn">
<div class="col-auto px-1 pt-0 pt-md-2" *ngFor="let action of actionList; trackBy: trackByFn">
<ng-container *ngIf="action.visible(data)">
<ng-container *abpPermission="action.permission">
<ng-container *ngIf="action.component as component; else button">
Expand Down

0 comments on commit dcb2cb5

Please sign in to comment.