Skip to content

Commit 32be6fb

Browse files
Merge pull request #261 from TransactionProcessing/codacy/high_fixes
loc fix for GetMerchant
2 parents 304dbda + a8081cd commit 32be6fb

1 file changed

Lines changed: 22 additions & 32 deletions

File tree

EstateReportingAPI.BusinessLogic/ReportingManager.cs

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -889,41 +889,31 @@ join product in context.ContractProducts on txn.ContractProductId equals product
889889

890890
return results;
891891
}
892-
893-
public async Task<List<Merchant>> GetMerchants(Guid estateId, CancellationToken cancellationToken){
892+
893+
public async Task<List<Merchant>> GetMerchants(Guid estateId,
894+
CancellationToken cancellationToken) {
894895
using ResolvedDbContext<EstateManagementContext>? resolvedContext = this.Resolver.Resolve(EstateManagementDatabaseName, estateId.ToString());
895896
await using EstateManagementContext context = resolvedContext.Context;
896897

897-
var merchants = context.Merchants
898-
.Select(m => new
899-
{
900-
MerchantReportingId = m.MerchantReportingId,
901-
Name = m.Name,
902-
LastSaleDateTime = m.LastSaleDateTime,
903-
LastSale = m.LastSaleDate,
904-
CreatedDateTime = m.CreatedDateTime,
905-
LastStatement = m.LastStatementGenerated,
906-
MerchantId = m.MerchantId,
907-
Reference = m.Reference,
908-
AddressInfo = context.MerchantAddresses
909-
.Where(ma => ma.MerchantId == m.MerchantId)
910-
.OrderByDescending(ma => ma.CreatedDateTime)
911-
.Select(ma => new
912-
{
913-
PostCode = ma.PostalCode,
914-
Region = ma.Region,
915-
Town = ma.Town,
916-
// Add more properties as needed
917-
})
918-
.FirstOrDefault(), // Get the first matching MerchantAddress or null
919-
EstateReportingId = context.Estates.Single(e => e.EstateId == m.EstateId).EstateReportingId
920-
});
898+
var merchants = context.Merchants.Select(m => new {
899+
MerchantReportingId = m.MerchantReportingId,
900+
Name = m.Name,
901+
LastSaleDateTime = m.LastSaleDateTime,
902+
LastSale = m.LastSaleDate,
903+
CreatedDateTime = m.CreatedDateTime,
904+
LastStatement = m.LastStatementGenerated,
905+
MerchantId = m.MerchantId,
906+
Reference = m.Reference,
907+
AddressInfo = context.MerchantAddresses.Where(ma => ma.MerchantId == m.MerchantId).OrderByDescending(ma => ma.CreatedDateTime).Select(ma => new {
908+
PostCode = ma.PostalCode, Region = ma.Region, Town = ma.Town,
909+
// Add more properties as needed
910+
}).FirstOrDefault(), // Get the first matching MerchantAddress or null
911+
EstateReportingId = context.Estates.Single(e => e.EstateId == m.EstateId).EstateReportingId
912+
});
921913

922914
List<Merchant> merchantList = new List<Merchant>();
923-
foreach (var result in merchants)
924-
{
925-
var model = new Merchant
926-
{
915+
foreach (var result in merchants) {
916+
var model = new Merchant {
927917
MerchantId = result.MerchantId,
928918
Name = result.Name,
929919
Reference = result.Reference,
@@ -935,12 +925,12 @@ public async Task<List<Merchant>> GetMerchants(Guid estateId, CancellationToken
935925
LastStatement = result.LastStatement
936926
};
937927

938-
if (result.AddressInfo != null)
939-
{
928+
if (result.AddressInfo != null) {
940929
model.PostCode = result.AddressInfo.PostCode;
941930
model.Town = result.AddressInfo.Town;
942931
model.Region = result.AddressInfo.Region;
943932
}
933+
944934
merchantList.Add(model);
945935
}
946936

0 commit comments

Comments
 (0)