@@ -1,8 +1,6 @@
|
|||||||
using System;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
using Microsoft.eShopWeb.ApplicationCore.Entities;
|
using Microsoft.eShopWeb.ApplicationCore.Entities;
|
||||||
using Microsoft.EntityFrameworkCore.Metadata;
|
|
||||||
using ApplicationCore.Entities.OrderAggregate;
|
using ApplicationCore.Entities.OrderAggregate;
|
||||||
|
|
||||||
namespace Infrastructure.Data
|
namespace Infrastructure.Data
|
||||||
@@ -105,6 +103,5 @@ namespace Infrastructure.Data
|
|||||||
{
|
{
|
||||||
builder.OwnsOne(i => i.ItemOrdered);
|
builder.OwnsOne(i => i.ItemOrdered);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,7 @@ namespace Infrastructure.Data
|
|||||||
{
|
{
|
||||||
public class CatalogContextSeed
|
public class CatalogContextSeed
|
||||||
{
|
{
|
||||||
public static async Task SeedAsync(IApplicationBuilder applicationBuilder,
|
public static async Task SeedAsync(CatalogContext catalogContext,
|
||||||
CatalogContext catalogContext,
|
|
||||||
ILoggerFactory loggerFactory, int? retry = 0)
|
ILoggerFactory loggerFactory, int? retry = 0)
|
||||||
{
|
{
|
||||||
int retryForAvailability = retry.Value;
|
int retryForAvailability = retry.Value;
|
||||||
@@ -51,7 +50,7 @@ namespace Infrastructure.Data
|
|||||||
retryForAvailability++;
|
retryForAvailability++;
|
||||||
var log = loggerFactory.CreateLogger<CatalogContextSeed>();
|
var log = loggerFactory.CreateLogger<CatalogContextSeed>();
|
||||||
log.LogError(ex.Message);
|
log.LogError(ex.Message);
|
||||||
await SeedAsync(applicationBuilder, catalogContext, loggerFactory, retryForAvailability);
|
await SeedAsync(catalogContext, loggerFactory, retryForAvailability);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,155 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
using Microsoft.EntityFrameworkCore.Metadata;
|
|
||||||
|
|
||||||
namespace Infrastructure.Data.Migrations
|
|
||||||
{
|
|
||||||
public partial class InitialModel : Migration
|
|
||||||
{
|
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
migrationBuilder.CreateSequence(
|
|
||||||
name: "catalog_brand_hilo",
|
|
||||||
incrementBy: 10);
|
|
||||||
|
|
||||||
migrationBuilder.CreateSequence(
|
|
||||||
name: "catalog_hilo",
|
|
||||||
incrementBy: 10);
|
|
||||||
|
|
||||||
migrationBuilder.CreateSequence(
|
|
||||||
name: "catalog_type_hilo",
|
|
||||||
incrementBy: 10);
|
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "Baskets",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
Id = table.Column<int>(nullable: false)
|
|
||||||
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
|
|
||||||
BuyerId = table.Column<string>(nullable: true)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_Baskets", x => x.Id);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "CatalogBrand",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
Id = table.Column<int>(nullable: false),
|
|
||||||
Brand = table.Column<string>(maxLength: 100, nullable: false)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_CatalogBrand", x => x.Id);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "CatalogType",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
Id = table.Column<int>(nullable: false),
|
|
||||||
Type = table.Column<string>(maxLength: 100, nullable: false)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_CatalogType", x => x.Id);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "BasketItem",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
Id = table.Column<int>(nullable: false)
|
|
||||||
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
|
|
||||||
BasketId = table.Column<int>(nullable: true),
|
|
||||||
CatalogItemId = table.Column<int>(nullable: false),
|
|
||||||
Quantity = table.Column<int>(nullable: false),
|
|
||||||
UnitPrice = table.Column<decimal>(nullable: false)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_BasketItem", x => x.Id);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_BasketItem_Baskets_BasketId",
|
|
||||||
column: x => x.BasketId,
|
|
||||||
principalTable: "Baskets",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Restrict);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "Catalog",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
Id = table.Column<int>(nullable: false),
|
|
||||||
CatalogBrandId = table.Column<int>(nullable: false),
|
|
||||||
CatalogTypeId = table.Column<int>(nullable: false),
|
|
||||||
Description = table.Column<string>(nullable: true),
|
|
||||||
Name = table.Column<string>(maxLength: 50, nullable: false),
|
|
||||||
PictureUri = table.Column<string>(nullable: true),
|
|
||||||
Price = table.Column<decimal>(nullable: false)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_Catalog", x => x.Id);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_Catalog_CatalogBrand_CatalogBrandId",
|
|
||||||
column: x => x.CatalogBrandId,
|
|
||||||
principalTable: "CatalogBrand",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_Catalog_CatalogType_CatalogTypeId",
|
|
||||||
column: x => x.CatalogTypeId,
|
|
||||||
principalTable: "CatalogType",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_BasketItem_BasketId",
|
|
||||||
table: "BasketItem",
|
|
||||||
column: "BasketId");
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_Catalog_CatalogBrandId",
|
|
||||||
table: "Catalog",
|
|
||||||
column: "CatalogBrandId");
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_Catalog_CatalogTypeId",
|
|
||||||
table: "Catalog",
|
|
||||||
column: "CatalogTypeId");
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "BasketItem");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "Catalog");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "Baskets");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "CatalogBrand");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "CatalogType");
|
|
||||||
|
|
||||||
migrationBuilder.DropSequence(
|
|
||||||
name: "catalog_brand_hilo");
|
|
||||||
|
|
||||||
migrationBuilder.DropSequence(
|
|
||||||
name: "catalog_hilo");
|
|
||||||
|
|
||||||
migrationBuilder.DropSequence(
|
|
||||||
name: "catalog_type_hilo");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +1,61 @@
|
|||||||
using System;
|
// <auto-generated />
|
||||||
|
using Infrastructure.Data;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore.Metadata;
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
using Infrastructure.Data;
|
using Microsoft.EntityFrameworkCore.Storage;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.Internal;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace Infrastructure.Data.Migrations
|
namespace Infrastructure.Data.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(CatalogContext))]
|
[DbContext(typeof(CatalogContext))]
|
||||||
[Migration("20170822214048_InitialModel")]
|
[Migration("20171018175735_Initial")]
|
||||||
partial class InitialModel
|
partial class Initial
|
||||||
{
|
{
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
modelBuilder
|
modelBuilder
|
||||||
.HasAnnotation("ProductVersion", "1.1.2")
|
.HasAnnotation("ProductVersion", "2.0.0-rtm-26452")
|
||||||
.HasAnnotation("SqlServer:Sequence:.catalog_brand_hilo", "'catalog_brand_hilo', '', '1', '10', '', '', 'Int64', 'False'")
|
.HasAnnotation("Relational:Sequence:.catalog_brand_hilo", "'catalog_brand_hilo', '', '1', '10', '', '', 'Int64', 'False'")
|
||||||
.HasAnnotation("SqlServer:Sequence:.catalog_hilo", "'catalog_hilo', '', '1', '10', '', '', 'Int64', 'False'")
|
.HasAnnotation("Relational:Sequence:.catalog_hilo", "'catalog_hilo', '', '1', '10', '', '', 'Int64', 'False'")
|
||||||
.HasAnnotation("SqlServer:Sequence:.catalog_type_hilo", "'catalog_type_hilo', '', '1', '10', '', '', 'Int64', 'False'")
|
.HasAnnotation("Relational:Sequence:.catalog_type_hilo", "'catalog_type_hilo', '', '1', '10', '', '', 'Int64', 'False'")
|
||||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||||
|
|
||||||
|
modelBuilder.Entity("ApplicationCore.Entities.OrderAggregate.Order", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<string>("BuyerId");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("OrderDate");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ApplicationCore.Entities.OrderAggregate.OrderItem", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<int?>("OrderId");
|
||||||
|
|
||||||
|
b.Property<decimal>("UnitPrice");
|
||||||
|
|
||||||
|
b.Property<int>("Units");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("OrderId");
|
||||||
|
|
||||||
|
b.ToTable("OrderItems");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.Basket", b =>
|
modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.Basket", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@@ -114,6 +150,56 @@ namespace Infrastructure.Data.Migrations
|
|||||||
b.ToTable("CatalogType");
|
b.ToTable("CatalogType");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ApplicationCore.Entities.OrderAggregate.Order", b =>
|
||||||
|
{
|
||||||
|
b.OwnsOne("ApplicationCore.Entities.OrderAggregate.Address", "ShipToAddress", b1 =>
|
||||||
|
{
|
||||||
|
b1.Property<int>("OrderId");
|
||||||
|
|
||||||
|
b1.Property<string>("City");
|
||||||
|
|
||||||
|
b1.Property<string>("Country");
|
||||||
|
|
||||||
|
b1.Property<string>("State");
|
||||||
|
|
||||||
|
b1.Property<string>("Street");
|
||||||
|
|
||||||
|
b1.Property<string>("ZipCode");
|
||||||
|
|
||||||
|
b1.ToTable("Orders");
|
||||||
|
|
||||||
|
b1.HasOne("ApplicationCore.Entities.OrderAggregate.Order")
|
||||||
|
.WithOne("ShipToAddress")
|
||||||
|
.HasForeignKey("ApplicationCore.Entities.OrderAggregate.Address", "OrderId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ApplicationCore.Entities.OrderAggregate.OrderItem", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("ApplicationCore.Entities.OrderAggregate.Order")
|
||||||
|
.WithMany("OrderItems")
|
||||||
|
.HasForeignKey("OrderId");
|
||||||
|
|
||||||
|
b.OwnsOne("ApplicationCore.Entities.OrderAggregate.CatalogItemOrdered", "ItemOrdered", b1 =>
|
||||||
|
{
|
||||||
|
b1.Property<int>("OrderItemId");
|
||||||
|
|
||||||
|
b1.Property<int>("CatalogItemId");
|
||||||
|
|
||||||
|
b1.Property<string>("PictureUri");
|
||||||
|
|
||||||
|
b1.Property<string>("ProductName");
|
||||||
|
|
||||||
|
b1.ToTable("OrderItems");
|
||||||
|
|
||||||
|
b1.HasOne("ApplicationCore.Entities.OrderAggregate.OrderItem")
|
||||||
|
.WithOne("ItemOrdered")
|
||||||
|
.HasForeignKey("ApplicationCore.Entities.OrderAggregate.CatalogItemOrdered", "OrderItemId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.BasketItem", b =>
|
modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.BasketItem", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.Basket")
|
b.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.Basket")
|
||||||
@@ -133,6 +219,7 @@ namespace Infrastructure.Data.Migrations
|
|||||||
.HasForeignKey("CatalogTypeId")
|
.HasForeignKey("CatalogTypeId")
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
});
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
209
src/Infrastructure/Data/Migrations/20171018175735_Initial.cs
Normal file
209
src/Infrastructure/Data/Migrations/20171018175735_Initial.cs
Normal file
@@ -0,0 +1,209 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Infrastructure.Data.Migrations
|
||||||
|
{
|
||||||
|
public partial class Initial : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateSequence(
|
||||||
|
name: "catalog_brand_hilo",
|
||||||
|
incrementBy: 10);
|
||||||
|
|
||||||
|
migrationBuilder.CreateSequence(
|
||||||
|
name: "catalog_hilo",
|
||||||
|
incrementBy: 10);
|
||||||
|
|
||||||
|
migrationBuilder.CreateSequence(
|
||||||
|
name: "catalog_type_hilo",
|
||||||
|
incrementBy: 10);
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Baskets",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
|
||||||
|
BuyerId = table.Column<string>(type: "nvarchar(max)", nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Baskets", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "CatalogBrand",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false),
|
||||||
|
Brand = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_CatalogBrand", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "CatalogType",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false),
|
||||||
|
Type = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_CatalogType", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Orders",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
|
||||||
|
BuyerId = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||||
|
OrderDate = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
|
||||||
|
ShipToAddress_City = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||||
|
ShipToAddress_Country = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||||
|
ShipToAddress_State = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||||
|
ShipToAddress_Street = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||||
|
ShipToAddress_ZipCode = table.Column<string>(type: "nvarchar(max)", nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Orders", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "BasketItem",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
|
||||||
|
BasketId = table.Column<int>(type: "int", nullable: true),
|
||||||
|
CatalogItemId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
Quantity = table.Column<int>(type: "int", nullable: false),
|
||||||
|
UnitPrice = table.Column<decimal>(type: "decimal(18, 2)", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_BasketItem", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_BasketItem_Baskets_BasketId",
|
||||||
|
column: x => x.BasketId,
|
||||||
|
principalTable: "Baskets",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Restrict);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Catalog",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false),
|
||||||
|
CatalogBrandId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
CatalogTypeId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
Description = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||||
|
Name = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
|
||||||
|
PictureUri = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||||
|
Price = table.Column<decimal>(type: "decimal(18, 2)", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Catalog", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Catalog_CatalogBrand_CatalogBrandId",
|
||||||
|
column: x => x.CatalogBrandId,
|
||||||
|
principalTable: "CatalogBrand",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Catalog_CatalogType_CatalogTypeId",
|
||||||
|
column: x => x.CatalogTypeId,
|
||||||
|
principalTable: "CatalogType",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "OrderItems",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
|
||||||
|
OrderId = table.Column<int>(type: "int", nullable: true),
|
||||||
|
UnitPrice = table.Column<decimal>(type: "decimal(18, 2)", nullable: false),
|
||||||
|
Units = table.Column<int>(type: "int", nullable: false),
|
||||||
|
ItemOrdered_CatalogItemId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
ItemOrdered_PictureUri = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||||
|
ItemOrdered_ProductName = table.Column<string>(type: "nvarchar(max)", nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_OrderItems", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_OrderItems_Orders_OrderId",
|
||||||
|
column: x => x.OrderId,
|
||||||
|
principalTable: "Orders",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Restrict);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_BasketItem_BasketId",
|
||||||
|
table: "BasketItem",
|
||||||
|
column: "BasketId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Catalog_CatalogBrandId",
|
||||||
|
table: "Catalog",
|
||||||
|
column: "CatalogBrandId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Catalog_CatalogTypeId",
|
||||||
|
table: "Catalog",
|
||||||
|
column: "CatalogTypeId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_OrderItems_OrderId",
|
||||||
|
table: "OrderItems",
|
||||||
|
column: "OrderId");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "BasketItem");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Catalog");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "OrderItems");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Baskets");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "CatalogBrand");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "CatalogType");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Orders");
|
||||||
|
|
||||||
|
migrationBuilder.DropSequence(
|
||||||
|
name: "catalog_brand_hilo");
|
||||||
|
|
||||||
|
migrationBuilder.DropSequence(
|
||||||
|
name: "catalog_hilo");
|
||||||
|
|
||||||
|
migrationBuilder.DropSequence(
|
||||||
|
name: "catalog_type_hilo");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
using System;
|
// <auto-generated />
|
||||||
|
using Infrastructure.Data;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore.Metadata;
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
using Infrastructure.Data;
|
using Microsoft.EntityFrameworkCore.Storage;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.Internal;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace Infrastructure.Data.Migrations
|
namespace Infrastructure.Data.Migrations
|
||||||
{
|
{
|
||||||
@@ -12,13 +15,46 @@ namespace Infrastructure.Data.Migrations
|
|||||||
{
|
{
|
||||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
modelBuilder
|
modelBuilder
|
||||||
.HasAnnotation("ProductVersion", "1.1.2")
|
.HasAnnotation("ProductVersion", "2.0.0-rtm-26452")
|
||||||
.HasAnnotation("SqlServer:Sequence:.catalog_brand_hilo", "'catalog_brand_hilo', '', '1', '10', '', '', 'Int64', 'False'")
|
.HasAnnotation("Relational:Sequence:.catalog_brand_hilo", "'catalog_brand_hilo', '', '1', '10', '', '', 'Int64', 'False'")
|
||||||
.HasAnnotation("SqlServer:Sequence:.catalog_hilo", "'catalog_hilo', '', '1', '10', '', '', 'Int64', 'False'")
|
.HasAnnotation("Relational:Sequence:.catalog_hilo", "'catalog_hilo', '', '1', '10', '', '', 'Int64', 'False'")
|
||||||
.HasAnnotation("SqlServer:Sequence:.catalog_type_hilo", "'catalog_type_hilo', '', '1', '10', '', '', 'Int64', 'False'")
|
.HasAnnotation("Relational:Sequence:.catalog_type_hilo", "'catalog_type_hilo', '', '1', '10', '', '', 'Int64', 'False'")
|
||||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||||
|
|
||||||
|
modelBuilder.Entity("ApplicationCore.Entities.OrderAggregate.Order", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<string>("BuyerId");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("OrderDate");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ApplicationCore.Entities.OrderAggregate.OrderItem", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<int?>("OrderId");
|
||||||
|
|
||||||
|
b.Property<decimal>("UnitPrice");
|
||||||
|
|
||||||
|
b.Property<int>("Units");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("OrderId");
|
||||||
|
|
||||||
|
b.ToTable("OrderItems");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.Basket", b =>
|
modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.Basket", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@@ -113,6 +149,56 @@ namespace Infrastructure.Data.Migrations
|
|||||||
b.ToTable("CatalogType");
|
b.ToTable("CatalogType");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ApplicationCore.Entities.OrderAggregate.Order", b =>
|
||||||
|
{
|
||||||
|
b.OwnsOne("ApplicationCore.Entities.OrderAggregate.Address", "ShipToAddress", b1 =>
|
||||||
|
{
|
||||||
|
b1.Property<int>("OrderId");
|
||||||
|
|
||||||
|
b1.Property<string>("City");
|
||||||
|
|
||||||
|
b1.Property<string>("Country");
|
||||||
|
|
||||||
|
b1.Property<string>("State");
|
||||||
|
|
||||||
|
b1.Property<string>("Street");
|
||||||
|
|
||||||
|
b1.Property<string>("ZipCode");
|
||||||
|
|
||||||
|
b1.ToTable("Orders");
|
||||||
|
|
||||||
|
b1.HasOne("ApplicationCore.Entities.OrderAggregate.Order")
|
||||||
|
.WithOne("ShipToAddress")
|
||||||
|
.HasForeignKey("ApplicationCore.Entities.OrderAggregate.Address", "OrderId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ApplicationCore.Entities.OrderAggregate.OrderItem", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("ApplicationCore.Entities.OrderAggregate.Order")
|
||||||
|
.WithMany("OrderItems")
|
||||||
|
.HasForeignKey("OrderId");
|
||||||
|
|
||||||
|
b.OwnsOne("ApplicationCore.Entities.OrderAggregate.CatalogItemOrdered", "ItemOrdered", b1 =>
|
||||||
|
{
|
||||||
|
b1.Property<int>("OrderItemId");
|
||||||
|
|
||||||
|
b1.Property<int>("CatalogItemId");
|
||||||
|
|
||||||
|
b1.Property<string>("PictureUri");
|
||||||
|
|
||||||
|
b1.Property<string>("ProductName");
|
||||||
|
|
||||||
|
b1.ToTable("OrderItems");
|
||||||
|
|
||||||
|
b1.HasOne("ApplicationCore.Entities.OrderAggregate.OrderItem")
|
||||||
|
.WithOne("ItemOrdered")
|
||||||
|
.HasForeignKey("ApplicationCore.Entities.OrderAggregate.CatalogItemOrdered", "OrderItemId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.BasketItem", b =>
|
modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.BasketItem", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.Basket")
|
b.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.Basket")
|
||||||
@@ -132,6 +218,7 @@ namespace Infrastructure.Data.Migrations
|
|||||||
.HasForeignKey("CatalogTypeId")
|
.HasForeignKey("CatalogTypeId")
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
});
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,46 @@
|
|||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore;
|
using Microsoft.AspNetCore;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Infrastructure.Data;
|
||||||
|
using System;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Infrastructure.Identity;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
|
||||||
namespace Microsoft.eShopWeb
|
namespace Microsoft.eShopWeb
|
||||||
{
|
{
|
||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
BuildWebHost(args).Run();
|
var host = BuildWebHost(args);
|
||||||
|
|
||||||
|
using (var scope = host.Services.CreateScope())
|
||||||
|
{
|
||||||
|
var services = scope.ServiceProvider;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var catalogContext = services.GetRequiredService<CatalogContext>();
|
||||||
|
var loggerFactory = services.GetRequiredService<ILoggerFactory>();
|
||||||
|
CatalogContextSeed.SeedAsync(catalogContext, loggerFactory)
|
||||||
|
.Wait();
|
||||||
|
|
||||||
|
// move to IdentitySeed method
|
||||||
|
var userManager = services.GetRequiredService<UserManager<ApplicationUser>>();
|
||||||
|
var defaultUser = new ApplicationUser { UserName = "demouser@microsoft.com", Email = "demouser@microsoft.com" };
|
||||||
|
userManager.CreateAsync(defaultUser, "Pass@word1").Wait();
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.ToString());
|
||||||
|
//var logger = services.GetRequiredService<ILogger<Program>>();
|
||||||
|
//logger.LogError(ex, "An error occurred seeding the DB.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
host.Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IWebHost BuildWebHost(string[] args) =>
|
public static IWebHost BuildWebHost(string[] args) =>
|
||||||
|
|||||||
@@ -32,14 +32,15 @@ namespace Microsoft.eShopWeb
|
|||||||
|
|
||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
// Requires LocalDB which can be installed with SQL Server Express 2016
|
|
||||||
// https://www.microsoft.com/en-us/download/details.aspx?id=54284
|
|
||||||
services.AddDbContext<CatalogContext>(c =>
|
services.AddDbContext<CatalogContext>(c =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
c.UseInMemoryDatabase("Catalog");
|
//c.UseInMemoryDatabase("Catalog");
|
||||||
//c.UseSqlServer(Configuration.GetConnectionString("CatalogConnection"));
|
|
||||||
|
// Requires LocalDB which can be installed with SQL Server Express 2016
|
||||||
|
// https://www.microsoft.com/en-us/download/details.aspx?id=54284
|
||||||
|
c.UseSqlServer(Configuration.GetConnectionString("CatalogConnection"));
|
||||||
}
|
}
|
||||||
catch (System.Exception ex )
|
catch (System.Exception ex )
|
||||||
{
|
{
|
||||||
@@ -49,8 +50,8 @@ namespace Microsoft.eShopWeb
|
|||||||
|
|
||||||
// Add Identity DbContext
|
// Add Identity DbContext
|
||||||
services.AddDbContext<AppIdentityDbContext>(options =>
|
services.AddDbContext<AppIdentityDbContext>(options =>
|
||||||
options.UseInMemoryDatabase("Identity"));
|
//options.UseInMemoryDatabase("Identity"));
|
||||||
//options.UseSqlServer(Configuration.GetConnectionString("IdentityConnection")));
|
options.UseSqlServer(Configuration.GetConnectionString("IdentityConnection")));
|
||||||
|
|
||||||
services.AddIdentity<ApplicationUser, IdentityRole>()
|
services.AddIdentity<ApplicationUser, IdentityRole>()
|
||||||
.AddEntityFrameworkStores<AppIdentityDbContext>()
|
.AddEntityFrameworkStores<AppIdentityDbContext>()
|
||||||
@@ -129,44 +130,21 @@ namespace Microsoft.eShopWeb
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ConfigureDevelopment(IApplicationBuilder app,
|
// moved to Program.cs
|
||||||
IHostingEnvironment env,
|
//public void ConfigureDevelopment(IApplicationBuilder app,
|
||||||
ILoggerFactory loggerFactory,
|
// IHostingEnvironment env,
|
||||||
UserManager<ApplicationUser> userManager,
|
// ILoggerFactory loggerFactory,
|
||||||
CatalogContext catalogContext)
|
// UserManager<ApplicationUser> userManager,
|
||||||
{
|
// CatalogContext catalogContext)
|
||||||
Configure(app, env);
|
//{
|
||||||
|
// Configure(app, env);
|
||||||
|
|
||||||
//Seed Data
|
// //Seed Data
|
||||||
CatalogContextSeed.SeedAsync(app, catalogContext, loggerFactory)
|
// CatalogContextSeed.SeedAsync(app, catalogContext, loggerFactory)
|
||||||
.Wait();
|
// .Wait();
|
||||||
|
|
||||||
var defaultUser = new ApplicationUser { UserName = "demouser@microsoft.com", Email = "demouser@microsoft.com" };
|
// var defaultUser = new ApplicationUser { UserName = "demouser@microsoft.com", Email = "demouser@microsoft.com" };
|
||||||
userManager.CreateAsync(defaultUser, "Pass@word1").Wait();
|
// userManager.CreateAsync(defaultUser, "Pass@word1").Wait();
|
||||||
}
|
//}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Use this section to perform production-specific configuration.
|
|
||||||
/// In this case it is duplicating Development so that deployments to Azure will have sample data immediately.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="app"></param>
|
|
||||||
/// <param name="env"></param>
|
|
||||||
/// <param name="loggerFactory"></param>
|
|
||||||
/// <param name="userManager"></param>
|
|
||||||
public void ConfigureProduction(IApplicationBuilder app,
|
|
||||||
IHostingEnvironment env,
|
|
||||||
ILoggerFactory loggerFactory,
|
|
||||||
UserManager<ApplicationUser> userManager,
|
|
||||||
CatalogContext catalogContext)
|
|
||||||
{
|
|
||||||
Configure(app, env);
|
|
||||||
|
|
||||||
//Seed Data
|
|
||||||
CatalogContextSeed.SeedAsync(app, catalogContext, loggerFactory)
|
|
||||||
.Wait();
|
|
||||||
|
|
||||||
var defaultUser = new ApplicationUser { UserName = "demouser@microsoft.com", Email = "demouser@microsoft.com" };
|
|
||||||
userManager.CreateAsync(defaultUser, "Pass@word1").Wait();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
<ProjectReference Include="..\Infrastructure\Infrastructure.csproj" />
|
<ProjectReference Include="..\Infrastructure\Infrastructure.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />
|
||||||
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
|
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
|
||||||
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="2.0.0" />
|
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="2.0.0" />
|
||||||
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
|
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
|
||||||
|
|||||||
Reference in New Issue
Block a user