Skip to content
Merged
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
54 changes: 22 additions & 32 deletions EstateReportingAPI.BusinessLogic/ReportingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -889,41 +889,31 @@ join product in context.ContractProducts on txn.ContractProductId equals product

return results;
}

public async Task<List<Merchant>> GetMerchants(Guid estateId, CancellationToken cancellationToken){

public async Task<List<Merchant>> GetMerchants(Guid estateId,
CancellationToken cancellationToken) {
using ResolvedDbContext<EstateManagementContext>? resolvedContext = this.Resolver.Resolve(EstateManagementDatabaseName, estateId.ToString());
await using EstateManagementContext context = resolvedContext.Context;

var merchants = context.Merchants
.Select(m => new
{
MerchantReportingId = m.MerchantReportingId,
Name = m.Name,
LastSaleDateTime = m.LastSaleDateTime,
LastSale = m.LastSaleDate,
CreatedDateTime = m.CreatedDateTime,
LastStatement = m.LastStatementGenerated,
MerchantId = m.MerchantId,
Reference = m.Reference,
AddressInfo = context.MerchantAddresses
.Where(ma => ma.MerchantId == m.MerchantId)
.OrderByDescending(ma => ma.CreatedDateTime)
.Select(ma => new
{
PostCode = ma.PostalCode,
Region = ma.Region,
Town = ma.Town,
// Add more properties as needed
})
.FirstOrDefault(), // Get the first matching MerchantAddress or null
EstateReportingId = context.Estates.Single(e => e.EstateId == m.EstateId).EstateReportingId
});
var merchants = context.Merchants.Select(m => new {
MerchantReportingId = m.MerchantReportingId,
Name = m.Name,
LastSaleDateTime = m.LastSaleDateTime,
LastSale = m.LastSaleDate,
CreatedDateTime = m.CreatedDateTime,
LastStatement = m.LastStatementGenerated,
MerchantId = m.MerchantId,
Reference = m.Reference,
AddressInfo = context.MerchantAddresses.Where(ma => ma.MerchantId == m.MerchantId).OrderByDescending(ma => ma.CreatedDateTime).Select(ma => new {
PostCode = ma.PostalCode, Region = ma.Region, Town = ma.Town,
// Add more properties as needed
}).FirstOrDefault(), // Get the first matching MerchantAddress or null
EstateReportingId = context.Estates.Single(e => e.EstateId == m.EstateId).EstateReportingId
});

List<Merchant> merchantList = new List<Merchant>();
foreach (var result in merchants)
{
var model = new Merchant
{
foreach (var result in merchants) {
var model = new Merchant {
MerchantId = result.MerchantId,
Name = result.Name,
Reference = result.Reference,
Expand All @@ -935,12 +925,12 @@ public async Task<List<Merchant>> GetMerchants(Guid estateId, CancellationToken
LastStatement = result.LastStatement
};

if (result.AddressInfo != null)
{
if (result.AddressInfo != null) {
model.PostCode = result.AddressInfo.PostCode;
model.Town = result.AddressInfo.Town;
model.Region = result.AddressInfo.Region;
}

merchantList.Add(model);
}

Expand Down
Loading