Set adddress as value object with workaround about Id and Hashkey
This commit is contained in:
parent
8522e4e288
commit
e991060a51
@ -30,7 +30,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> Handle(CreateOrderCommand message)
|
public async Task<bool> Handle(CreateOrderCommand message)
|
||||||
{
|
{
|
||||||
// Add/Update the Buyer AggregateRoot
|
// Add/Update the Buyer AggregateRoot
|
||||||
// DDD patterns comment: Add child entities and value-objects through the Order Aggregate-Root
|
// DDD patterns comment: Add child entities and value-objects through the Order Aggregate-Root
|
||||||
// methods and constructor so validations, invariants and business logic
|
// methods and constructor so validations, invariants and business logic
|
||||||
@ -73,6 +73,7 @@
|
|||||||
.SaveChangesAsync();
|
.SaveChangesAsync();
|
||||||
|
|
||||||
return result > 0;
|
return result > 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ using System.Threading.Tasks;
|
|||||||
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
|
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
|
||||||
{
|
{
|
||||||
[Route("api/v1/[controller]")]
|
[Route("api/v1/[controller]")]
|
||||||
[Authorize]
|
//[Authorize]
|
||||||
public class OrdersController : Controller
|
public class OrdersController : Controller
|
||||||
{
|
{
|
||||||
private readonly IMediator _mediator;
|
private readonly IMediator _mediator;
|
||||||
|
@ -1,217 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
||||||
using Microsoft.EntityFrameworkCore.Metadata;
|
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure;
|
|
||||||
|
|
||||||
namespace Ordering.API.Migrations
|
|
||||||
{
|
|
||||||
[DbContext(typeof(OrderingContext))]
|
|
||||||
[Migration("20170127103457_Initial")]
|
|
||||||
partial class Initial
|
|
||||||
{
|
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
|
||||||
{
|
|
||||||
modelBuilder
|
|
||||||
.HasAnnotation("ProductVersion", "1.1.0-rtm-22752")
|
|
||||||
.HasAnnotation("SqlServer:Sequence:.orderitemseq", "'orderitemseq', '', '1', '10', '', '', 'Int64', 'False'")
|
|
||||||
.HasAnnotation("SqlServer:Sequence:ordering.buyerseq", "'buyerseq', 'ordering', '1', '10', '', '', 'Int64', 'False'")
|
|
||||||
.HasAnnotation("SqlServer:Sequence:ordering.orderseq", "'orderseq', 'ordering', '1', '10', '', '', 'Int64', 'False'")
|
|
||||||
.HasAnnotation("SqlServer:Sequence:ordering.paymentseq", "'paymentseq', 'ordering', '1', '10', '', '', 'Int64', 'False'")
|
|
||||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Buyer", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasAnnotation("SqlServer:HiLoSequenceName", "buyerseq")
|
|
||||||
.HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering")
|
|
||||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
|
|
||||||
|
|
||||||
b.Property<string>("FullName")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(200);
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.HasIndex("FullName")
|
|
||||||
.IsUnique();
|
|
||||||
|
|
||||||
b.ToTable("buyers","ordering");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.CardType", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.HasDefaultValue(1);
|
|
||||||
|
|
||||||
b.Property<string>("Name")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(200);
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.ToTable("cardtypes","ordering");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.PaymentMethod", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasAnnotation("SqlServer:HiLoSequenceName", "paymentseq")
|
|
||||||
.HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering")
|
|
||||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
|
|
||||||
|
|
||||||
b.Property<string>("Alias")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(200);
|
|
||||||
|
|
||||||
b.Property<int>("BuyerId");
|
|
||||||
|
|
||||||
b.Property<string>("CardHolderName")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(200);
|
|
||||||
|
|
||||||
b.Property<string>("CardNumber")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(25);
|
|
||||||
|
|
||||||
b.Property<int>("CardTypeId");
|
|
||||||
|
|
||||||
b.Property<DateTime>("Expiration");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.HasIndex("BuyerId");
|
|
||||||
|
|
||||||
b.HasIndex("CardTypeId");
|
|
||||||
|
|
||||||
b.ToTable("paymentmethods","ordering");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Order", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasAnnotation("SqlServer:HiLoSequenceName", "orderseq")
|
|
||||||
.HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering")
|
|
||||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
|
|
||||||
|
|
||||||
b.Property<int>("BuyerId");
|
|
||||||
|
|
||||||
b.Property<string>("City")
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Property<string>("Country")
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Property<DateTime>("OrderDate");
|
|
||||||
|
|
||||||
b.Property<int>("OrderStatusId");
|
|
||||||
|
|
||||||
b.Property<int>("PaymentMethodId");
|
|
||||||
|
|
||||||
b.Property<string>("State")
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Property<string>("Street")
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Property<string>("ZipCode")
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.HasIndex("BuyerId");
|
|
||||||
|
|
||||||
b.HasIndex("OrderStatusId");
|
|
||||||
|
|
||||||
b.HasIndex("PaymentMethodId");
|
|
||||||
|
|
||||||
b.ToTable("orders","ordering");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.OrderItem", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasAnnotation("SqlServer:HiLoSequenceName", "orderitemseq")
|
|
||||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
|
|
||||||
|
|
||||||
b.Property<decimal>("Discount");
|
|
||||||
|
|
||||||
b.Property<int>("OrderId");
|
|
||||||
|
|
||||||
b.Property<string>("PictureUrl");
|
|
||||||
|
|
||||||
b.Property<int>("ProductId");
|
|
||||||
|
|
||||||
b.Property<string>("ProductName")
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Property<decimal>("UnitPrice");
|
|
||||||
|
|
||||||
b.Property<int>("Units");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.HasIndex("OrderId");
|
|
||||||
|
|
||||||
b.ToTable("orderItems","ordering");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.OrderStatus", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.HasDefaultValue(1);
|
|
||||||
|
|
||||||
b.Property<string>("Name")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(200);
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.ToTable("orderstatus","ordering");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.PaymentMethod", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Buyer")
|
|
||||||
.WithMany("PaymentMethods")
|
|
||||||
.HasForeignKey("BuyerId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
|
||||||
|
|
||||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.CardType", "CardType")
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("CardTypeId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Order", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Buyer", "Buyer")
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("BuyerId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
|
||||||
|
|
||||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.OrderStatus", "OrderStatus")
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("OrderStatusId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
|
||||||
|
|
||||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.PaymentMethod", "PaymentMethod")
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("PaymentMethodId");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.OrderItem", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Order")
|
|
||||||
.WithMany("OrderItems")
|
|
||||||
.HasForeignKey("OrderId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,39 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Migrations
|
|
||||||
{
|
|
||||||
public partial class RefactorBuyerWithIdentityGuid : Migration
|
|
||||||
{
|
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
migrationBuilder.RenameColumn(
|
|
||||||
name: "FullName",
|
|
||||||
schema: "ordering",
|
|
||||||
table: "buyers",
|
|
||||||
newName: "IdentityGuid");
|
|
||||||
|
|
||||||
migrationBuilder.RenameIndex(
|
|
||||||
name: "IX_buyers_FullName",
|
|
||||||
schema: "ordering",
|
|
||||||
table: "buyers",
|
|
||||||
newName: "IX_buyers_IdentityGuid");
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
migrationBuilder.RenameColumn(
|
|
||||||
name: "IdentityGuid",
|
|
||||||
schema: "ordering",
|
|
||||||
table: "buyers",
|
|
||||||
newName: "FullName");
|
|
||||||
|
|
||||||
migrationBuilder.RenameIndex(
|
|
||||||
name: "IX_buyers_IdentityGuid",
|
|
||||||
schema: "ordering",
|
|
||||||
table: "buyers",
|
|
||||||
newName: "IX_buyers_FullName");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -5,11 +5,11 @@ using Microsoft.EntityFrameworkCore.Metadata;
|
|||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure;
|
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure;
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Migrations
|
namespace Ordering.API.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(OrderingContext))]
|
[DbContext(typeof(OrderingContext))]
|
||||||
[Migration("20170208054757_RefactorBuyerWithIdentityGuid")]
|
[Migration("20170208181933_Initial")]
|
||||||
partial class RefactorBuyerWithIdentityGuid
|
partial class Initial
|
||||||
{
|
{
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
@ -90,6 +90,26 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Migra
|
|||||||
b.ToTable("paymentmethods","ordering");
|
b.ToTable("paymentmethods","ordering");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Address", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<string>("City");
|
||||||
|
|
||||||
|
b.Property<string>("Country");
|
||||||
|
|
||||||
|
b.Property<string>("State");
|
||||||
|
|
||||||
|
b.Property<string>("Street");
|
||||||
|
|
||||||
|
b.Property<string>("ZipCode");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("address","ordering");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Order", b =>
|
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Order", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@ -98,31 +118,20 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Migra
|
|||||||
.HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering")
|
.HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering")
|
||||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
|
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
|
||||||
|
|
||||||
|
b.Property<int?>("AddressId");
|
||||||
|
|
||||||
b.Property<int>("BuyerId");
|
b.Property<int>("BuyerId");
|
||||||
|
|
||||||
b.Property<string>("City")
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Property<string>("Country")
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Property<DateTime>("OrderDate");
|
b.Property<DateTime>("OrderDate");
|
||||||
|
|
||||||
b.Property<int>("OrderStatusId");
|
b.Property<int>("OrderStatusId");
|
||||||
|
|
||||||
b.Property<int>("PaymentMethodId");
|
b.Property<int>("PaymentMethodId");
|
||||||
|
|
||||||
b.Property<string>("State")
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Property<string>("Street")
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Property<string>("ZipCode")
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("AddressId");
|
||||||
|
|
||||||
b.HasIndex("BuyerId");
|
b.HasIndex("BuyerId");
|
||||||
|
|
||||||
b.HasIndex("OrderStatusId");
|
b.HasIndex("OrderStatusId");
|
||||||
@ -190,6 +199,10 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Migra
|
|||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Order", b =>
|
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Order", b =>
|
||||||
{
|
{
|
||||||
|
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Address", "Address")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("AddressId");
|
||||||
|
|
||||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Buyer", "Buyer")
|
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Buyer", "Buyer")
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("BuyerId")
|
.HasForeignKey("BuyerId")
|
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
|
||||||
namespace Ordering.API.Migrations
|
namespace Ordering.API.Migrations
|
||||||
{
|
{
|
||||||
@ -36,7 +37,7 @@ namespace Ordering.API.Migrations
|
|||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
Id = table.Column<int>(nullable: false),
|
Id = table.Column<int>(nullable: false),
|
||||||
FullName = table.Column<string>(maxLength: 200, nullable: false)
|
IdentityGuid = table.Column<string>(maxLength: 200, nullable: false)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
@ -56,6 +57,24 @@ namespace Ordering.API.Migrations
|
|||||||
table.PrimaryKey("PK_cardtypes", x => x.Id);
|
table.PrimaryKey("PK_cardtypes", x => x.Id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "address",
|
||||||
|
schema: "ordering",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(nullable: false)
|
||||||
|
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
|
||||||
|
City = table.Column<string>(nullable: true),
|
||||||
|
Country = table.Column<string>(nullable: true),
|
||||||
|
State = table.Column<string>(nullable: true),
|
||||||
|
Street = table.Column<string>(nullable: true),
|
||||||
|
ZipCode = table.Column<string>(nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_address", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "orderstatus",
|
name: "orderstatus",
|
||||||
schema: "ordering",
|
schema: "ordering",
|
||||||
@ -107,19 +126,22 @@ namespace Ordering.API.Migrations
|
|||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
Id = table.Column<int>(nullable: false),
|
Id = table.Column<int>(nullable: false),
|
||||||
|
AddressId = table.Column<int>(nullable: true),
|
||||||
BuyerId = table.Column<int>(nullable: false),
|
BuyerId = table.Column<int>(nullable: false),
|
||||||
City = table.Column<string>(nullable: false),
|
|
||||||
Country = table.Column<string>(nullable: false),
|
|
||||||
OrderDate = table.Column<DateTime>(nullable: false),
|
OrderDate = table.Column<DateTime>(nullable: false),
|
||||||
OrderStatusId = table.Column<int>(nullable: false),
|
OrderStatusId = table.Column<int>(nullable: false),
|
||||||
PaymentMethodId = table.Column<int>(nullable: false),
|
PaymentMethodId = table.Column<int>(nullable: false)
|
||||||
State = table.Column<string>(nullable: false),
|
|
||||||
Street = table.Column<string>(nullable: false),
|
|
||||||
ZipCode = table.Column<string>(nullable: false)
|
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
table.PrimaryKey("PK_orders", x => x.Id);
|
table.PrimaryKey("PK_orders", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_orders_address_AddressId",
|
||||||
|
column: x => x.AddressId,
|
||||||
|
principalSchema: "ordering",
|
||||||
|
principalTable: "address",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Restrict);
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "FK_orders_buyers_BuyerId",
|
name: "FK_orders_buyers_BuyerId",
|
||||||
column: x => x.BuyerId,
|
column: x => x.BuyerId,
|
||||||
@ -170,10 +192,10 @@ namespace Ordering.API.Migrations
|
|||||||
});
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_buyers_FullName",
|
name: "IX_buyers_IdentityGuid",
|
||||||
schema: "ordering",
|
schema: "ordering",
|
||||||
table: "buyers",
|
table: "buyers",
|
||||||
column: "FullName",
|
column: "IdentityGuid",
|
||||||
unique: true);
|
unique: true);
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
@ -188,6 +210,12 @@ namespace Ordering.API.Migrations
|
|||||||
table: "paymentmethods",
|
table: "paymentmethods",
|
||||||
column: "CardTypeId");
|
column: "CardTypeId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_orders_AddressId",
|
||||||
|
schema: "ordering",
|
||||||
|
table: "orders",
|
||||||
|
column: "AddressId");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_orders_BuyerId",
|
name: "IX_orders_BuyerId",
|
||||||
schema: "ordering",
|
schema: "ordering",
|
||||||
@ -223,6 +251,10 @@ namespace Ordering.API.Migrations
|
|||||||
name: "orders",
|
name: "orders",
|
||||||
schema: "ordering");
|
schema: "ordering");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "address",
|
||||||
|
schema: "ordering");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "orderstatus",
|
name: "orderstatus",
|
||||||
schema: "ordering");
|
schema: "ordering");
|
@ -89,6 +89,26 @@ namespace Ordering.API.Migrations
|
|||||||
b.ToTable("paymentmethods","ordering");
|
b.ToTable("paymentmethods","ordering");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Address", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<string>("City");
|
||||||
|
|
||||||
|
b.Property<string>("Country");
|
||||||
|
|
||||||
|
b.Property<string>("State");
|
||||||
|
|
||||||
|
b.Property<string>("Street");
|
||||||
|
|
||||||
|
b.Property<string>("ZipCode");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("address","ordering");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Order", b =>
|
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Order", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@ -97,31 +117,20 @@ namespace Ordering.API.Migrations
|
|||||||
.HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering")
|
.HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering")
|
||||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
|
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
|
||||||
|
|
||||||
|
b.Property<int?>("AddressId");
|
||||||
|
|
||||||
b.Property<int>("BuyerId");
|
b.Property<int>("BuyerId");
|
||||||
|
|
||||||
b.Property<string>("City")
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Property<string>("Country")
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Property<DateTime>("OrderDate");
|
b.Property<DateTime>("OrderDate");
|
||||||
|
|
||||||
b.Property<int>("OrderStatusId");
|
b.Property<int>("OrderStatusId");
|
||||||
|
|
||||||
b.Property<int>("PaymentMethodId");
|
b.Property<int>("PaymentMethodId");
|
||||||
|
|
||||||
b.Property<string>("State")
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Property<string>("Street")
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Property<string>("ZipCode")
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("AddressId");
|
||||||
|
|
||||||
b.HasIndex("BuyerId");
|
b.HasIndex("BuyerId");
|
||||||
|
|
||||||
b.HasIndex("OrderStatusId");
|
b.HasIndex("OrderStatusId");
|
||||||
@ -189,6 +198,10 @@ namespace Ordering.API.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Order", b =>
|
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Order", b =>
|
||||||
{
|
{
|
||||||
|
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Address", "Address")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("AddressId");
|
||||||
|
|
||||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Buyer", "Buyer")
|
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Buyer", "Buyer")
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("BuyerId")
|
.HasForeignKey("BuyerId")
|
||||||
|
@ -109,14 +109,14 @@
|
|||||||
|
|
||||||
app.UseCors("CorsPolicy");
|
app.UseCors("CorsPolicy");
|
||||||
|
|
||||||
var identityUrl = Configuration.GetValue<string>("IdentityUrl");
|
//var identityUrl = Configuration.GetValue<string>("IdentityUrl");
|
||||||
|
|
||||||
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
|
//app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
|
||||||
{
|
//{
|
||||||
Authority = identityUrl.ToString(),
|
// Authority = identityUrl.ToString(),
|
||||||
ScopeName = "orders",
|
// ScopeName = "orders",
|
||||||
RequireHttpsMetadata = false
|
// RequireHttpsMetadata = false
|
||||||
});
|
//});
|
||||||
|
|
||||||
|
|
||||||
app.UseMvcWithDefaultRoute();
|
app.UseMvcWithDefaultRoute();
|
||||||
|
@ -1,18 +1,21 @@
|
|||||||
using System;
|
using Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate
|
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate
|
||||||
{
|
{
|
||||||
public class Address
|
public class Address
|
||||||
|
:ValueObject
|
||||||
{
|
{
|
||||||
public String Street { get; }
|
public String Street { get; private set; }
|
||||||
|
|
||||||
public String City { get; }
|
public String City { get; private set; }
|
||||||
|
|
||||||
public String State { get; }
|
public String State { get; private set; }
|
||||||
|
|
||||||
public String Country { get; }
|
public String Country { get; private set; }
|
||||||
|
|
||||||
public String ZipCode { get; }
|
public String ZipCode { get; private set; }
|
||||||
|
|
||||||
public Address(string street, string city, string state, string country, string zipcode)
|
public Address(string street, string city, string state, string country, string zipcode)
|
||||||
{
|
{
|
||||||
@ -22,5 +25,14 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
|||||||
Country = country;
|
Country = country;
|
||||||
ZipCode = zipcode;
|
ZipCode = zipcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override IEnumerable<object> GetAtomicValues()
|
||||||
|
{
|
||||||
|
yield return Street;
|
||||||
|
yield return City;
|
||||||
|
yield return State;
|
||||||
|
yield return Country;
|
||||||
|
yield return ZipCode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,12 +14,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
|||||||
// aligned with DDD Aggregates and Domain Entities (Instead of properties and property collections)
|
// aligned with DDD Aggregates and Domain Entities (Instead of properties and property collections)
|
||||||
private DateTime _orderDate;
|
private DateTime _orderDate;
|
||||||
|
|
||||||
//TO DO: These fields need to be converted to a VALUE-OBJECT "Address"
|
public Address Address { get; private set; }
|
||||||
private string _street;
|
|
||||||
private string _city;
|
|
||||||
private string _state;
|
|
||||||
private string _country;
|
|
||||||
private string _zipCode;
|
|
||||||
|
|
||||||
public Buyer Buyer { get; private set; }
|
public Buyer Buyer { get; private set; }
|
||||||
private int _buyerId;
|
private int _buyerId;
|
||||||
@ -46,18 +41,13 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
|||||||
|
|
||||||
public Order(int buyerId, int paymentMethodId, Address address)
|
public Order(int buyerId, int paymentMethodId, Address address)
|
||||||
{
|
{
|
||||||
|
_orderItems = new List<OrderItem>();
|
||||||
_buyerId = buyerId;
|
_buyerId = buyerId;
|
||||||
_paymentMethodId = paymentMethodId;
|
_paymentMethodId = paymentMethodId;
|
||||||
_orderStatusId = OrderStatus.InProcess.Id;
|
_orderStatusId = OrderStatus.InProcess.Id;
|
||||||
_orderDate = DateTime.UtcNow;
|
_orderDate = DateTime.UtcNow;
|
||||||
_street = address.Street;
|
|
||||||
_city = address.City;
|
|
||||||
_state = address.State;
|
|
||||||
_country = address.Country;
|
|
||||||
_zipCode = address.ZipCode;
|
|
||||||
|
|
||||||
_orderItems = new List<OrderItem>();
|
Address = address;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DDD Patterns comment
|
// DDD Patterns comment
|
||||||
|
@ -30,6 +30,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure
|
|||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
|
modelBuilder.Entity<Address>(ConfigureAddress);
|
||||||
modelBuilder.Entity<Buyer>(ConfigureBuyer);
|
modelBuilder.Entity<Buyer>(ConfigureBuyer);
|
||||||
modelBuilder.Entity<PaymentMethod>(ConfigurePayment);
|
modelBuilder.Entity<PaymentMethod>(ConfigurePayment);
|
||||||
modelBuilder.Entity<Order>(ConfigureOrder);
|
modelBuilder.Entity<Order>(ConfigureOrder);
|
||||||
@ -38,6 +39,16 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure
|
|||||||
modelBuilder.Entity<OrderStatus>(ConfigureOrderStatus);
|
modelBuilder.Entity<OrderStatus>(ConfigureOrderStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConfigureAddress(EntityTypeBuilder<Address> addressConfiguration)
|
||||||
|
{
|
||||||
|
addressConfiguration.ToTable("address", DEFAULT_SCHEMA);
|
||||||
|
|
||||||
|
addressConfiguration.Property<int>("Id")
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
addressConfiguration.HasKey("Id");
|
||||||
|
}
|
||||||
|
|
||||||
void ConfigureBuyer(EntityTypeBuilder<Buyer> buyerConfiguration)
|
void ConfigureBuyer(EntityTypeBuilder<Buyer> buyerConfiguration)
|
||||||
{
|
{
|
||||||
buyerConfiguration.ToTable("buyers", DEFAULT_SCHEMA);
|
buyerConfiguration.ToTable("buyers", DEFAULT_SCHEMA);
|
||||||
@ -109,11 +120,6 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure
|
|||||||
.ForSqlServerUseSequenceHiLo("orderseq", DEFAULT_SCHEMA);
|
.ForSqlServerUseSequenceHiLo("orderseq", DEFAULT_SCHEMA);
|
||||||
|
|
||||||
orderConfiguration.Property<DateTime>("OrderDate").IsRequired();
|
orderConfiguration.Property<DateTime>("OrderDate").IsRequired();
|
||||||
orderConfiguration.Property<string>("Street").IsRequired();
|
|
||||||
orderConfiguration.Property<string>("State").IsRequired();
|
|
||||||
orderConfiguration.Property<string>("City").IsRequired();
|
|
||||||
orderConfiguration.Property<string>("ZipCode").IsRequired();
|
|
||||||
orderConfiguration.Property<string>("Country").IsRequired();
|
|
||||||
orderConfiguration.Property<int>("BuyerId").IsRequired();
|
orderConfiguration.Property<int>("BuyerId").IsRequired();
|
||||||
orderConfiguration.Property<int>("OrderStatusId").IsRequired();
|
orderConfiguration.Property<int>("OrderStatusId").IsRequired();
|
||||||
orderConfiguration.Property<int>("PaymentMethodId").IsRequired();
|
orderConfiguration.Property<int>("PaymentMethodId").IsRequired();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user