Browse Source

Added PaymentRequest aggregate root and mapped to EF Core

pull/69/head
Halil İbrahim Kalkan 5 years ago
parent
commit
e3b50eefff
  1. 8
      modules/payment/src/Payment.Domain.Shared/PaymentRequests/PaymentRequestConsts.cs
  2. 9
      modules/payment/src/Payment.Domain.Shared/PaymentRequests/PaymentRequestState.cs
  3. 2
      modules/payment/src/Payment.Domain/PaymentDbProperties.cs
  4. 33
      modules/payment/src/Payment.Domain/PaymentRequests/PaymentRequest.cs
  5. 8
      modules/payment/src/Payment.EntityFrameworkCore/EntityFrameworkCore/IPaymentDbContext.cs
  6. 5
      modules/payment/src/Payment.EntityFrameworkCore/EntityFrameworkCore/PaymentDbContext.cs
  7. 23
      modules/payment/src/Payment.EntityFrameworkCore/EntityFrameworkCore/PaymentDbContextModelCreatingExtensions.cs

8
modules/payment/src/Payment.Domain.Shared/PaymentRequests/PaymentRequestConsts.cs

@ -0,0 +1,8 @@
namespace Payment.PaymentRequests
{
public static class PaymentRequestConsts
{
public const int MaxProductIdLength = 100;
public const int MaxProductNameLength = 200;
}
}

9
modules/payment/src/Payment.Domain.Shared/PaymentRequests/PaymentRequestState.cs

@ -0,0 +1,9 @@
namespace Payment.PaymentRequests
{
public enum PaymentRequestState : byte
{
Waiting = 0,
Completed,
Failed
}
}

2
modules/payment/src/Payment.Domain/PaymentDbProperties.cs

@ -2,7 +2,7 @@
{
public static class PaymentDbProperties
{
public static string DbTablePrefix { get; set; } = "Payment";
public static string DbTablePrefix { get; set; } = "Pay";
public static string DbSchema { get; set; } = null;

33
modules/payment/src/Payment.Domain/PaymentRequests/PaymentRequest.cs

@ -0,0 +1,33 @@
using System;
using JetBrains.Annotations;
using Volo.Abp;
using Volo.Abp.Domain.Entities.Auditing;
namespace Payment.PaymentRequests
{
public class PaymentRequest : CreationAuditedAggregateRoot<Guid>
{
public string CustomerId { get; private set; }
public string ProductId { get; private set; }
[NotNull]
public string ProductName { get; private set; }
public decimal Amount { get; private set; }
public PaymentRequestState State { get; set; }
public PaymentRequest(
Guid id,
[NotNull] string productName,
[CanBeNull] string productId,
decimal amount)
: base(id)
{
ProductName = Check.NotNullOrWhiteSpace(productName, nameof(productName));
ProductId = productId;
Amount = amount;
}
}
}

8
modules/payment/src/Payment.EntityFrameworkCore/EntityFrameworkCore/IPaymentDbContext.cs

@ -1,4 +1,6 @@
using Volo.Abp.Data;
using Microsoft.EntityFrameworkCore;
using Payment.PaymentRequests;
using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;
namespace Payment.EntityFrameworkCore
@ -6,8 +8,6 @@ namespace Payment.EntityFrameworkCore
[ConnectionStringName(PaymentDbProperties.ConnectionStringName)]
public interface IPaymentDbContext : IEfCoreDbContext
{
/* Add DbSet for each Aggregate Root here. Example:
* DbSet<Question> Questions { get; }
*/
DbSet<PaymentRequest> PaymentRequests { get; }
}
}

5
modules/payment/src/Payment.EntityFrameworkCore/EntityFrameworkCore/PaymentDbContext.cs

@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore;
using Payment.PaymentRequests;
using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;
@ -7,9 +8,7 @@ namespace Payment.EntityFrameworkCore
[ConnectionStringName(PaymentDbProperties.ConnectionStringName)]
public class PaymentDbContext : AbpDbContext<PaymentDbContext>, IPaymentDbContext
{
/* Add DbSet for each Aggregate Root here. Example:
* public DbSet<Question> Questions { get; set; }
*/
public DbSet<PaymentRequest> PaymentRequests { get; set; }
public PaymentDbContext(DbContextOptions<PaymentDbContext> options)
: base(options)

23
modules/payment/src/Payment.EntityFrameworkCore/EntityFrameworkCore/PaymentDbContextModelCreatingExtensions.cs

@ -1,5 +1,7 @@
using Microsoft.EntityFrameworkCore;
using Payment.PaymentRequests;
using Volo.Abp;
using Volo.Abp.EntityFrameworkCore.Modeling;
namespace Payment.EntityFrameworkCore
{
@ -10,25 +12,16 @@ namespace Payment.EntityFrameworkCore
{
Check.NotNull(builder, nameof(builder));
/* Configure all entities here. Example:
builder.Entity<Question>(b =>
builder.Entity<PaymentRequest>(b =>
{
//Configure table & schema name
b.ToTable(PaymentDbProperties.DbTablePrefix + "Questions", PaymentDbProperties.DbSchema);
b.ToTable(PaymentDbProperties.DbTablePrefix + "PaymentRequests", PaymentDbProperties.DbSchema);
b.ConfigureByConvention();
b.Property(x => x.ProductName).IsRequired().HasMaxLength(PaymentRequestConsts.MaxProductNameLength);
b.Property(x => x.ProductId).IsRequired().HasMaxLength(PaymentRequestConsts.MaxProductIdLength);
//Properties
b.Property(q => q.Title).IsRequired().HasMaxLength(QuestionConsts.MaxTitleLength);
//Relations
b.HasMany(question => question.Tags).WithOne().HasForeignKey(qt => qt.QuestionId);
//Indexes
b.HasIndex(q => q.CreationTime);
b.HasIndex(x => x.CustomerId);
b.HasIndex(x => x.State);
});
*/
}
}
}

Loading…
Cancel
Save