Added field "Alias" to PaymentMethod and created EF migration for that
Refactoring related to OrderCommand (instead NewOrderCommand) Refactoring in Buyer.IdentityGuid instead of fullname variables..
This commit is contained in:
parent
57ae6ab3be
commit
2babf6e4fe
@ -10,10 +10,10 @@
|
|||||||
//Need to create a different DTO class, like OrderLineDTO or similar...
|
//Need to create a different DTO class, like OrderLineDTO or similar...
|
||||||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
|
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
|
||||||
|
|
||||||
public class NewOrderCommand
|
public class CreateOrderCommand
|
||||||
:IAsyncRequest<bool>
|
:IAsyncRequest<bool>
|
||||||
{
|
{
|
||||||
//(CDLTLL) TO DO: This is wrong, we must NOT use a child-entity class within a Command class!!
|
//(CDLTLL) TO DO: This is wrong, we must NOT use a child-entity class (OrderItem) within a Command class!!
|
||||||
//Need to create a different DTO class, like OrderLineDTO or similar...
|
//Need to create a different DTO class, like OrderLineDTO or similar...
|
||||||
private readonly List<OrderItem> _orderItems;
|
private readonly List<OrderItem> _orderItems;
|
||||||
public string City { get; set; }
|
public string City { get; set; }
|
||||||
@ -36,7 +36,7 @@
|
|||||||
|
|
||||||
public int CardTypeId { get; set; }
|
public int CardTypeId { get; set; }
|
||||||
|
|
||||||
public string Buyer { get; set; }
|
public string BuyerIdentityGuid { get; set; }
|
||||||
|
|
||||||
public IEnumerable<OrderItem> OrderItems => _orderItems;
|
public IEnumerable<OrderItem> OrderItems => _orderItems;
|
||||||
|
|
||||||
@ -45,7 +45,7 @@
|
|||||||
_orderItems.Add(item);
|
_orderItems.Add(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NewOrderCommand()
|
public CreateOrderCommand()
|
||||||
{
|
{
|
||||||
_orderItems = new List<OrderItem>();
|
_orderItems = new List<OrderItem>();
|
||||||
}
|
}
|
@ -9,13 +9,13 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Domain;
|
using Domain;
|
||||||
|
|
||||||
public class NewOrderCommandHandler
|
public class CreateOrderCommandHandler
|
||||||
: IAsyncRequestHandler<NewOrderCommand, bool>
|
: IAsyncRequestHandler<CreateOrderCommand, bool>
|
||||||
{
|
{
|
||||||
private readonly IBuyerRepository _buyerRepository;
|
private readonly IBuyerRepository _buyerRepository;
|
||||||
private readonly IOrderRepository _orderRepository;
|
private readonly IOrderRepository _orderRepository;
|
||||||
|
|
||||||
public NewOrderCommandHandler(IBuyerRepository buyerRepository,IOrderRepository orderRepository)
|
public CreateOrderCommandHandler(IBuyerRepository buyerRepository,IOrderRepository orderRepository)
|
||||||
{
|
{
|
||||||
if (buyerRepository == null)
|
if (buyerRepository == null)
|
||||||
{
|
{
|
||||||
@ -30,11 +30,11 @@
|
|||||||
_buyerRepository = buyerRepository;
|
_buyerRepository = buyerRepository;
|
||||||
_orderRepository = orderRepository;
|
_orderRepository = orderRepository;
|
||||||
}
|
}
|
||||||
public async Task<bool> Handle(NewOrderCommand message)
|
public async Task<bool> Handle(CreateOrderCommand message)
|
||||||
{
|
{
|
||||||
//find buyer/payment or add a new one buyer/payment
|
//find buyer/payment or add a new one buyer/payment
|
||||||
|
|
||||||
var buyer = await _buyerRepository.FindAsync(message.Buyer);
|
var buyer = await _buyerRepository.FindAsync(message.BuyerIdentityGuid);
|
||||||
|
|
||||||
if (buyer == null)
|
if (buyer == null)
|
||||||
{
|
{
|
||||||
@ -70,9 +70,32 @@
|
|||||||
return result > 0;
|
return result > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Buyer CreateBuyer(CreateOrderCommand message)
|
||||||
|
{
|
||||||
|
return _buyerRepository.Add(
|
||||||
|
new Buyer(message.BuyerIdentityGuid));
|
||||||
|
}
|
||||||
|
|
||||||
|
Order CreateOrder(int buyerId, int paymentId, int addressId)
|
||||||
|
{
|
||||||
|
return new Order(buyerId, paymentId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Payment GetExistingPaymentOrAddANewOne(Buyer buyer, NewOrderCommand message)
|
//TO DO:
|
||||||
|
//(CDLTLL) This is wrong. We shouldn't be able to create a PaymentMethod from a CommandHandler or anywhere in the Application Layer
|
||||||
|
//because a PaymentMethod is a child-entity, part of the Buyer Aggregate.
|
||||||
|
//So, any creation/update of a PaymentMethod should be done through its Aggregate-Root: the Buyer root entity.
|
||||||
|
//Need to move this logic to the Buyer Aggregate-Root and rename to "AddPaymentMethod()"
|
||||||
|
Payment CreatePayment(CreateOrderCommand message)
|
||||||
|
{
|
||||||
|
return new Payment("My Default Payment Method", message.CardNumber, message.CardSecurityNumber, message.CardHolderName, message.CardExpiration, message.CardTypeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
//TO DO:
|
||||||
|
//(CDLTLL) This is wrong. As explained, this logic should be part of the
|
||||||
|
//Buyer Aggregate Root, as a PaymentMethod is a child-entity of that Aggregate.
|
||||||
|
Payment GetExistingPaymentOrAddANewOne(Buyer buyer, CreateOrderCommand message)
|
||||||
{
|
{
|
||||||
Payment payment = PaymentAlreadyExist(buyer, message);
|
Payment payment = PaymentAlreadyExist(buyer, message);
|
||||||
|
|
||||||
@ -86,7 +109,10 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Payment PaymentAlreadyExist(Buyer buyer, NewOrderCommand message)
|
//TO DO:
|
||||||
|
//(CDLTLL) This is wrong. As explained, this logic should be part of the
|
||||||
|
//Buyer Aggregate Root, as a PaymentMethod is a child-entity of that Aggregate.
|
||||||
|
Payment PaymentAlreadyExist(Buyer buyer, CreateOrderCommand message)
|
||||||
{
|
{
|
||||||
return buyer.Payments
|
return buyer.Payments
|
||||||
.SingleOrDefault(p =>
|
.SingleOrDefault(p =>
|
||||||
@ -100,21 +126,5 @@
|
|||||||
p.SecurityNumber == message.CardSecurityNumber;
|
p.SecurityNumber == message.CardSecurityNumber;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Buyer CreateBuyer(NewOrderCommand message)
|
|
||||||
{
|
|
||||||
return _buyerRepository.Add(
|
|
||||||
new Buyer(message.Buyer));
|
|
||||||
}
|
|
||||||
|
|
||||||
Order CreateOrder(int buyerId, int paymentId, int addressId)
|
|
||||||
{
|
|
||||||
return new Order(buyerId, paymentId);
|
|
||||||
}
|
|
||||||
|
|
||||||
Payment CreatePayment(NewOrderCommand message)
|
|
||||||
{
|
|
||||||
return new Payment(message.CardNumber, message.CardSecurityNumber, message.CardHolderName, message.CardExpiration, message.CardTypeId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -43,14 +43,14 @@
|
|||||||
|
|
||||||
[Route("new")]
|
[Route("new")]
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IActionResult> AddOrder([FromBody]NewOrderCommand order)
|
public async Task<IActionResult> AddOrder([FromBody]CreateOrderCommand createOrderCommand)
|
||||||
{
|
{
|
||||||
if (order.CardTypeId == 0)
|
if (createOrderCommand.CardTypeId == 0)
|
||||||
order.CardTypeId = 1;
|
createOrderCommand.CardTypeId = 1;
|
||||||
|
|
||||||
order.Buyer = _identityService.GetUserIdentity();
|
createOrderCommand.BuyerIdentityGuid = _identityService.GetUserIdentity();
|
||||||
|
|
||||||
var added = await _mediator.SendAsync(order);
|
var added = await _mediator.SendAsync(createOrderCommand);
|
||||||
if (added)
|
if (added)
|
||||||
{
|
{
|
||||||
return Ok();
|
return Ok();
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
builder.RegisterAssemblyTypes(typeof(IMediator).GetTypeInfo().Assembly)
|
builder.RegisterAssemblyTypes(typeof(IMediator).GetTypeInfo().Assembly)
|
||||||
.AsImplementedInterfaces();
|
.AsImplementedInterfaces();
|
||||||
|
|
||||||
builder.RegisterAssemblyTypes(typeof(NewOrderCommand).GetTypeInfo().Assembly)
|
builder.RegisterAssemblyTypes(typeof(CreateOrderCommand).GetTypeInfo().Assembly)
|
||||||
.As(o => o.GetInterfaces()
|
.As(o => o.GetInterfaces()
|
||||||
.Where(i => i.IsClosedTypeOf(typeof(IAsyncRequestHandler<,>)))
|
.Where(i => i.IsClosedTypeOf(typeof(IAsyncRequestHandler<,>)))
|
||||||
.Select(i => new KeyedService("IAsyncRequestHandler", i)));
|
.Select(i => new KeyedService("IAsyncRequestHandler", i)));
|
||||||
|
@ -0,0 +1,233 @@
|
|||||||
|
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.Infrastructure.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(OrderingContext))]
|
||||||
|
[Migration("20170118230807_PaymentMethodWithAlias")]
|
||||||
|
partial class PaymentMethodWithAlias
|
||||||
|
{
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "1.0.1")
|
||||||
|
.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()
|
||||||
|
.HasAnnotation("MaxLength", 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")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasDefaultValue(1);
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasAnnotation("MaxLength", 200);
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("cardtypes","ordering");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Payment", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasAnnotation("SqlServer:HiLoSequenceName", "paymentseq")
|
||||||
|
.HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering")
|
||||||
|
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
|
||||||
|
|
||||||
|
b.Property<string>("Alias")
|
||||||
|
.IsRequired()
|
||||||
|
.HasAnnotation("MaxLength", 200);
|
||||||
|
|
||||||
|
b.Property<int>("BuyerId");
|
||||||
|
|
||||||
|
b.Property<string>("CardHolderName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasAnnotation("MaxLength", 200);
|
||||||
|
|
||||||
|
b.Property<string>("CardNumber")
|
||||||
|
.IsRequired()
|
||||||
|
.HasAnnotation("MaxLength", 25);
|
||||||
|
|
||||||
|
b.Property<int>("CardTypeId");
|
||||||
|
|
||||||
|
b.Property<DateTime>("Expiration");
|
||||||
|
|
||||||
|
b.Property<string>("SecurityNumber");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("BuyerId");
|
||||||
|
|
||||||
|
b.HasIndex("CardTypeId");
|
||||||
|
|
||||||
|
b.ToTable("payments","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 =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasAnnotation("SqlServer:HiLoSequenceName", "orderseq")
|
||||||
|
.HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering")
|
||||||
|
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
|
||||||
|
|
||||||
|
b.Property<int>("BuyerId");
|
||||||
|
|
||||||
|
b.Property<DateTime>("OrderDate");
|
||||||
|
|
||||||
|
b.Property<int>("PaymentId");
|
||||||
|
|
||||||
|
b.Property<int?>("ShippingAddressId");
|
||||||
|
|
||||||
|
b.Property<int>("StatusId");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("BuyerId");
|
||||||
|
|
||||||
|
b.HasIndex("PaymentId");
|
||||||
|
|
||||||
|
b.HasIndex("ShippingAddressId");
|
||||||
|
|
||||||
|
b.HasIndex("StatusId");
|
||||||
|
|
||||||
|
b.ToTable("orders","ordering");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.OrderItem", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
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")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasAnnotation("SqlServer:DefaultValue", 1);
|
||||||
|
|
||||||
|
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")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasDefaultValue(1);
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasAnnotation("MaxLength", 200);
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("orderstatus","ordering");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Payment", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Buyer")
|
||||||
|
.WithMany("Payments")
|
||||||
|
.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.BuyerAggregate.Payment", "Payment")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("PaymentId");
|
||||||
|
|
||||||
|
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Address", "ShippingAddress")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("ShippingAddressId");
|
||||||
|
|
||||||
|
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.OrderStatus", "Status")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("StatusId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
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,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
namespace Ordering.API.Infrastructure.Migrations
|
||||||
|
{
|
||||||
|
public partial class PaymentMethodWithAlias : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "Alias",
|
||||||
|
schema: "ordering",
|
||||||
|
table: "payments",
|
||||||
|
maxLength: 200,
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: "");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "Alias",
|
||||||
|
schema: "ordering",
|
||||||
|
table: "payments");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -19,27 +19,7 @@ namespace Ordering.API.Infrastructure.Migrations
|
|||||||
.HasAnnotation("SqlServer:Sequence:ordering.paymentseq", "'paymentseq', 'ordering', '1', '10', '', '', 'Int64', 'False'")
|
.HasAnnotation("SqlServer:Sequence:ordering.paymentseq", "'paymentseq', 'ordering', '1', '10', '', '', 'Int64', 'False'")
|
||||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Address", b =>
|
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Buyer", 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.Buyer", b =>
|
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
@ -59,7 +39,7 @@ namespace Ordering.API.Infrastructure.Migrations
|
|||||||
b.ToTable("buyers","ordering");
|
b.ToTable("buyers","ordering");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.CardType", b =>
|
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.CardType", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
@ -74,7 +54,64 @@ namespace Ordering.API.Infrastructure.Migrations
|
|||||||
b.ToTable("cardtypes","ordering");
|
b.ToTable("cardtypes","ordering");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Order", b =>
|
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Payment", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasAnnotation("SqlServer:HiLoSequenceName", "paymentseq")
|
||||||
|
.HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering")
|
||||||
|
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
|
||||||
|
|
||||||
|
b.Property<string>("Alias")
|
||||||
|
.IsRequired()
|
||||||
|
.HasAnnotation("MaxLength", 200);
|
||||||
|
|
||||||
|
b.Property<int>("BuyerId");
|
||||||
|
|
||||||
|
b.Property<string>("CardHolderName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasAnnotation("MaxLength", 200);
|
||||||
|
|
||||||
|
b.Property<string>("CardNumber")
|
||||||
|
.IsRequired()
|
||||||
|
.HasAnnotation("MaxLength", 25);
|
||||||
|
|
||||||
|
b.Property<int>("CardTypeId");
|
||||||
|
|
||||||
|
b.Property<DateTime>("Expiration");
|
||||||
|
|
||||||
|
b.Property<string>("SecurityNumber");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("BuyerId");
|
||||||
|
|
||||||
|
b.HasIndex("CardTypeId");
|
||||||
|
|
||||||
|
b.ToTable("payments","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 =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
@ -105,7 +142,7 @@ namespace Ordering.API.Infrastructure.Migrations
|
|||||||
b.ToTable("orders","ordering");
|
b.ToTable("orders","ordering");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.OrderItem", b =>
|
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.OrderItem", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd();
|
.ValueGeneratedOnAdd();
|
||||||
@ -114,6 +151,8 @@ namespace Ordering.API.Infrastructure.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")
|
||||||
@ -132,7 +171,7 @@ namespace Ordering.API.Infrastructure.Migrations
|
|||||||
b.ToTable("orderItems","ordering");
|
b.ToTable("orderItems","ordering");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.OrderStatus", b =>
|
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.OrderStatus", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
@ -147,80 +186,47 @@ namespace Ordering.API.Infrastructure.Migrations
|
|||||||
b.ToTable("orderstatus","ordering");
|
b.ToTable("orderstatus","ordering");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Payment", b =>
|
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Payment", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Buyer")
|
||||||
.ValueGeneratedOnAdd()
|
.WithMany("Payments")
|
||||||
.HasAnnotation("SqlServer:HiLoSequenceName", "paymentseq")
|
.HasForeignKey("BuyerId")
|
||||||
.HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering")
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
|
|
||||||
|
|
||||||
b.Property<int>("BuyerId");
|
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.CardType", "CardType")
|
||||||
|
.WithMany()
|
||||||
b.Property<string>("CardHolderName")
|
.HasForeignKey("CardTypeId")
|
||||||
.IsRequired()
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
.HasAnnotation("MaxLength", 200);
|
|
||||||
|
|
||||||
b.Property<string>("CardNumber")
|
|
||||||
.IsRequired()
|
|
||||||
.HasAnnotation("MaxLength", 25);
|
|
||||||
|
|
||||||
b.Property<int>("CardTypeId");
|
|
||||||
|
|
||||||
b.Property<DateTime>("Expiration");
|
|
||||||
|
|
||||||
b.Property<string>("SecurityNumber");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.HasIndex("BuyerId");
|
|
||||||
|
|
||||||
b.HasIndex("CardTypeId");
|
|
||||||
|
|
||||||
b.ToTable("payments","ordering");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Order", b =>
|
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Order", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Buyer", "Buyer")
|
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Buyer", "Buyer")
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("BuyerId")
|
.HasForeignKey("BuyerId")
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
|
||||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Payment", "Payment")
|
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Payment", "Payment")
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("PaymentId");
|
.HasForeignKey("PaymentId");
|
||||||
|
|
||||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Address", "ShippingAddress")
|
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Address", "ShippingAddress")
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("ShippingAddressId");
|
.HasForeignKey("ShippingAddressId");
|
||||||
|
|
||||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.OrderStatus", "Status")
|
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.OrderStatus", "Status")
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("StatusId")
|
.HasForeignKey("StatusId")
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.OrderItem", b =>
|
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.OrderItem", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Order")
|
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Order")
|
||||||
.WithMany("OrderItems")
|
.WithMany("OrderItems")
|
||||||
.HasForeignKey("OrderId")
|
.HasForeignKey("OrderId")
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Payment", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Buyer")
|
|
||||||
.WithMany("Payments")
|
|
||||||
.HasForeignKey("BuyerId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
|
||||||
|
|
||||||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.CardType", "CardType")
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("CardTypeId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,14 +13,14 @@
|
|||||||
|
|
||||||
protected Buyer() { }
|
protected Buyer() { }
|
||||||
|
|
||||||
public Buyer(string fullName)
|
public Buyer(string IdentityGuid)
|
||||||
{
|
{
|
||||||
if (String.IsNullOrWhiteSpace(fullName))
|
if (String.IsNullOrWhiteSpace(IdentityGuid))
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(fullName));
|
throw new ArgumentNullException(nameof(IdentityGuid));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.FullName = fullName;
|
this.FullName = IdentityGuid;
|
||||||
this.Payments = new HashSet<Payment>();
|
this.Payments = new HashSet<Payment>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
public class Payment
|
public class Payment
|
||||||
: Entity
|
: Entity
|
||||||
{
|
{
|
||||||
|
public string Alias { get; private set; }
|
||||||
public int BuyerId { get; private set; }
|
public int BuyerId { get; private set; }
|
||||||
|
|
||||||
public string CardNumber { get; private set; }
|
public string CardNumber { get; private set; }
|
||||||
@ -23,7 +24,7 @@
|
|||||||
|
|
||||||
protected Payment() { }
|
protected Payment() { }
|
||||||
|
|
||||||
public Payment(string cardNumber, string securityNumber, string cardHolderName, DateTime expiration, int cardTypeId)
|
public Payment(string alias, string cardNumber, string securityNumber, string cardHolderName, DateTime expiration, int cardTypeId)
|
||||||
{
|
{
|
||||||
if (String.IsNullOrWhiteSpace(cardNumber))
|
if (String.IsNullOrWhiteSpace(cardNumber))
|
||||||
{
|
{
|
||||||
@ -45,6 +46,7 @@
|
|||||||
throw new ArgumentException(nameof(expiration));
|
throw new ArgumentException(nameof(expiration));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.Alias = alias;
|
||||||
this.CardNumber = cardNumber;
|
this.CardNumber = cardNumber;
|
||||||
this.SecurityNumber = securityNumber;
|
this.SecurityNumber = securityNumber;
|
||||||
this.CardHolderName = cardHolderName;
|
this.CardHolderName = cardHolderName;
|
||||||
|
@ -9,6 +9,6 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.RepositoryContrac
|
|||||||
{
|
{
|
||||||
Buyer Add(Buyer buyer);
|
Buyer Add(Buyer buyer);
|
||||||
|
|
||||||
Task<Buyer> FindAsync(string name);
|
Task<Buyer> FindAsync(string BuyerIdentityGuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,10 @@
|
|||||||
.HasMaxLength(200)
|
.HasMaxLength(200)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
|
paymentConfiguration.Property(p => p.Alias)
|
||||||
|
.HasMaxLength(200)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
paymentConfiguration.Property(p => p.CardNumber)
|
paymentConfiguration.Property(p => p.CardNumber)
|
||||||
.HasMaxLength(25)
|
.HasMaxLength(25)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
@ -39,11 +39,11 @@
|
|||||||
.Entity;
|
.Entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Buyer> FindAsync(string name)
|
public async Task<Buyer> FindAsync(string BuyerIdentityGuid)
|
||||||
{
|
{
|
||||||
var buyer = await _context.Buyers
|
var buyer = await _context.Buyers
|
||||||
.Include(b => b.Payments)
|
.Include(b => b.Payments)
|
||||||
.Where(b => b.FullName == name)
|
.Where(b => b.FullName == BuyerIdentityGuid)
|
||||||
.SingleOrDefaultAsync();
|
.SingleOrDefaultAsync();
|
||||||
|
|
||||||
return buyer;
|
return buyer;
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
public async Task Handle_returns_true_when_order_is_persisted_succesfully()
|
public async Task Handle_returns_true_when_order_is_persisted_succesfully()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
_buyerRepositoryMock.Setup(buyerRepo => buyerRepo.FindAsync(FakeOrderRequestWithBuyer().Buyer))
|
_buyerRepositoryMock.Setup(buyerRepo => buyerRepo.FindAsync(FakeOrderRequestWithBuyer().BuyerIdentityGuid))
|
||||||
.Returns(Task.FromResult<Buyer>(FakeBuyer()));
|
.Returns(Task.FromResult<Buyer>(FakeBuyer()));
|
||||||
|
|
||||||
_buyerRepositoryMock.Setup(buyerRepo => buyerRepo.UnitOfWork.SaveChangesAsync(default(CancellationToken)))
|
_buyerRepositoryMock.Setup(buyerRepo => buyerRepo.UnitOfWork.SaveChangesAsync(default(CancellationToken)))
|
||||||
@ -39,7 +39,7 @@
|
|||||||
.Returns(Task.FromResult(1));
|
.Returns(Task.FromResult(1));
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
var handler = new NewOrderCommandHandler(_buyerRepositoryMock.Object, _orderRepositoryMock.Object);
|
var handler = new CreateOrderCommandHandler(_buyerRepositoryMock.Object, _orderRepositoryMock.Object);
|
||||||
var result = await handler.Handle(FakeOrderRequestWithBuyer());
|
var result = await handler.Handle(FakeOrderRequestWithBuyer());
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
@ -49,7 +49,7 @@
|
|||||||
[Fact]
|
[Fact]
|
||||||
public async Task Handle_return_false_if_order_is_not_persisted()
|
public async Task Handle_return_false_if_order_is_not_persisted()
|
||||||
{
|
{
|
||||||
_buyerRepositoryMock.Setup(buyerRepo => buyerRepo.FindAsync(FakeOrderRequestWithBuyer().Buyer))
|
_buyerRepositoryMock.Setup(buyerRepo => buyerRepo.FindAsync(FakeOrderRequestWithBuyer().BuyerIdentityGuid))
|
||||||
.Returns(Task.FromResult<Buyer>(FakeBuyer()));
|
.Returns(Task.FromResult<Buyer>(FakeBuyer()));
|
||||||
|
|
||||||
_buyerRepositoryMock.Setup(buyerRepo => buyerRepo.UnitOfWork.SaveChangesAsync(default(CancellationToken)))
|
_buyerRepositoryMock.Setup(buyerRepo => buyerRepo.UnitOfWork.SaveChangesAsync(default(CancellationToken)))
|
||||||
@ -60,7 +60,7 @@
|
|||||||
.Returns(Task.FromResult(0));
|
.Returns(Task.FromResult(0));
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
var handler = new NewOrderCommandHandler(_buyerRepositoryMock.Object, _orderRepositoryMock.Object);
|
var handler = new CreateOrderCommandHandler(_buyerRepositoryMock.Object, _orderRepositoryMock.Object);
|
||||||
var result = await handler.Handle(FakeOrderRequestWithBuyer());
|
var result = await handler.Handle(FakeOrderRequestWithBuyer());
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
@ -80,11 +80,11 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private NewOrderCommand FakeOrderRequestWithBuyer()
|
private CreateOrderCommand FakeOrderRequestWithBuyer()
|
||||||
{
|
{
|
||||||
return new NewOrderCommand
|
return new CreateOrderCommand
|
||||||
{
|
{
|
||||||
Buyer = "1234",
|
BuyerIdentityGuid = "1234",
|
||||||
CardNumber = "1234",
|
CardNumber = "1234",
|
||||||
CardExpiration = DateTime.Now.AddYears(1),
|
CardExpiration = DateTime.Now.AddYears(1),
|
||||||
CardSecurityNumber = "123",
|
CardSecurityNumber = "123",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user