I work on asp.net core 2.2
i face issue I can't
modify web api
to display message "Not Matched Compare"
when compare excel function return false (areIdentical == false)
.
web api
below return physical file as zip file
in case of compare excel return true
but I need when compare excel function return false
to display message "Not matched compare"
so How to do it please ?
what i try
public IActionResult ExportNormalizedRelation()
{
var InputfilePath = System.IO.Path.Combine(GetFilesDownload, "DeliveryGenerationNormalTest_Input.xlsx");
using (var stream = new FileStream(dbPath, FileMode.Create))
{
Request.Form.Files[0].CopyTo(stream);
stream.Flush();
stream.Close();
}
bool areIdentical = ex.CompareExcel(dbPath, InputfilePath, out rowCount, out error);
if (areIdentical == true)
{
pathToCreate = Path.Combine(myValue2,Month,"file" DateTime.Now.Ticks.ToString());
Directory.CreateDirectory(pathToCreate);
List<inputexcelnormaltest> inputexcellist = new List<inputexcelnormaltest>();
inputexcellist = ex.ImportNormalTest(dbPath);
List<string> tabs = new List<string>();
var outputTemplatePath = System.IO.Path.Combine(GetFilesDownload, "DeliveryGeneration_Output.xlsx");
List<inputexcelnormaltest> inputmodulelist = new List<inputexcelnormaltest>();
foreach (var m in tabs)
{
inputmodulelist.Clear();
inputmodulelist = inputexcellist.Where(x => (x.TabName == m && x.FileName == f)).ToList();
var dtimport = DatatableConversion.ToDataTable(inputmodulelist);
DataTable dtexport = new DataTable();
dtexport = _deliveryService.LoadExcelToDataTableZipData(_connectionString, dtimport);
ex.Export(dtexport, m, exportPath);
}
}
string zipPath = Path.Combine(myValue2,Month,"result" DateTime.Now.Ticks.ToString() ".zip");
ZipFile.CreateFromDirectory(pathToCreate, zipPath);
return PhysicalFile(zipPath, "application/zip", Path.GetFileName(zipPath));
}
expected result
if (areIdentical == false)
return "Not Matched Compare"
so How to do that ?
CodePudding user response:
i solved my issue
i only add return return new JsonResult("Not Matched Excel");
public IActionResult ExportNormalizedRelation()
{
var InputfilePath = System.IO.Path.Combine(GetFilesDownload, "DeliveryGenerationNormalTest_Input.xlsx");
using (var stream = new FileStream(dbPath, FileMode.Create))
{
Request.Form.Files[0].CopyTo(stream);
stream.Flush();
stream.Close();
}
bool areIdentical = ex.CompareExcel(dbPath, InputfilePath, out rowCount, out error);
if (areIdentical == false)
{
return new JsonResult("Not Matched Excel");
}
else
{
pathToCreate = Path.Combine(myValue2,Month,"file" DateTime.Now.Ticks.ToString());
Directory.CreateDirectory(pathToCreate);
List<inputexcelnormaltest> inputexcellist = new List<inputexcelnormaltest>();
inputexcellist = ex.ImportNormalTest(dbPath);
List<string> tabs = new List<string>();
var outputTemplatePath = System.IO.Path.Combine(GetFilesDownload, "DeliveryGeneration_Output.xlsx");
List<inputexcelnormaltest> inputmodulelist = new List<inputexcelnormaltest>();
foreach (var m in tabs)
{
inputmodulelist.Clear();
inputmodulelist = inputexcellist.Where(x => (x.TabName == m && x.FileName == f)).ToList();
var dtimport = DatatableConversion.ToDataTable(inputmodulelist);
DataTable dtexport = new DataTable();
dtexport = _deliveryService.LoadExcelToDataTableZipData(_connectionString, dtimport);
ex.Export(dtexport, m, exportPath);
}
}
string zipPath = Path.Combine(myValue2,Month,"result" DateTime.Now.Ticks.ToString() ".zip");
ZipFile.CreateFromDirectory(pathToCreate, zipPath);
return PhysicalFile(zipPath, "application/zip", Path.GetFileName(zipPath));
}