diff --git a/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToExcel.cs index 86c6749..6b06f84 100644 --- a/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToExcel.cs +++ b/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -24,54 +24,86 @@ namespace BankBusinessLogic.OfficePackage MergeCells(new ExcelMergeParameters { CellFromName = "A1", - CellToName = "C1" + CellToName = "E1" }); - uint rowIndex = 2; - foreach (var transfer in info.Transfers) + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = 2, + Text = "Номер счёта", + StyleInfo = ExcelStyleInfoType.Title + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = 2, + Text = "Номер заявки", + StyleInfo = ExcelStyleInfoType.Title + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = 2, + Text = "Статус заявки", + StyleInfo = ExcelStyleInfoType.Title + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "D", + RowIndex = 2, + Text = "Сумма заявки", + StyleInfo = ExcelStyleInfoType.Title + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "E", + RowIndex = 2, + Text = "Дата заявки", + StyleInfo = ExcelStyleInfoType.Title + }); + uint rowIndex = 3; + foreach (var report in info.Requests) { InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "A", RowIndex = rowIndex, - Text = "", + Text = report.AccountNumber, StyleInfo = ExcelStyleInfoType.Text }); rowIndex++; - foreach (var component in transfer.Transfers) + foreach (var request in report.Requests) { InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "B", RowIndex = rowIndex, - Text = "", - StyleInfo = - ExcelStyleInfoType.TextWithBroder + Text = request.Id.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBroder }); InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "C", RowIndex = rowIndex, - Text = "", - StyleInfo = - ExcelStyleInfoType.TextWithBroder + Text = request.Status.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "D", + RowIndex = rowIndex, + Text = request.Sum.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "E", + RowIndex = rowIndex, + Text = request.RequestTime.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBroder }); rowIndex++; } - InsertCellInWorksheet(new ExcelCellParameters - { - ColumnName = "A", - RowIndex = rowIndex, - Text = "Итого", - StyleInfo = ExcelStyleInfoType.Text - }); - InsertCellInWorksheet(new ExcelCellParameters - { - ColumnName = "C", - RowIndex = rowIndex, - Text = "", - StyleInfo = ExcelStyleInfoType.Text - }); - rowIndex++; } SaveExcel(info); } diff --git a/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToWord.cs index bc7ab60..87a6a33 100644 --- a/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -44,10 +44,10 @@ namespace BankBusinessLogic.OfficePackage var wordTable = new WordTable { Headers = new List { - "Номер карты", + "Номер счёта", "Номер заявки", "Статус заявки", - "Сумма выдачи", + "Сумма заявки", "Дата заявки"}, Columns = 5, RowText = table diff --git a/Bank/BankDatabaseImplement/Implements/WithdrawalStorage.cs b/Bank/BankDatabaseImplement/Implements/WithdrawalStorage.cs index fc39deb..629304e 100644 --- a/Bank/BankDatabaseImplement/Implements/WithdrawalStorage.cs +++ b/Bank/BankDatabaseImplement/Implements/WithdrawalStorage.cs @@ -126,11 +126,24 @@ namespace BankDatabaseImplement.Implements Withdrawal? withdrawal; try { - withdrawal = context.Withdrawals.FirstOrDefault(x => x.Id == withdrawalId); + withdrawal = context.Withdrawals.Include(x => x.Accounts).FirstOrDefault(x => x.Id == withdrawalId); if (withdrawal == null) throw new InvalidOperationException("Withdrawal was not found"); + var request = context.Requests.FirstOrDefault(x => x.Id == requestId); + if (request == null) + throw new InvalidOperationException("Request was not found"); + WithdrawalBindingModel model = new WithdrawalBindingModel + { + Id = withdrawal.Id, + WithdrawalAccounts = withdrawal.WithdrawalAccounts, + Sum = request.Sum, + }; + MakeWithdrawal(context, model); withdrawal.LinkToRequest(requestId); - context.SaveChanges(); + if (!request.Execute()) + throw new InvalidOperationException("Request was not executed"); + withdrawal.UpdateAccounts(context, model); + context.SaveChanges(); } catch { @@ -144,16 +157,18 @@ namespace BankDatabaseImplement.Implements public WithdrawalViewModel? Delete(WithdrawalBindingModel model) { using var context = new BankDatabase(); - var element = context.Withdrawals + var withdrawal = context.Withdrawals .Include(x => x.Request) .Include(x => x.Accounts) .ThenInclude(x => x.Account) .FirstOrDefault(rec => rec.Id == model.Id); - if (element != null) - { - context.Withdrawals.Remove(element); + if (withdrawal != null) + { + if (withdrawal.RequestId != null) + throw new InvalidOperationException("Deletion was rejected: withdrawal was done"); + context.Withdrawals.Remove(withdrawal); context.SaveChanges(); - return element.GetViewModel; + return withdrawal.GetViewModel; } return null; } diff --git a/Bank/BankDatabaseImplement/Models/Withdrawal.cs b/Bank/BankDatabaseImplement/Models/Withdrawal.cs index 6afb579..83bb6f9 100644 --- a/Bank/BankDatabaseImplement/Models/Withdrawal.cs +++ b/Bank/BankDatabaseImplement/Models/Withdrawal.cs @@ -88,6 +88,7 @@ namespace BankDatabaseImplement.Models { context.AccountWithdrawals.RemoveRange(WithdrawalAccounts.Where(rec => !model.WithdrawalAccounts.ContainsKey(rec.AccountId))); context.SaveChanges(); + WithdrawalAccounts = context.AccountWithdrawals.Where(rec => rec.WithdrawalId == model.Id).ToList(); foreach (var wa in WithdrawalAccounts) { wa.Sum = model.WithdrawalAccounts[wa.AccountId].Item2; diff --git a/Bank/BankManagersClientApp/Controllers/HomeController.cs b/Bank/BankManagersClientApp/Controllers/HomeController.cs index 9e627f3..b0fea54 100644 --- a/Bank/BankManagersClientApp/Controllers/HomeController.cs +++ b/Bank/BankManagersClientApp/Controllers/HomeController.cs @@ -494,7 +494,7 @@ namespace BankManagersClientApp.Controllers APIClient.PostRequest("/api/report/saverequeststoexcel", new ReportBindingModel { SelectedAccountIds = accounts, - FileName = "C:\\Users\\user\\Downloads\\RequestList.docx", + FileName = "C:\\Users\\user\\Downloads\\RequestList.xlsx", }); break; default: diff --git a/Bank/BankRestApi/Controllers/ReportController.cs b/Bank/BankRestApi/Controllers/ReportController.cs index e528fe5..5c4401c 100644 --- a/Bank/BankRestApi/Controllers/ReportController.cs +++ b/Bank/BankRestApi/Controllers/ReportController.cs @@ -26,15 +26,24 @@ namespace BankRestApi.Controllers } catch (Exception ex) { - _logger.LogError(ex, "Ошибка сохранения переводов в ворд"); + _logger.LogError(ex, "Ошибка сохранения переводов в Word"); throw; } } [HttpPost] - public void SaveRequestsToExcel(ReportBindingModel? model) - { + public void SaveRequestsToExcel(ReportBindingModel model) + { + try + { + _logic.SaveRequestsToExcelFile(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения переводов в Excel"); + throw; + } - } + } [HttpPost] public void SaveTransfersToWord(ReportBindingModel model) {