add reports in AccountStorage

This commit is contained in:
Zakharov_Rostislav 2024-05-02 18:34:24 +04:00
parent fa86861b42
commit 599c4b1a41
5 changed files with 91 additions and 2 deletions

View File

@ -10,7 +10,9 @@ namespace BankContracts.SearchModels
{
public int? Id { get; set; }
public string? Number { get; set; }
public DateTime? ReleaseDate { get; set; }
public DateTime? DateTo { get; set; }
public DateTime? DateFrom { get; set; }
public int? ManagerId { get; set; }
public List<int>? SelectedAccountIds { get; set; }
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankContracts.ViewModels
{
public class ReportRequestsViewModel
{
public string AccountNumber { get; set; } = string.Empty;
public List<RequestViewModel> Requests { get; set; } = new();
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankContracts.ViewModels
{
public class ReportTransfersWithdrawalsViewModel
{
public string AccountNumber { get; set; } = string.Empty;
public List<TransferViewModel> SenderTransfers { get; set; } = new();
public List<TransferViewModel> RecipientTransfers { get; set; } = new();
public List<WithdrawalViewModel> Withdrawals { get; set; } = new();
}
}

View File

@ -103,5 +103,58 @@ namespace BankDatabaseImplement.Implements
}
return null;
}
public List<ReportRequestsViewModel> GetRequestsReport(AccountSearchModel model)
{
using var context = new BankDatabase();
return context.Accounts
.Where(a => model.SelectedAccountIds == null || model.SelectedAccountIds.Contains(a.Id))
.Select(a => new ReportRequestsViewModel()
{
AccountNumber = a.Number,
Requests = context.Requests
.Include(x => x.Withdrawal)
.ThenInclude(x => x.Accounts)
.Where(x => x.Withdrawal != null && x.Withdrawal.Accounts
.Select(x => x.AccountId)
.ToList()
.Contains(a.Id))
.Select (r => r.GetViewModel)
.ToList()
})
.ToList();
}
public List<ReportTransfersWithdrawalsViewModel> GetTransfersWithdrawalsReport(AccountSearchModel model)
{
using var context = new BankDatabase();
return context.Accounts
.Select(a => new ReportTransfersWithdrawalsViewModel()
{
AccountNumber = a.Number,
SenderTransfers = context.Transfers
.Where(t => t.TransferTime <= model.DateTo &&
t.TransferTime >= model.DateFrom &&
t.SenderAccountId == a.Id)
.Select(t => t.GetViewModel)
.ToList(),
RecipientTransfers = context.Transfers
.Where(t => t.TransferTime <= model.DateTo &&
t.TransferTime >= model.DateFrom &&
t.RecipientAccountId == a.Id)
.Select(t => t.GetViewModel)
.ToList(),
Withdrawals = context.Withdrawals
.Include(w => w.Accounts)
.Where(w => w.WithdrawalTime <= model.DateTo &&
w.WithdrawalTime >= model.DateFrom && w.Accounts
.Select(x => x.AccountId)
.ToList()
.Contains(a.Id))
.Select(w => w.GetViewModel)
.ToList()
})
.ToList();
}
}
}

View File

@ -22,7 +22,10 @@ namespace BankDatabaseImplement.Models
public RequestStatus Status { get; set; }
[ForeignKey("RequestId")]
public virtual List<CardRequest> Cards { get; set; } = new();
private Dictionary<int, ICardModel>? _cardRequests { get; set; } = null;
[ForeignKey("RequestId")]
public virtual Withdrawal? Withdrawal { get; set; }
private Dictionary<int, ICardModel>? _cardRequests { get; set; } = null;
[NotMapped]
public Dictionary<int, ICardModel> CardRequests
{