Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Payments.Core/CreateMigration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[ "$#" -eq 1 ] || { echo "1 argument required, $# provided. Useage: sh CreateMigration <MigrationName>"; exit 1; }

dotnet ef migrations add $1 --context ApplicationDbContext --output-dir Migrations --startup-project ../Payments.Mvc --project ../Payments.Core
# usage from PM console in the Payments.Core directory: ./CreateMigration.sh <MigrationName>

echo 'All done';
1 change: 1 addition & 0 deletions src/Payments.Core/Data/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ protected override void OnModelCreating(ModelBuilder builder)
LogMessage.OnModelCreating(builder);
MoneyMovementJobRecord.OnModelCreating(builder);
TaxReportJobRecord.OnModelCreating(builder);
Team.OnModelCreating(builder);
}
}
}
17 changes: 17 additions & 0 deletions src/Payments.Core/Domain/Invoice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ public string GetFormattedId()
[JsonIgnore]
public IList<PaymentEvent> PaymentEvents { get; set; }

[Required]
[StringLength(10)]
public string Type { get; set; } = InvoiceTypes.CreditCard; // CC or Recharge

// ----------------------
// Calculated Values
// ----------------------
Expand Down Expand Up @@ -234,6 +238,13 @@ protected internal static void OnModelCreating(ModelBuilder builder)
builder.Entity<Invoice>()
.Property(i => i.CalculatedTotal)
.HasColumnType("decimal(18,2)");

// Set default value for Type column
builder.Entity<Invoice>()
.Property(i => i.Type)
.HasDefaultValue(InvoiceTypes.CreditCard);

builder.Entity<Invoice>().HasIndex(a => a.Type);
}

public Dictionary<string, string> GetPaymentDictionary()
Expand Down Expand Up @@ -320,5 +331,11 @@ public static string GetBadgeClass(string status)
}
}
}

public static class InvoiceTypes
{
public const string CreditCard = "CC";
public const string Recharge = "Recharge";
}
}
}
26 changes: 25 additions & 1 deletion src/Payments.Core/Domain/Team.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using Newtonsoft.Json;

namespace Payments.Core.Domain
{
Expand Down Expand Up @@ -71,6 +72,10 @@ public Team()
[StringLength(128)]
public string WebHookApiKey { get; set; }

[Required]
[StringLength(10)]
public string AllowedInvoiceType { get; set; } = AllowedInvoiceTypes.CreditCard;

[NotMapped]
public FinancialAccount DefaultAccount {
get {
Expand All @@ -91,5 +96,24 @@ public TeamPermission AddPermission(User user, TeamRole role)

return permission;
}

protected internal static void OnModelCreating(ModelBuilder builder)
{
builder.Entity<Team>()
.Property(t => t.AllowedInvoiceType)
.HasMaxLength(10)
.HasDefaultValue(AllowedInvoiceTypes.CreditCard);
}

/// <summary>
/// These are a superset of the Invoice.Types
/// (Adds Both value)
/// </summary>
public static class AllowedInvoiceTypes
{
public const string CreditCard = "CC";
public const string Recharge = "Recharge";
public const string Both = "Both";
}
}
}
4 changes: 4 additions & 0 deletions src/Payments.Core/ExecuteMigration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dotnet ef database update --startup-project ../Payments.Mvc/Payments.Mvc.csproj --context ApplicationDbContext
# usage from PM console in the Payments.Core directory: ./ExecuteMigration.sh

echo 'All done';
Loading