diff --git a/src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs b/src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs index 864be88b5..3e721cadc 100644 --- a/src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs @@ -30,7 +30,7 @@ } public async Task Handle(CreateOrderCommand message) - { + { // Add/Update the Buyer AggregateRoot // DDD patterns comment: Add child entities and value-objects through the Order Aggregate-Root // methods and constructor so validations, invariants and business logic @@ -73,6 +73,7 @@ .SaveChangesAsync(); return result > 0; + } } } diff --git a/src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs b/src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs index 2d46ec6a9..463417960 100644 --- a/src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs +++ b/src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs @@ -11,7 +11,7 @@ using System.Threading.Tasks; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers { [Route("api/v1/[controller]")] - [Authorize] + //[Authorize] public class OrdersController : Controller { private readonly IMediator _mediator; diff --git a/src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170127103457_Initial.Designer.cs b/src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170127103457_Initial.Designer.cs deleted file mode 100644 index cf7e5fdfb..000000000 --- a/src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170127103457_Initial.Designer.cs +++ /dev/null @@ -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("Id") - .ValueGeneratedOnAdd() - .HasAnnotation("SqlServer:HiLoSequenceName", "buyerseq") - .HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); - - b.Property("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("Id") - .HasDefaultValue(1); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200); - - b.HasKey("Id"); - - b.ToTable("cardtypes","ordering"); - }); - - modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.PaymentMethod", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasAnnotation("SqlServer:HiLoSequenceName", "paymentseq") - .HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); - - b.Property("Alias") - .IsRequired() - .HasMaxLength(200); - - b.Property("BuyerId"); - - b.Property("CardHolderName") - .IsRequired() - .HasMaxLength(200); - - b.Property("CardNumber") - .IsRequired() - .HasMaxLength(25); - - b.Property("CardTypeId"); - - b.Property("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("Id") - .ValueGeneratedOnAdd() - .HasAnnotation("SqlServer:HiLoSequenceName", "orderseq") - .HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); - - b.Property("BuyerId"); - - b.Property("City") - .IsRequired(); - - b.Property("Country") - .IsRequired(); - - b.Property("OrderDate"); - - b.Property("OrderStatusId"); - - b.Property("PaymentMethodId"); - - b.Property("State") - .IsRequired(); - - b.Property("Street") - .IsRequired(); - - b.Property("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("Id") - .ValueGeneratedOnAdd() - .HasAnnotation("SqlServer:HiLoSequenceName", "orderitemseq") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); - - b.Property("Discount"); - - b.Property("OrderId"); - - b.Property("PictureUrl"); - - b.Property("ProductId"); - - b.Property("ProductName") - .IsRequired(); - - b.Property("UnitPrice"); - - b.Property("Units"); - - b.HasKey("Id"); - - b.HasIndex("OrderId"); - - b.ToTable("orderItems","ordering"); - }); - - modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.OrderStatus", b => - { - b.Property("Id") - .HasDefaultValue(1); - - b.Property("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); - }); - } - } -} diff --git a/src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170208054757_RefactorBuyerWithIdentityGuid.cs b/src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170208054757_RefactorBuyerWithIdentityGuid.cs deleted file mode 100644 index 7f4f783e2..000000000 --- a/src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170208054757_RefactorBuyerWithIdentityGuid.cs +++ /dev/null @@ -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"); - } - } -} diff --git a/src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170208054757_RefactorBuyerWithIdentityGuid.Designer.cs b/src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170208181933_Initial.Designer.cs similarity index 89% rename from src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170208054757_RefactorBuyerWithIdentityGuid.Designer.cs rename to src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170208181933_Initial.Designer.cs index 954e8e66a..a6bd1fe1d 100644 --- a/src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170208054757_RefactorBuyerWithIdentityGuid.Designer.cs +++ b/src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170208181933_Initial.Designer.cs @@ -5,11 +5,11 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure; -namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Migrations +namespace Ordering.API.Migrations { [DbContext(typeof(OrderingContext))] - [Migration("20170208054757_RefactorBuyerWithIdentityGuid")] - partial class RefactorBuyerWithIdentityGuid + [Migration("20170208181933_Initial")] + partial class Initial { protected override void BuildTargetModel(ModelBuilder modelBuilder) { @@ -90,6 +90,26 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Migra b.ToTable("paymentmethods","ordering"); }); + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Address", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("City"); + + b.Property("Country"); + + b.Property("State"); + + b.Property("Street"); + + b.Property("ZipCode"); + + b.HasKey("Id"); + + b.ToTable("address","ordering"); + }); + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Order", b => { b.Property("Id") @@ -98,13 +118,9 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Migra .HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering") .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); - b.Property("BuyerId"); - - b.Property("City") - .IsRequired(); + b.Property("AddressId"); - b.Property("Country") - .IsRequired(); + b.Property("BuyerId"); b.Property("OrderDate"); @@ -112,17 +128,10 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Migra b.Property("PaymentMethodId"); - b.Property("State") - .IsRequired(); - - b.Property("Street") - .IsRequired(); - - b.Property("ZipCode") - .IsRequired(); - b.HasKey("Id"); + b.HasIndex("AddressId"); + b.HasIndex("BuyerId"); 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 => { + 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") .WithMany() .HasForeignKey("BuyerId") diff --git a/src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170127103457_Initial.cs b/src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170208181933_Initial.cs similarity index 84% rename from src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170127103457_Initial.cs rename to src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170208181933_Initial.cs index 86a9403c4..5346cef60 100644 --- a/src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170127103457_Initial.cs +++ b/src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170208181933_Initial.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Metadata; namespace Ordering.API.Migrations { @@ -36,7 +37,7 @@ namespace Ordering.API.Migrations columns: table => new { Id = table.Column(nullable: false), - FullName = table.Column(maxLength: 200, nullable: false) + IdentityGuid = table.Column(maxLength: 200, nullable: false) }, constraints: table => { @@ -56,6 +57,24 @@ namespace Ordering.API.Migrations table.PrimaryKey("PK_cardtypes", x => x.Id); }); + migrationBuilder.CreateTable( + name: "address", + schema: "ordering", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + City = table.Column(nullable: true), + Country = table.Column(nullable: true), + State = table.Column(nullable: true), + Street = table.Column(nullable: true), + ZipCode = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_address", x => x.Id); + }); + migrationBuilder.CreateTable( name: "orderstatus", schema: "ordering", @@ -107,19 +126,22 @@ namespace Ordering.API.Migrations columns: table => new { Id = table.Column(nullable: false), + AddressId = table.Column(nullable: true), BuyerId = table.Column(nullable: false), - City = table.Column(nullable: false), - Country = table.Column(nullable: false), OrderDate = table.Column(nullable: false), OrderStatusId = table.Column(nullable: false), - PaymentMethodId = table.Column(nullable: false), - State = table.Column(nullable: false), - Street = table.Column(nullable: false), - ZipCode = table.Column(nullable: false) + PaymentMethodId = table.Column(nullable: false) }, constraints: table => { 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( name: "FK_orders_buyers_BuyerId", column: x => x.BuyerId, @@ -170,10 +192,10 @@ namespace Ordering.API.Migrations }); migrationBuilder.CreateIndex( - name: "IX_buyers_FullName", + name: "IX_buyers_IdentityGuid", schema: "ordering", table: "buyers", - column: "FullName", + column: "IdentityGuid", unique: true); migrationBuilder.CreateIndex( @@ -188,6 +210,12 @@ namespace Ordering.API.Migrations table: "paymentmethods", column: "CardTypeId"); + migrationBuilder.CreateIndex( + name: "IX_orders_AddressId", + schema: "ordering", + table: "orders", + column: "AddressId"); + migrationBuilder.CreateIndex( name: "IX_orders_BuyerId", schema: "ordering", @@ -223,6 +251,10 @@ namespace Ordering.API.Migrations name: "orders", schema: "ordering"); + migrationBuilder.DropTable( + name: "address", + schema: "ordering"); + migrationBuilder.DropTable( name: "orderstatus", schema: "ordering"); diff --git a/src/Services/Ordering/Ordering.API/Infrastructure/Migrations/OrderingContextModelSnapshot.cs b/src/Services/Ordering/Ordering.API/Infrastructure/Migrations/OrderingContextModelSnapshot.cs index fb0788e55..5c7b6d25b 100644 --- a/src/Services/Ordering/Ordering.API/Infrastructure/Migrations/OrderingContextModelSnapshot.cs +++ b/src/Services/Ordering/Ordering.API/Infrastructure/Migrations/OrderingContextModelSnapshot.cs @@ -89,6 +89,26 @@ namespace Ordering.API.Migrations b.ToTable("paymentmethods","ordering"); }); + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Address", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("City"); + + b.Property("Country"); + + b.Property("State"); + + b.Property("Street"); + + b.Property("ZipCode"); + + b.HasKey("Id"); + + b.ToTable("address","ordering"); + }); + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Order", b => { b.Property("Id") @@ -97,13 +117,9 @@ namespace Ordering.API.Migrations .HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering") .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); - b.Property("BuyerId"); - - b.Property("City") - .IsRequired(); + b.Property("AddressId"); - b.Property("Country") - .IsRequired(); + b.Property("BuyerId"); b.Property("OrderDate"); @@ -111,17 +127,10 @@ namespace Ordering.API.Migrations b.Property("PaymentMethodId"); - b.Property("State") - .IsRequired(); - - b.Property("Street") - .IsRequired(); - - b.Property("ZipCode") - .IsRequired(); - b.HasKey("Id"); + b.HasIndex("AddressId"); + b.HasIndex("BuyerId"); b.HasIndex("OrderStatusId"); @@ -189,6 +198,10 @@ namespace Ordering.API.Migrations 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") .WithMany() .HasForeignKey("BuyerId") diff --git a/src/Services/Ordering/Ordering.API/Startup.cs b/src/Services/Ordering/Ordering.API/Startup.cs index 3ff48d2a8..381ed7cba 100644 --- a/src/Services/Ordering/Ordering.API/Startup.cs +++ b/src/Services/Ordering/Ordering.API/Startup.cs @@ -109,14 +109,14 @@ app.UseCors("CorsPolicy"); - var identityUrl = Configuration.GetValue("IdentityUrl"); - - app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions - { - Authority = identityUrl.ToString(), - ScopeName = "orders", - RequireHttpsMetadata = false - }); + //var identityUrl = Configuration.GetValue("IdentityUrl"); + + //app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions + //{ + // Authority = identityUrl.ToString(), + // ScopeName = "orders", + // RequireHttpsMetadata = false + //}); app.UseMvcWithDefaultRoute(); diff --git a/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Address.cs b/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Address.cs index b3760480c..961d83d3a 100644 --- a/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Address.cs +++ b/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Address.cs @@ -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 { 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) { @@ -22,5 +25,14 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O Country = country; ZipCode = zipcode; } + + protected override IEnumerable GetAtomicValues() + { + yield return Street; + yield return City; + yield return State; + yield return Country; + yield return ZipCode; + } } } diff --git a/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs b/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs index 8f6656c23..3c856f09a 100644 --- a/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs +++ b/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs @@ -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) 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; } private int _buyerId; @@ -46,18 +41,13 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O public Order(int buyerId, int paymentMethodId, Address address) { - + _orderItems = new List(); _buyerId = buyerId; _paymentMethodId = paymentMethodId; _orderStatusId = OrderStatus.InProcess.Id; _orderDate = DateTime.UtcNow; - _street = address.Street; - _city = address.City; - _state = address.State; - _country = address.Country; - _zipCode = address.ZipCode; - _orderItems = new List(); + Address = address; } // DDD Patterns comment diff --git a/src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs b/src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs index 4e3890e8a..34815b524 100644 --- a/src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs +++ b/src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs @@ -30,6 +30,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure protected override void OnModelCreating(ModelBuilder modelBuilder) { + modelBuilder.Entity
(ConfigureAddress); modelBuilder.Entity(ConfigureBuyer); modelBuilder.Entity(ConfigurePayment); modelBuilder.Entity(ConfigureOrder); @@ -38,6 +39,16 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure modelBuilder.Entity(ConfigureOrderStatus); } + void ConfigureAddress(EntityTypeBuilder
addressConfiguration) + { + addressConfiguration.ToTable("address", DEFAULT_SCHEMA); + + addressConfiguration.Property("Id") + .IsRequired(); + + addressConfiguration.HasKey("Id"); + } + void ConfigureBuyer(EntityTypeBuilder buyerConfiguration) { buyerConfiguration.ToTable("buyers", DEFAULT_SCHEMA); @@ -109,11 +120,6 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure .ForSqlServerUseSequenceHiLo("orderseq", DEFAULT_SCHEMA); orderConfiguration.Property("OrderDate").IsRequired(); - orderConfiguration.Property("Street").IsRequired(); - orderConfiguration.Property("State").IsRequired(); - orderConfiguration.Property("City").IsRequired(); - orderConfiguration.Property("ZipCode").IsRequired(); - orderConfiguration.Property("Country").IsRequired(); orderConfiguration.Property("BuyerId").IsRequired(); orderConfiguration.Property("OrderStatusId").IsRequired(); orderConfiguration.Property("PaymentMethodId").IsRequired();