Fix query with new model. Add missing properties into migration. Work on github issues
This commit is contained in:
parent
9d2d152c2d
commit
607d1ca2fa
@ -39,7 +39,7 @@
|
|||||||
buyer = new Buyer(message.BuyerFullName);
|
buyer = new Buyer(message.BuyerFullName);
|
||||||
}
|
}
|
||||||
|
|
||||||
var payment = buyer.AddPayment(message.CardTypeId,
|
var payment = buyer.AddPaymentMethod(message.CardTypeId,
|
||||||
$"Payment Method on {DateTime.UtcNow}",
|
$"Payment Method on {DateTime.UtcNow}",
|
||||||
message.CardNumber,
|
message.CardNumber,
|
||||||
message.CardSecurityNumber,
|
message.CardSecurityNumber,
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using MediatR;
|
using MediatR;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
|
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
|
||||||
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Queries;
|
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Queries;
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
using Microsoft.AspNetCore.Mvc.Authorization;
|
using Microsoft.AspNetCore.Mvc.Authorization;
|
||||||
using Swashbuckle.Swagger.Model;
|
using Swashbuckle.Swagger.Model;
|
||||||
using Swashbuckle.SwaggerGen.Generator;
|
using Swashbuckle.SwaggerGen.Generator;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Auth
|
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Auth
|
||||||
{
|
{
|
||||||
|
@ -8,7 +8,7 @@ using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure;
|
|||||||
namespace Ordering.API.Migrations
|
namespace Ordering.API.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(OrderingContext))]
|
[DbContext(typeof(OrderingContext))]
|
||||||
[Migration("20170125143653_Initial")]
|
[Migration("20170127103457_Initial")]
|
||||||
partial class Initial
|
partial class Initial
|
||||||
{
|
{
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
@ -55,7 +55,7 @@ namespace Ordering.API.Migrations
|
|||||||
b.ToTable("cardtypes","ordering");
|
b.ToTable("cardtypes","ordering");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Payment", b =>
|
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.PaymentMethod", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
@ -87,7 +87,7 @@ namespace Ordering.API.Migrations
|
|||||||
|
|
||||||
b.HasIndex("CardTypeId");
|
b.HasIndex("CardTypeId");
|
||||||
|
|
||||||
b.ToTable("payments","ordering");
|
b.ToTable("paymentmethods","ordering");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Order", b =>
|
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Order", b =>
|
||||||
@ -103,11 +103,14 @@ namespace Ordering.API.Migrations
|
|||||||
b.Property<string>("City")
|
b.Property<string>("City")
|
||||||
.IsRequired();
|
.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>("PaymentId");
|
b.Property<int>("PaymentMethodId");
|
||||||
|
|
||||||
b.Property<string>("State")
|
b.Property<string>("State")
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
@ -124,7 +127,7 @@ namespace Ordering.API.Migrations
|
|||||||
|
|
||||||
b.HasIndex("OrderStatusId");
|
b.HasIndex("OrderStatusId");
|
||||||
|
|
||||||
b.HasIndex("PaymentId");
|
b.HasIndex("PaymentMethodId");
|
||||||
|
|
||||||
b.ToTable("orders","ordering");
|
b.ToTable("orders","ordering");
|
||||||
});
|
});
|
||||||
@ -140,6 +143,8 @@ namespace Ordering.API.Migrations
|
|||||||
|
|
||||||
b.Property<int>("OrderId");
|
b.Property<int>("OrderId");
|
||||||
|
|
||||||
|
b.Property<string>("PictureUrl");
|
||||||
|
|
||||||
b.Property<int>("ProductId");
|
b.Property<int>("ProductId");
|
||||||
|
|
||||||
b.Property<string>("ProductName")
|
b.Property<string>("ProductName")
|
||||||
@ -170,10 +175,10 @@ namespace Ordering.API.Migrations
|
|||||||
b.ToTable("orderstatus","ordering");
|
b.ToTable("orderstatus","ordering");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Payment", b =>
|
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.PaymentMethod", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Buyer")
|
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Buyer")
|
||||||
.WithMany("Payments")
|
.WithMany("PaymentMethods")
|
||||||
.HasForeignKey("BuyerId")
|
.HasForeignKey("BuyerId")
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
|
||||||
@ -195,9 +200,9 @@ namespace Ordering.API.Migrations
|
|||||||
.HasForeignKey("OrderStatusId")
|
.HasForeignKey("OrderStatusId")
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
|
||||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Payment", "Payment")
|
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.PaymentMethod", "PaymentMethod")
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("PaymentId");
|
.HasForeignKey("PaymentMethodId");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.OrderItem", b =>
|
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.OrderItem", b =>
|
@ -70,7 +70,7 @@ namespace Ordering.API.Migrations
|
|||||||
});
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "payments",
|
name: "paymentmethods",
|
||||||
schema: "ordering",
|
schema: "ordering",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
@ -84,16 +84,16 @@ namespace Ordering.API.Migrations
|
|||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
table.PrimaryKey("PK_payments", x => x.Id);
|
table.PrimaryKey("PK_paymentmethods", x => x.Id);
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "FK_payments_buyers_BuyerId",
|
name: "FK_paymentmethods_buyers_BuyerId",
|
||||||
column: x => x.BuyerId,
|
column: x => x.BuyerId,
|
||||||
principalSchema: "ordering",
|
principalSchema: "ordering",
|
||||||
principalTable: "buyers",
|
principalTable: "buyers",
|
||||||
principalColumn: "Id",
|
principalColumn: "Id",
|
||||||
onDelete: ReferentialAction.Cascade);
|
onDelete: ReferentialAction.Cascade);
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "FK_payments_cardtypes_CardTypeId",
|
name: "FK_paymentmethods_cardtypes_CardTypeId",
|
||||||
column: x => x.CardTypeId,
|
column: x => x.CardTypeId,
|
||||||
principalSchema: "ordering",
|
principalSchema: "ordering",
|
||||||
principalTable: "cardtypes",
|
principalTable: "cardtypes",
|
||||||
@ -109,9 +109,10 @@ namespace Ordering.API.Migrations
|
|||||||
Id = table.Column<int>(nullable: false),
|
Id = table.Column<int>(nullable: false),
|
||||||
BuyerId = table.Column<int>(nullable: false),
|
BuyerId = table.Column<int>(nullable: false),
|
||||||
City = table.Column<string>(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),
|
||||||
PaymentId = table.Column<int>(nullable: false),
|
PaymentMethodId = table.Column<int>(nullable: false),
|
||||||
State = table.Column<string>(nullable: false),
|
State = table.Column<string>(nullable: false),
|
||||||
Street = table.Column<string>(nullable: false),
|
Street = table.Column<string>(nullable: false),
|
||||||
ZipCode = table.Column<string>(nullable: false)
|
ZipCode = table.Column<string>(nullable: false)
|
||||||
@ -134,10 +135,10 @@ namespace Ordering.API.Migrations
|
|||||||
principalColumn: "Id",
|
principalColumn: "Id",
|
||||||
onDelete: ReferentialAction.Cascade);
|
onDelete: ReferentialAction.Cascade);
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "FK_orders_payments_PaymentId",
|
name: "FK_orders_paymentmethods_PaymentMethodId",
|
||||||
column: x => x.PaymentId,
|
column: x => x.PaymentMethodId,
|
||||||
principalSchema: "ordering",
|
principalSchema: "ordering",
|
||||||
principalTable: "payments",
|
principalTable: "paymentmethods",
|
||||||
principalColumn: "Id",
|
principalColumn: "Id",
|
||||||
onDelete: ReferentialAction.Restrict);
|
onDelete: ReferentialAction.Restrict);
|
||||||
});
|
});
|
||||||
@ -150,6 +151,7 @@ namespace Ordering.API.Migrations
|
|||||||
Id = table.Column<int>(nullable: false),
|
Id = table.Column<int>(nullable: false),
|
||||||
Discount = table.Column<decimal>(nullable: false),
|
Discount = table.Column<decimal>(nullable: false),
|
||||||
OrderId = table.Column<int>(nullable: false),
|
OrderId = table.Column<int>(nullable: false),
|
||||||
|
PictureUrl = table.Column<string>(nullable: true),
|
||||||
ProductId = table.Column<int>(nullable: false),
|
ProductId = table.Column<int>(nullable: false),
|
||||||
ProductName = table.Column<string>(nullable: false),
|
ProductName = table.Column<string>(nullable: false),
|
||||||
UnitPrice = table.Column<decimal>(nullable: false),
|
UnitPrice = table.Column<decimal>(nullable: false),
|
||||||
@ -175,15 +177,15 @@ namespace Ordering.API.Migrations
|
|||||||
unique: true);
|
unique: true);
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_payments_BuyerId",
|
name: "IX_paymentmethods_BuyerId",
|
||||||
schema: "ordering",
|
schema: "ordering",
|
||||||
table: "payments",
|
table: "paymentmethods",
|
||||||
column: "BuyerId");
|
column: "BuyerId");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_payments_CardTypeId",
|
name: "IX_paymentmethods_CardTypeId",
|
||||||
schema: "ordering",
|
schema: "ordering",
|
||||||
table: "payments",
|
table: "paymentmethods",
|
||||||
column: "CardTypeId");
|
column: "CardTypeId");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
@ -199,10 +201,10 @@ namespace Ordering.API.Migrations
|
|||||||
column: "OrderStatusId");
|
column: "OrderStatusId");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_orders_PaymentId",
|
name: "IX_orders_PaymentMethodId",
|
||||||
schema: "ordering",
|
schema: "ordering",
|
||||||
table: "orders",
|
table: "orders",
|
||||||
column: "PaymentId");
|
column: "PaymentMethodId");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_orderItems_OrderId",
|
name: "IX_orderItems_OrderId",
|
||||||
@ -226,7 +228,7 @@ namespace Ordering.API.Migrations
|
|||||||
schema: "ordering");
|
schema: "ordering");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "payments",
|
name: "paymentmethods",
|
||||||
schema: "ordering");
|
schema: "ordering");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
@ -54,7 +54,7 @@ namespace Ordering.API.Migrations
|
|||||||
b.ToTable("cardtypes","ordering");
|
b.ToTable("cardtypes","ordering");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Payment", b =>
|
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.PaymentMethod", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
@ -86,7 +86,7 @@ namespace Ordering.API.Migrations
|
|||||||
|
|
||||||
b.HasIndex("CardTypeId");
|
b.HasIndex("CardTypeId");
|
||||||
|
|
||||||
b.ToTable("payments","ordering");
|
b.ToTable("paymentmethods","ordering");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Order", b =>
|
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Order", b =>
|
||||||
@ -102,11 +102,14 @@ namespace Ordering.API.Migrations
|
|||||||
b.Property<string>("City")
|
b.Property<string>("City")
|
||||||
.IsRequired();
|
.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>("PaymentId");
|
b.Property<int>("PaymentMethodId");
|
||||||
|
|
||||||
b.Property<string>("State")
|
b.Property<string>("State")
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
@ -123,7 +126,7 @@ namespace Ordering.API.Migrations
|
|||||||
|
|
||||||
b.HasIndex("OrderStatusId");
|
b.HasIndex("OrderStatusId");
|
||||||
|
|
||||||
b.HasIndex("PaymentId");
|
b.HasIndex("PaymentMethodId");
|
||||||
|
|
||||||
b.ToTable("orders","ordering");
|
b.ToTable("orders","ordering");
|
||||||
});
|
});
|
||||||
@ -139,6 +142,8 @@ namespace Ordering.API.Migrations
|
|||||||
|
|
||||||
b.Property<int>("OrderId");
|
b.Property<int>("OrderId");
|
||||||
|
|
||||||
|
b.Property<string>("PictureUrl");
|
||||||
|
|
||||||
b.Property<int>("ProductId");
|
b.Property<int>("ProductId");
|
||||||
|
|
||||||
b.Property<string>("ProductName")
|
b.Property<string>("ProductName")
|
||||||
@ -169,10 +174,10 @@ namespace Ordering.API.Migrations
|
|||||||
b.ToTable("orderstatus","ordering");
|
b.ToTable("orderstatus","ordering");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Payment", b =>
|
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.PaymentMethod", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Buyer")
|
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Buyer")
|
||||||
.WithMany("Payments")
|
.WithMany("PaymentMethods")
|
||||||
.HasForeignKey("BuyerId")
|
.HasForeignKey("BuyerId")
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
|
||||||
@ -194,9 +199,9 @@ namespace Ordering.API.Migrations
|
|||||||
.HasForeignKey("OrderStatusId")
|
.HasForeignKey("OrderStatusId")
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
|
||||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Payment", "Payment")
|
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.PaymentMethod", "PaymentMethod")
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("PaymentId");
|
.HasForeignKey("PaymentMethodId");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.OrderItem", b =>
|
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.OrderItem", b =>
|
||||||
|
@ -10,9 +10,9 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.B
|
|||||||
{
|
{
|
||||||
public string FullName { get; private set; }
|
public string FullName { get; private set; }
|
||||||
|
|
||||||
private HashSet<Payment> _payments;
|
private HashSet<PaymentMethod> _paymentMethods;
|
||||||
|
|
||||||
public IEnumerable<Payment> Payments => _payments?.ToList().AsEnumerable();
|
public IEnumerable<PaymentMethod> PaymentMethods => _paymentMethods?.ToList().AsEnumerable();
|
||||||
|
|
||||||
protected Buyer() { }
|
protected Buyer() { }
|
||||||
|
|
||||||
@ -25,12 +25,12 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.B
|
|||||||
|
|
||||||
FullName = identity;
|
FullName = identity;
|
||||||
|
|
||||||
_payments = new HashSet<Payment>();
|
_paymentMethods = new HashSet<PaymentMethod>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Payment AddPayment(int cardTypeId, string alias, string cardNumber, string securityNumber, string cardHolderName, DateTime expiration)
|
public PaymentMethod AddPaymentMethod(int cardTypeId, string alias, string cardNumber, string securityNumber, string cardHolderName, DateTime expiration)
|
||||||
{
|
{
|
||||||
var existingPayment = Payments.Where(p => p.IsEqualTo(cardTypeId, cardNumber, expiration))
|
var existingPayment = _paymentMethods.Where(p => p.IsEqualTo(cardTypeId, cardNumber, expiration))
|
||||||
.SingleOrDefault();
|
.SingleOrDefault();
|
||||||
|
|
||||||
if (existingPayment != null)
|
if (existingPayment != null)
|
||||||
@ -39,9 +39,9 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.B
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var payment = new Payment(cardTypeId, alias, cardNumber, securityNumber, cardHolderName, expiration);
|
var payment = new PaymentMethod(cardTypeId, alias, cardNumber, securityNumber, cardHolderName, expiration);
|
||||||
|
|
||||||
_payments.Add(payment);
|
_paymentMethods.Add(payment);
|
||||||
|
|
||||||
return payment;
|
return payment;
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ using System;
|
|||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate
|
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate
|
||||||
{
|
{
|
||||||
public class Payment
|
public class PaymentMethod
|
||||||
: Entity
|
: Entity
|
||||||
{
|
{
|
||||||
private int _buyerId;
|
private int _buyerId;
|
||||||
@ -17,9 +17,9 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.B
|
|||||||
public CardType CardType { get; private set; }
|
public CardType CardType { get; private set; }
|
||||||
|
|
||||||
|
|
||||||
protected Payment() { }
|
protected PaymentMethod() { }
|
||||||
|
|
||||||
public Payment(int cardTypeId, string alias, string cardNumber, string securityNumber, string cardHolderName, DateTime expiration)
|
public PaymentMethod(int cardTypeId, string alias, string cardNumber, string securityNumber, string cardHolderName, DateTime expiration)
|
||||||
{
|
{
|
||||||
if (String.IsNullOrWhiteSpace(cardNumber))
|
if (String.IsNullOrWhiteSpace(cardNumber))
|
||||||
{
|
{
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate
|
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate
|
||||||
{
|
{
|
||||||
|
|
||||||
//This is just the RepositoryContracts or Interface defined at the Domain Layer
|
//This is just the RepositoryContracts or Interface defined at the Domain Layer
|
||||||
//as requisite for the Order Aggregate
|
//as requisite for the Order Aggregate
|
||||||
public interface IOrderRepository
|
public interface IOrderRepository
|
||||||
|
@ -9,7 +9,6 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
|||||||
public class Order
|
public class Order
|
||||||
: Entity
|
: Entity
|
||||||
{
|
{
|
||||||
|
|
||||||
private string _street;
|
private string _street;
|
||||||
private string _city;
|
private string _city;
|
||||||
private string _state;
|
private string _state;
|
||||||
@ -26,16 +25,16 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
|||||||
HashSet<OrderItem> _orderItems;
|
HashSet<OrderItem> _orderItems;
|
||||||
public IEnumerable<OrderItem> OrderItems => _orderItems.ToList().AsEnumerable();
|
public IEnumerable<OrderItem> OrderItems => _orderItems.ToList().AsEnumerable();
|
||||||
|
|
||||||
public Payment Payment { get; private set; }
|
public PaymentMethod PaymentMethod { get; private set; }
|
||||||
int _paymentId;
|
int _paymentMethodId;
|
||||||
|
|
||||||
protected Order() { }
|
protected Order() { }
|
||||||
|
|
||||||
public Order(int buyerId, int paymentId, Address address)
|
public Order(int buyerId, int paymentMethodId, Address address)
|
||||||
{
|
{
|
||||||
|
|
||||||
_buyerId = buyerId;
|
_buyerId = buyerId;
|
||||||
_paymentId = paymentId;
|
_paymentMethodId = paymentMethodId;
|
||||||
_orderStatusId = OrderStatus.InProcess.Id;
|
_orderStatusId = OrderStatus.InProcess.Id;
|
||||||
_orderDate = DateTime.UtcNow;
|
_orderDate = DateTime.UtcNow;
|
||||||
_street = address.Street;
|
_street = address.Street;
|
||||||
|
@ -18,7 +18,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure
|
|||||||
|
|
||||||
public DbSet<OrderItem> OrderItems { get; set; }
|
public DbSet<OrderItem> OrderItems { get; set; }
|
||||||
|
|
||||||
public DbSet<Payment> Payments { get; set; }
|
public DbSet<PaymentMethod> Payments { get; set; }
|
||||||
|
|
||||||
public DbSet<Buyer> Buyers { get; set; }
|
public DbSet<Buyer> Buyers { get; set; }
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure
|
|||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
modelBuilder.Entity<Buyer>(ConfigureBuyer);
|
modelBuilder.Entity<Buyer>(ConfigureBuyer);
|
||||||
modelBuilder.Entity<Payment>(ConfigurePayment);
|
modelBuilder.Entity<PaymentMethod>(ConfigurePayment);
|
||||||
modelBuilder.Entity<Order>(ConfigureOrder);
|
modelBuilder.Entity<Order>(ConfigureOrder);
|
||||||
modelBuilder.Entity<OrderItem>(ConfigureOrderItems);
|
modelBuilder.Entity<OrderItem>(ConfigureOrderItems);
|
||||||
modelBuilder.Entity<CardType>(ConfigureCardTypes);
|
modelBuilder.Entity<CardType>(ConfigureCardTypes);
|
||||||
@ -54,18 +54,19 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure
|
|||||||
buyerConfiguration.HasIndex("FullName")
|
buyerConfiguration.HasIndex("FullName")
|
||||||
.IsUnique(true);
|
.IsUnique(true);
|
||||||
|
|
||||||
buyerConfiguration.HasMany(b => b.Payments)
|
buyerConfiguration.HasMany(b => b.PaymentMethods)
|
||||||
.WithOne()
|
.WithOne()
|
||||||
.HasForeignKey("BuyerId")
|
.HasForeignKey("BuyerId")
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
|
||||||
var navigation = buyerConfiguration.Metadata.FindNavigation(nameof(Buyer.Payments));
|
var navigation = buyerConfiguration.Metadata.FindNavigation(nameof(Buyer.PaymentMethods));
|
||||||
|
|
||||||
navigation.SetPropertyAccessMode(PropertyAccessMode.Field);
|
navigation.SetPropertyAccessMode(PropertyAccessMode.Field);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigurePayment(EntityTypeBuilder<Payment> paymentConfiguration)
|
void ConfigurePayment(EntityTypeBuilder<PaymentMethod> paymentConfiguration)
|
||||||
{
|
{
|
||||||
paymentConfiguration.ToTable("payments", DEFAULT_SCHEMA);
|
paymentConfiguration.ToTable("paymentmethods", DEFAULT_SCHEMA);
|
||||||
|
|
||||||
paymentConfiguration.HasKey(b => b.Id);
|
paymentConfiguration.HasKey(b => b.Id);
|
||||||
|
|
||||||
@ -112,17 +113,18 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure
|
|||||||
orderConfiguration.Property<string>("State").IsRequired();
|
orderConfiguration.Property<string>("State").IsRequired();
|
||||||
orderConfiguration.Property<string>("City").IsRequired();
|
orderConfiguration.Property<string>("City").IsRequired();
|
||||||
orderConfiguration.Property<string>("ZipCode").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>("PaymentId").IsRequired();
|
orderConfiguration.Property<int>("PaymentMethodId").IsRequired();
|
||||||
|
|
||||||
var navigation = orderConfiguration.Metadata.FindNavigation(nameof(Order.OrderItems));
|
var navigation = orderConfiguration.Metadata.FindNavigation(nameof(Order.OrderItems));
|
||||||
|
|
||||||
navigation.SetPropertyAccessMode(PropertyAccessMode.Field);
|
navigation.SetPropertyAccessMode(PropertyAccessMode.Field);
|
||||||
|
|
||||||
orderConfiguration.HasOne(o => o.Payment)
|
orderConfiguration.HasOne(o => o.PaymentMethod)
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("PaymentId")
|
.HasForeignKey("PaymentMethodId")
|
||||||
.OnDelete(DeleteBehavior.Restrict);
|
.OnDelete(DeleteBehavior.Restrict);
|
||||||
|
|
||||||
orderConfiguration.HasOne(o => o.Buyer)
|
orderConfiguration.HasOne(o => o.Buyer)
|
||||||
@ -160,6 +162,9 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure
|
|||||||
|
|
||||||
orderItemConfiguration.Property<int>("Units")
|
orderItemConfiguration.Property<int>("Units")
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
|
orderItemConfiguration.Property<string>("PictureUrl")
|
||||||
|
.IsRequired(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureOrderStatus(EntityTypeBuilder<OrderStatus> orderStatusConfiguration)
|
void ConfigureOrderStatus(EntityTypeBuilder<OrderStatus> orderStatusConfiguration)
|
||||||
|
@ -48,7 +48,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositor
|
|||||||
public async Task<Buyer> FindAsync(string identity)
|
public async Task<Buyer> FindAsync(string identity)
|
||||||
{
|
{
|
||||||
var buyer = await _context.Buyers
|
var buyer = await _context.Buyers
|
||||||
.Include(b => b.Payments)
|
.Include(b => b.PaymentMethods)
|
||||||
.Where(b => b.FullName == identity)
|
.Where(b => b.FullName == identity)
|
||||||
.SingleOrDefaultAsync();
|
.SingleOrDefaultAsync();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user