diff --git a/Bank/BankContracts/SearchModels/AccountSearchModel.cs b/Bank/BankContracts/SearchModels/AccountSearchModel.cs index 220bcf2..4bdbaad 100644 --- a/Bank/BankContracts/SearchModels/AccountSearchModel.cs +++ b/Bank/BankContracts/SearchModels/AccountSearchModel.cs @@ -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? SelectedAccountIds { get; set; } } } diff --git a/Bank/BankContracts/ViewModels/ReportRequestsViewModel.cs b/Bank/BankContracts/ViewModels/ReportRequestsViewModel.cs new file mode 100644 index 0000000..3913cc2 --- /dev/null +++ b/Bank/BankContracts/ViewModels/ReportRequestsViewModel.cs @@ -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 Requests { get; set; } = new(); + } +} diff --git a/Bank/BankContracts/ViewModels/ReportTransfersWithdrawalsViewModel.cs b/Bank/BankContracts/ViewModels/ReportTransfersWithdrawalsViewModel.cs new file mode 100644 index 0000000..ff459b7 --- /dev/null +++ b/Bank/BankContracts/ViewModels/ReportTransfersWithdrawalsViewModel.cs @@ -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 SenderTransfers { get; set; } = new(); + public List RecipientTransfers { get; set; } = new(); + public List Withdrawals { get; set; } = new(); + } +} diff --git a/Bank/BankDatabaseImplement/Implements/AccountStorage.cs b/Bank/BankDatabaseImplement/Implements/AccountStorage.cs index 79e67f8..72e07f7 100644 --- a/Bank/BankDatabaseImplement/Implements/AccountStorage.cs +++ b/Bank/BankDatabaseImplement/Implements/AccountStorage.cs @@ -103,5 +103,58 @@ namespace BankDatabaseImplement.Implements } return null; } + + public List 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 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(); + } } } diff --git a/Bank/BankDatabaseImplement/Models/Request.cs b/Bank/BankDatabaseImplement/Models/Request.cs index 0992bca..b956c80 100644 --- a/Bank/BankDatabaseImplement/Models/Request.cs +++ b/Bank/BankDatabaseImplement/Models/Request.cs @@ -22,7 +22,10 @@ namespace BankDatabaseImplement.Models public RequestStatus Status { get; set; } [ForeignKey("RequestId")] public virtual List Cards { get; set; } = new(); - private Dictionary? _cardRequests { get; set; } = null; + + [ForeignKey("RequestId")] + public virtual Withdrawal? Withdrawal { get; set; } + private Dictionary? _cardRequests { get; set; } = null; [NotMapped] public Dictionary CardRequests {