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
75 changes: 66 additions & 9 deletions .github/workflows/createrelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@ jobs:
run: |
dotnet restore TransactionProcessor.HealthChecksUI/TransactionProcessor.HealthChecksUI.sln --source ${{ secrets.PUBLICFEEDURL }} --source ${{ secrets.PRIVATEFEED_URL }}
dotnet restore TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.sln --source ${{ secrets.PUBLICFEEDURL }} --source ${{ secrets.PRIVATEFEED_URL }}
dotnet restore TransactionProcessing.MerchantPos/TransactionProcessing.MerchantPos.sln --source ${{ secrets.PUBLICFEEDURL }} --source ${{ secrets.PRIVATEFEED_URL }}

- name: Build Code
run: |
dotnet build TransactionProcessor.HealthChecksUI/TransactionProcessor.HealthChecksUI.sln --configuration Release
dotnet build TransactionProcessor.MerchantPos/TransactionProcessor.MerchantPos.sln --configuration Release

- name: Publish API
run: |
dotnet publish "TransactionProcessor.HealthChecksUI/TransactionProcessor.HealthChecksUI/TransactionProcessor.HealthChecksUI.csproj" --configuration Release --output TransactionProcessor.HealthChecksUI/publishOutput -r win-x64 --self-contained

dotnet publish "TransactionProcessor.MerchantPos/TransactionProcessor.MerchantPos/TransactionProcessor.MerchantPos.csproj" --configuration Release --output TransactionProcessor.MerchantPos/publishOutput -r win-x64 --self-contained

- name: Build Release Package (Health Check UI)
run: |
cd /home/runner/work/SupportTools/SupportTools/TransactionProcessor.HealthChecksUI/publishOutput
Expand All @@ -48,6 +51,18 @@ jobs:
with:
name: healthchecksui
path: /home/runner/work/SupportTools/SupportTools/TransactionProcessor.HealthChecksUI/healthchecksui.zip

- name: Build Release Package (Merchant Pos)
run: |
cd /home/runner/work/SupportTools/SupportTools/TransactionProcessor.MerchantPos/publishOutput
zip -r ../merchantpos.zip ./*
echo "Zip file created at: $(realpath ../merchantpos.zip)"

- name: Upload the artifact (Merchant Pos)
uses: actions/upload-artifact@v4.4.0
with:
name: merchantpos
path: /home/runner/work/SupportTools/SupportTools/TransactionProcessor.MerchantPos/merchantpos.zip

deploystaging:
runs-on: [stagingserver, windows]
Expand All @@ -61,7 +76,7 @@ jobs:
with:
name: healthchecksui

- name: Remove existing Windows service
- name: Remove existing Windows service (Health Check UI)
run: |
$serviceName = "Transaction Processing - Health Checks UI"
# Check if the service exists
Expand All @@ -70,18 +85,39 @@ jobs:
sc.exe delete $serviceName
}

- name: Unzip the files
- name: Unzip the files (Health Check UI)
run: |
Expand-Archive -Path healthchecksui.zip -DestinationPath "C:\txnproc\transactionprocessing\healthchecksui" -Force

- name: Install as a Windows service
- name: Install as a Windows service (Health Check UI)
run: |
$serviceName = "Transaction Processing - Health Checks UI"
$servicePath = "C:\txnproc\transactionprocessing\healthchecksui\TransactionProcessor.HealthChecksUI.exe"

New-Service -Name $serviceName -BinaryPathName $servicePath -Description $serviceName -DisplayName $serviceName -StartupType Automatic
Start-Service -Name $serviceName
Start-Service -Name $serviceName

- name: Remove existing Windows service (Merchant Pos)
run: |
$serviceName = "Transaction Processing - Merchant Pos"
# Check if the service exists
if (Get-Service -Name $serviceName -ErrorAction SilentlyContinue) {
Stop-Service -Name $serviceName
sc.exe delete $serviceName
}

- name: Unzip the files (Merchant Pos)
run: |
Expand-Archive -Path merchantpos.zip -DestinationPath "C:\txnproc\transactionprocessing\merchantpos" -Force

- name: Install as a Windows service (Merchant Pos)
run: |
$serviceName = "Transaction Processing - Merchant Pos"
$servicePath = "C:\txnproc\transactionprocessing\merchantpos\TransactionProcessor.MerchantPos.exe"

New-Service -Name $serviceName -BinaryPathName $servicePath -Description $serviceName -DisplayName $serviceName -StartupType Automatic
Start-Service -Name $serviceName

deployproduction:
runs-on: [productionserver, windows]
needs: [build, deploystaging]
Expand All @@ -94,7 +130,7 @@ jobs:
with:
name: healthchecksui

- name: Remove existing Windows service
- name: Remove existing Windows service (Health Check UI)
run: |
$serviceName = "Transaction Processing - Health Checks UI"
# Check if the service exists
Expand All @@ -103,14 +139,35 @@ jobs:
sc.exe delete $serviceName
}

- name: Unzip the files
- name: Unzip the files (Health Check UI)
run: |
Expand-Archive -Path healthchecksui.zip -DestinationPath "C:\txnproc\transactionprocessing\healthchecksui" -Force

- name: Install as a Windows service
- name: Install as a Windows service (Health Check UI)
run: |
$serviceName = "Transaction Processing - Health Checks UI"
$servicePath = "C:\txnproc\transactionprocessing\healthchecksui\TransactionProcessor.HealthChecksUI.exe"

New-Service -Name $serviceName -BinaryPathName $servicePath -Description $serviceName -DisplayName $serviceName -StartupType Automatic
Start-Service -Name $serviceName
Start-Service -Name $serviceName

- name: Remove existing Windows service (Merchant Pos)
run: |
$serviceName = "Transaction Processing - Merchant Pos"
# Check if the service exists
if (Get-Service -Name $serviceName -ErrorAction SilentlyContinue) {
Stop-Service -Name $serviceName
sc.exe delete $serviceName
}

- name: Unzip the files (Merchant Pos)
run: |
Expand-Archive -Path merchantpos.zip -DestinationPath "C:\txnproc\transactionprocessing\merchantpos" -Force

- name: Install as a Windows service (Merchant Pos)
run: |
$serviceName = "Transaction Processing - Merchant Pos"
$servicePath = "C:\txnproc\transactionprocessing\merchantpos\TransactionProcessor.MerchantPos.exe"

New-Service -Name $serviceName -BinaryPathName $servicePath -Description $serviceName -DisplayName $serviceName -StartupType Automatic
Start-Service -Name $serviceName
3 changes: 3 additions & 0 deletions .github/workflows/pullrequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ jobs:
run: |
dotnet restore TransactionProcessor.HealthChecksUI/TransactionProcessor.HealthChecksUI.sln --source ${{ secrets.PUBLICFEEDURL }} --source ${{ secrets.PRIVATEFEED_URL }}
dotnet restore TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.sln --source ${{ secrets.PUBLICFEEDURL }} --source ${{ secrets.PRIVATEFEED_URL }}
dotnet restore TransactionProcessing.MerchantPos/TransactionProcessing.MerchantPos.sln --source ${{ secrets.PUBLICFEEDURL }} --source ${{ secrets.PRIVATEFEED_URL }}


- name: Build Code
run: |
dotnet build TransactionProcessor.HealthChecksUI/TransactionProcessor.HealthChecksUI.sln --configuration Release
dotnet build TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.sln --configuration Release
dotnet build TransactionProcessing.MerchantPos/TransactionProcessing.MerchantPos.sln --configuration Release
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,6 @@ MigrationBackup/
.ionide/
/TransactionProcessor.HealthChecksUI/TransactionProcessor.HealthChecksUI/appsettings.development.json
/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService/appsettings.development.json
/TransactionProcessing.MerchantPos/merchant.db
/TransactionProcessing.MerchantPos/merchant.db-shm
/TransactionProcessing.MerchantPos/merchant.db-wal
27 changes: 27 additions & 0 deletions TransactionProcessing.MerchantPos/Models/Entities.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace MerchantPos.EF.Models
{
public class Merchant
{
[Key]
public Guid MerchantId { get; set; }
public String MerchantName { get; set; }
public Decimal Balance { get; set; }
public DateTime LastEndOfDayDateTime { get; set; }
public DateTime LastLogonDateTime { get; set; }
public Int32 TransactionNumber { get; set; }
}

public class OperatorTotal
{
[Key]
public int Id { get; set; }
public Guid MerchantId { get; set; }
public Guid OperatorId { get; set; }
public Guid ContractId { get; set; }
public Decimal Total { get; set; }
public Int32 TotalCount { get; set; }
}
}
166 changes: 166 additions & 0 deletions TransactionProcessing.MerchantPos/Persistence/EfRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
using MerchantPos.EF.Models;
using Microsoft.EntityFrameworkCore;

namespace MerchantPos.EF.Persistence
{
public interface IEfRepository
{
Task<List<Merchant>> GetAllMerchants();
Task<Decimal> GetBalance(Guid merchantId);
Task<Merchant> CreateMerchantRecord(Guid merchantId, String merchantName);
Task UpdateBalance(Guid merchantId, String merchantName, Decimal balance);
Task UpdateLastEndOfDay(Guid merchantId, String merchantName, DateTime lastEndOfDayDateTime);
Task UpdateLastLogon(Guid merchantId, String merchantName, DateTime lastLogonDateTime);
Task UpdateTotals(Guid merchantId, Guid operatorId, Guid contractId, Decimal amount);
Task<List<OperatorTotal>> GetTotals(Guid merchantId);
Task ClearTotals(Guid merchantId);
Task<Merchant> GetMerchant(Guid merchantId);

Task IncrementTransactionNumber(Guid merchantId, String merchantName);
}

public class EfRepository : IEfRepository
{
private readonly MerchantDbContext _db;

public EfRepository(MerchantDbContext db)
{
_db = db;
}

public async Task<Merchant> CreateMerchantRecord(Guid merchantId,
String merchantName) {
Merchant merchant = new Merchant();
merchant.MerchantId = merchantId;
merchant.MerchantName = merchantName;
merchant.Balance = 0;
merchant.TransactionNumber = 0;
merchant.LastEndOfDayDateTime = DateTime.MinValue;
merchant.LastLogonDateTime = DateTime.MinValue;
_db.Merchants.Add(merchant);
await _db.SaveChangesAsync();
return merchant;
}

public async Task UpdateBalance(Guid merchantId,String merchantName, Decimal balance)
{
Merchant? entry = await this.GetMerchant(merchantId);

if (entry == null) {
entry = await this.CreateMerchantRecord(merchantId, merchantName);
}

entry.MerchantName = merchantName;
entry.Balance = balance;

await _db.SaveChangesAsync();
}

public async Task<Merchant?> GetMerchant(Guid merchantId)
{
return await _db.Merchants.FindAsync(merchantId);
}

public async Task IncrementTransactionNumber(Guid merchantId,
String merchantName) {
Merchant? entry = await this.GetMerchant(merchantId);

if (entry == null)
{
entry = await this.CreateMerchantRecord(merchantId, merchantName);
}

Int32 nextTransactionNumber = entry.TransactionNumber + 1;
if (nextTransactionNumber == 9999) {
nextTransactionNumber = 1;
}
entry.TransactionNumber = nextTransactionNumber;
await _db.SaveChangesAsync();
}

public async Task UpdateLastEndOfDay(Guid merchantId, String merchantName, DateTime lastEndOfDayDateTime)
{
Merchant? entry = await this.GetMerchant(merchantId);

if (entry == null)
{
entry = await this.CreateMerchantRecord(merchantId, merchantName);
}
entry.LastEndOfDayDateTime = lastEndOfDayDateTime;

await _db.SaveChangesAsync();
}

public async Task UpdateLastLogon(Guid merchantId,
String merchantName,
DateTime lastLogonDateTime) {
Merchant? entry = await this.GetMerchant(merchantId);

if (entry == null)
{
entry = await this.CreateMerchantRecord(merchantId, merchantName);
}
entry.LastLogonDateTime = lastLogonDateTime;

await _db.SaveChangesAsync();
}


public async Task<List<Merchant>> GetAllMerchants() {
var entries = await _db.Merchants.ToListAsync();
return entries.ToList();
}

public async Task<decimal> GetBalance(Guid merchantId)
{
Merchant? entry = await this.GetMerchant(merchantId);
return entry?.Balance ?? 0;
}

public async Task<DateTime> GetLastEndOfDay(Guid merchantId)
{
Merchant? entry = await this.GetMerchant(merchantId);
return entry?.LastEndOfDayDateTime ?? DateTime.MinValue;
}

public async Task UpdateTotals(Guid merchantId, Guid operatorId, Guid contractId, decimal amount)
{
OperatorTotal? entry = await _db.OperatorTotals
.SingleOrDefaultAsync(o => o.MerchantId == merchantId && o.OperatorId == operatorId
&& o.ContractId == contractId);

if (entry == null)
{
entry = new OperatorTotal
{
MerchantId = merchantId,
OperatorId = operatorId,
ContractId = contractId,
Total = amount
};
_db.OperatorTotals.Add(entry);
}
else
{
entry.Total += amount;
}

await _db.SaveChangesAsync();
}

public async Task<List<OperatorTotal>> GetTotals(Guid merchantId)
{
return await _db.OperatorTotals
.Where(o => o.MerchantId == merchantId)
.ToListAsync();
}

public async Task ClearTotals(Guid merchantId)
{
IQueryable<OperatorTotal> rows = _db.OperatorTotals.Where(o => o.MerchantId == merchantId);
_db.OperatorTotals.RemoveRange(rows);
await _db.SaveChangesAsync();
}
}
}

19 changes: 19 additions & 0 deletions TransactionProcessing.MerchantPos/Persistence/MerchantDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Microsoft.EntityFrameworkCore;
using MerchantPos.EF.Models;

namespace MerchantPos.EF.Persistence
{
public class MerchantDbContext : DbContext
{
public MerchantDbContext(DbContextOptions<MerchantDbContext> opts) : base(opts) { }

public DbSet<Merchant> Merchants { get; set; }
public DbSet<OperatorTotal> OperatorTotals { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Merchant>().HasKey(m => m.MerchantId);
modelBuilder.Entity<OperatorTotal>().HasIndex(o => new { o.MerchantId, o.OperatorId });
}
}
}
Loading
Loading