From 5802a5a4ddbb6e963f4f2d6dc3aa5ba66524b9fa Mon Sep 17 00:00:00 2001 From: Yuee Shiness Date: Fri, 19 May 2023 18:57:49 +0400 Subject: [PATCH] File saving methods. --- .../Controllers/ReportController.cs | 33 +++++++++++++------ .../Views/Report/ConsignmentsReport.cshtml | 17 ++++++---- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/ComputerStoreEmployeeApp/Controllers/ReportController.cs b/ComputerStoreEmployeeApp/Controllers/ReportController.cs index 4e14ac1..4af86a4 100644 --- a/ComputerStoreEmployeeApp/Controllers/ReportController.cs +++ b/ComputerStoreEmployeeApp/Controllers/ReportController.cs @@ -1,4 +1,6 @@ -using ComputerStoreContracts.ViewModels; +using ComputerStoreContracts.BindingModels; +using ComputerStoreContracts.SearchModels; +using ComputerStoreContracts.ViewModels; using Microsoft.AspNetCore.Mvc; namespace ComputerStoreEmployeeApp.Controllers @@ -26,19 +28,22 @@ namespace ComputerStoreEmployeeApp.Controllers } [HttpPost] - public IActionResult SaveExcel(List consignments) + public IActionResult SaveExcel() { + var model = new ReportComponentsBindingModel { FileName = "ReportConsignments", Components = APIClient.productComponents.Select(x => new ComponentSearchModel { ID = x.Key, Name = x.Value.Component.Name }).ToList() }; + return File(APIClient.GetRequest($"api/main/savereportconsignmentstoexcel?model={model}").Result, + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + "ReportConsignments.xlsx"); - - return View("ReportMenu"); } [HttpPost] - public IActionResult SaveWord(List consignments) + public IActionResult SaveWord() { - - - return View("ReportMenu"); + var model = new ReportComponentsBindingModel { FileName = "ReportConsignments", Components = APIClient.productComponents.Select(x => new ComponentSearchModel { ID = x.Key, Name = x.Value.Component.Name }).ToList() }; + return File(APIClient.GetRequest($"api/main/savereportconsignmentstoword?model={model}").Result, + "application/vnd.openxmlformats-officedocument.spreadsheetml.document", + "ReportConsignments.doc"); } [HttpPost] @@ -60,13 +65,21 @@ namespace ComputerStoreEmployeeApp.Controllers else { APIClient.productComponents.Add(component.ID, (component, componentquantity)); - } + } + } [HttpGet] public IActionResult ConsignmentsReportResult() { - ViewBag.Consignments = APIClient.GetRequest>($"api/main/getreportconsignmentslist").Result; + if(APIClient.productComponents.Any()) + { + ViewBag.Consignments = APIClient.GetRequest>($"api/main/getreportconsignmentslist?model={APIClient.productComponents.Select(x => new ComponentSearchModel { ID = x.Key, Name = x.Value.Component.Name })}").Result; + return View("ConsignmentsReport", APIClient.productComponents); + } + + ViewBag.Message = "You should enter at least one product"; + ViewBag.Components = APIClient.GetRequest>("api/main/getcomponentslist").Result; return View("ConsignmentsReport", APIClient.productComponents); } } diff --git a/ComputerStoreEmployeeApp/Views/Report/ConsignmentsReport.cshtml b/ComputerStoreEmployeeApp/Views/Report/ConsignmentsReport.cshtml index d54a110..e881891 100644 --- a/ComputerStoreEmployeeApp/Views/Report/ConsignmentsReport.cshtml +++ b/ComputerStoreEmployeeApp/Views/Report/ConsignmentsReport.cshtml @@ -10,7 +10,7 @@
@if(ViewBag.Components != null) { -
+

Component:

@@ -49,6 +49,7 @@
+ } @if(ViewBag.Consignments != null) @@ -91,15 +92,13 @@
- + -
+
-
- - +
} @if (!string.IsNullOrEmpty(ViewBag.Message)) @@ -117,6 +116,12 @@ }) }); + $('#findbtn').on("click", function () { + + window.location.href = '/Report/ConsignmentsReportResult' + + }); + function ajax1(id, count) { return $.ajax({