Browse Source

Set adddress as value object with workaround about Id and Hashkey

pull/49/merge
unai 8 years ago
parent
commit
e991060a51
11 changed files with 143 additions and 332 deletions
  1. +2
    -1
      src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs
  2. +1
    -1
      src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs
  3. +0
    -217
      src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170127103457_Initial.Designer.cs
  4. +0
    -39
      src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170208054757_RefactorBuyerWithIdentityGuid.cs
  5. +31
    -18
      src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170208181933_Initial.Designer.cs
  6. +41
    -9
      src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170208181933_Initial.cs
  7. +28
    -15
      src/Services/Ordering/Ordering.API/Infrastructure/Migrations/OrderingContextModelSnapshot.cs
  8. +8
    -8
      src/Services/Ordering/Ordering.API/Startup.cs
  9. +18
    -6
      src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Address.cs
  10. +3
    -13
      src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs
  11. +11
    -5
      src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs

+ 2
- 1
src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs View File

@ -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;
} }
} }
} }

+ 1
- 1
src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs View File

@ -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;


+ 0
- 217
src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170127103457_Initial.Designer.cs View File

@ -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);
});
}
}
}

+ 0
- 39
src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170208054757_RefactorBuyerWithIdentityGuid.cs View File

@ -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");
}
}
}

src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170208054757_RefactorBuyerWithIdentityGuid.Designer.cs → src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170208181933_Initial.Designer.cs View File

@ -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")]
partial class RefactorBuyerWithIdentityGuid
[Migration("20170208181933_Initial")]
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,13 +118,9 @@ 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>("BuyerId");
b.Property<string>("City")
.IsRequired();
b.Property<int?>("AddressId");
b.Property<string>("Country")
.IsRequired();
b.Property<int>("BuyerId");
b.Property<DateTime>("OrderDate"); b.Property<DateTime>("OrderDate");
@ -112,17 +128,10 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Migra
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")

src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170127103457_Initial.cs → src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170208181933_Initial.cs View File

@ -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),
State = table.Column<string>(nullable: false),
Street = table.Column<string>(nullable: false),
ZipCode = table.Column<string>(nullable: false)
PaymentMethodId = table.Column<int>(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");

+ 28
- 15
src/Services/Ordering/Ordering.API/Infrastructure/Migrations/OrderingContextModelSnapshot.cs View File

@ -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,13 +117,9 @@ 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>("BuyerId");
b.Property<string>("City")
.IsRequired();
b.Property<int?>("AddressId");
b.Property<string>("Country")
.IsRequired();
b.Property<int>("BuyerId");
b.Property<DateTime>("OrderDate"); b.Property<DateTime>("OrderDate");
@ -111,17 +127,10 @@ namespace Ordering.API.Migrations
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")


+ 8
- 8
src/Services/Ordering/Ordering.API/Startup.cs View File

@ -109,14 +109,14 @@
app.UseCors("CorsPolicy"); app.UseCors("CorsPolicy");
var identityUrl = Configuration.GetValue<string>("IdentityUrl");
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
{
Authority = identityUrl.ToString(),
ScopeName = "orders",
RequireHttpsMetadata = false
});
//var identityUrl = Configuration.GetValue<string>("IdentityUrl");
//app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
//{
// Authority = identityUrl.ToString(),
// ScopeName = "orders",
// RequireHttpsMetadata = false
//});
app.UseMvcWithDefaultRoute(); app.UseMvcWithDefaultRoute();


+ 18
- 6
src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Address.cs View File

@ -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;
}
} }
} }

+ 3
- 13
src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs View File

@ -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"
private string _street;
private string _city;
private string _state;
private string _country;
private string _zipCode;
public Address Address { get; private set; }
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


+ 11
- 5
src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs View File

@ -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…
Cancel
Save