HRM-10/HRM.UI/Controllers/CommonInterface/DataUploadController.cs

673 lines
29 KiB
C#
Raw Permalink Normal View History

2026-11-03 13:06:00 +06:00
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using HRM.BO;
using HRM.DA;
using Microsoft.AspNetCore.Authorization;
using System.IO;
using Newtonsoft.Json;
using Microsoft.AspNetCore.StaticFiles;
namespace HRM.UI.Controllers.Payroll
{
[Route("api/dataUpload")]
[ApiController]
[Authorize]
public class DataUploadController : ControllerBase
{
private static string _filePath = @"ClientApp\Documents\";
public readonly IDataUploadColumnDefinition _columnDefination;
private readonly IEmployeeBulkUploadService _employeeBulkUploadService;
private readonly ISalaryMasterBulkUploadService _salaryMasterBulkUploadService;
private readonly IEmployeePhotoBulkUploadService _employeePhotoBulkUploadService;
private readonly ICacheManager _cashManager;
2026-11-12 15:03:31 +06:00
private readonly IBonusProcessService _bonusProcessService;
2026-11-03 13:06:00 +06:00
public DataUploadController(IDataUploadColumnDefinition columnDefination,
IEmployeeBulkUploadService employeeBulkUploadService,
ISalaryMasterBulkUploadService salaryMasterBulkUploadService,
IEmployeePhotoBulkUploadService employeePhotoBulkUploadService,
2026-11-12 15:03:31 +06:00
ICacheManager cashManager,
IBonusProcessService bonusProcessService)
2026-11-03 13:06:00 +06:00
{
this._columnDefination = columnDefination;
this._employeeBulkUploadService = employeeBulkUploadService;
this._salaryMasterBulkUploadService = salaryMasterBulkUploadService;
this._employeePhotoBulkUploadService = employeePhotoBulkUploadService;
this._cashManager = cashManager;
2026-11-12 15:03:31 +06:00
this._bonusProcessService = bonusProcessService;
2026-11-03 13:06:00 +06:00
}
// loan
[HttpGet("prepareUpload/{uploadId}/{itemid}")]
public ActionResult GetPrepareUpload(int uploadId, string itemid)
{
int? newItemid = GlobalFunctions.GetApiDefaultIntData(itemid);
DataUploadColumnDefinition dataColumnDefinition = new DataUploadColumnDefinition();
try
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
dataColumnDefinition = this._columnDefination.GetColumnDefinition(uploadId, newItemid, (int)currentUser.PayrollTypeID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(dataColumnDefinition);
}
//[HttpGet("uploadData/{uploadId}/{oColumnDefination}/{path}")]
//public ActionResult GetUploadDataMessage(int uploadId, DataUploadColumnDefinitionVM oColumnDefination, string path)
//{
// RegularDataUpload regUpload= new RegularDataUpload();
// List<UploadErrorOrSuccess> errorOrSuccessList = new List<UploadErrorOrSuccess>();
// try
// {
// // regUpload.UploadData(uploadId, oColumnDefination, path);
// }
// catch (Exception ex)
// {
// return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
// }
// return Ok(regUpload);
//}
[HttpPost]
[Route("regularExcelInterface")]
//[AllowAnonymous]
2026-11-03 13:06:00 +06:00
public ActionResult regularExcelInterface()
{
DataUploadColumnDefinition oColumnDefination = new DataUploadColumnDefinition();
RegularDataUploadService regUpload = new RegularDataUploadService();
List<UploadErrorOrSuccess> errorOrSuccessList = new List<UploadErrorOrSuccess>();
DateTime selectedDate = DateTime.Today;
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
try
2026-11-03 13:06:00 +06:00
{
int uploadID = Convert.ToInt32(Request.Form["uploadID"]);
int? itemid = GlobalFunctions.GetApiDefaultIntData( Convert.ToString(Request.Form["itemID"]));
int? itemidTwo = GlobalFunctions.GetApiDefaultIntData(Convert.ToString(Request.Form["itemIDTwo"]));
int? payrolltypeid = currentUser.PayrollTypeID;
int? userid = (int)currentUser.UserID;
2026-11-03 13:06:00 +06:00
string date = Request.Form["selectedDate"];
if (!string.IsNullOrEmpty(date))
{
selectedDate = DateTime.Parse(date);
}
var files = Request.Form.Files;
foreach (var formFile in files)
{
oColumnDefination = this._columnDefination.GetColumnDefinition(uploadID, itemid, (int)payrolltypeid);
if (itemid != null)
{
oColumnDefination.uploadItemID =(int) itemid;
oColumnDefination.SelectedItemOneID =(int) itemid;
}
if (itemidTwo != null)
{
oColumnDefination.SelectedItemTwoID =(int) itemidTwo;
}
errorOrSuccessList = regUpload.UploadData(uploadID, oColumnDefination, formFile.OpenReadStream()
, (int)payrolltypeid, (int) userid, itemid, selectedDate);
break;
}
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(errorOrSuccessList);
}
[HttpPost]
[Route("uploadBonusFile")]
//[AllowAnonymous]
2026-11-03 13:06:00 +06:00
public ActionResult uploadBonusFile()
{
DataUploadColumnDefinition oColumnDefination = new DataUploadColumnDefinition();
RegularDataUploadService regUpload = new RegularDataUploadService();
List<BonusProcess.BonusProcessDetail> items = null;
try
{
int? payrolltypeid = GlobalFunctions.GetApiDefaultIntData(Convert.ToString(Request.Form["payrolltypeid"]));
var files = Request.Form.Files;
foreach (var formFile in files)
{
oColumnDefination = this._columnDefination.GetColumnDefinition(
(int)EnumRegularDataUpload.Bonus, null, (int)payrolltypeid);
items = regUpload.GetBonusData((int)EnumRegularDataUpload.Bonus, oColumnDefination, formFile.OpenReadStream()
, (int)payrolltypeid);
break;
}
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
2026-11-12 15:03:31 +06:00
/// <summary>
/// Bonus Process screen, "Upload Data": reads the bonus file (sheet EmpBonus: Employee No, Amount — the
/// same reader as uploadBonusFile) and saves it in the same request, with the tax when the header asks
/// for it (BonusProcessService.UploadAndSave). Form fields: excelfile, and header = the JSON of a
/// BonusProcessAndSaveRequest (bonus, dates, flags). Returns the saved rows.
/// </summary>
[HttpPost]
[Route("uploadBonusFileAndSave")]
public ActionResult uploadBonusFileAndSave()
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
BonusProcessAndSaveResult result = null;
try
{
int payrolltypeid = (int)currentUser.PayrollTypeID;
string headerJson = Convert.ToString(Request.Form["header"]);
if (string.IsNullOrWhiteSpace(headerJson))
return StatusCode(StatusCodes.Status500InternalServerError, "Bonus information not found.");
// same JSON reading as the Process button's request (Newtonsoft defaults), so dates arrive the same way
BonusProcessAndSaveRequest request = JsonConvert.DeserializeObject<BonusProcessAndSaveRequest>(headerJson);
IFormFile formFile = Request.Form.Files.FirstOrDefault();
if (formFile == null || formFile.Length == 0)
return StatusCode(StatusCodes.Status500InternalServerError, "Please select a file.");
string extension = Path.GetExtension(formFile.FileName ?? string.Empty).ToLowerInvariant();
if (extension != ".xlsx" && extension != ".xls")
return StatusCode(StatusCodes.Status500InternalServerError, "Please select an Excel file (.xlsx or .xls).");
DataUploadColumnDefinition oColumnDefination = this._columnDefination.GetColumnDefinition(
(int)EnumRegularDataUpload.Bonus, null, payrolltypeid);
List<BonusProcess.BonusProcessDetail> items;
using (Stream stream = formFile.OpenReadStream())
{
items = new RegularDataUploadService().GetBonusData((int)EnumRegularDataUpload.Bonus, oColumnDefination,
stream, payrolltypeid);
}
result = _bonusProcessService.UploadAndSave(items, request, payrolltypeid, currentUser.UserID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(result);
}
2026-11-03 13:06:00 +06:00
/// <summary>
/// The Employee Bulk Upload layout — groups, sub-groups and columns — that the page shows
/// as section checkboxes and in its template guide.
/// </summary>
[HttpGet("employee-bulk-upload-layout")]
[ProducesResponseType(StatusCodes.Status200OK)]
public ActionResult GetEmployeeBulkUploadLayout()
{
return Ok(EmployeeBulkUploadTemplate.GetGroups());
}
/// <summary>
/// The empty Employee Bulk Upload workbook. Generated on each request from
/// EmployeeBulkUploadTemplate, so the downloaded file can never fall out of step with
/// the validation rules. <paramref name="subGroups"/> lists the row-2 band names to
/// include (repeat the query key per name); none means the full template.
/// </summary>
[HttpGet("employee-bulk-upload-template")]
[ProducesResponseType(StatusCodes.Status200OK)]
public ActionResult GetEmployeeBulkUploadTemplate([FromQuery] List<string> subGroups)
{
if (subGroups != null && subGroups.Count > 0)
{
List<string> known = EmployeeBulkUploadTemplate.GetSubGroupNames();
List<string> unknown = subGroups
.Where(x => !known.Contains(x, StringComparer.OrdinalIgnoreCase))
.ToList();
if (unknown.Count > 0)
{
return BadRequest("Unknown section(s): " + string.Join(", ", unknown));
}
}
byte[] file;
try
{
file = this._employeeBulkUploadService.GetTemplate(subGroups);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return File(file, EmployeeBulkUploadTemplate.ContentType, EmployeeBulkUploadTemplate.FileName);
}
/// <summary>
/// Validates a filled Employee Bulk Upload workbook (multipart form: first file, plus one
/// "subGroups" field per section ticked in Template sections) and returns the result of
/// every validation layer, plus the sections and rows when all layers passed. All the
/// validation lives in the service; a failed check is a normal 200 result, not an error.
/// Nothing is saved.
/// </summary>
[HttpPost("employee-bulk-upload-read")]
[ProducesResponseType(StatusCodes.Status200OK)]
public ActionResult ReadEmployeeBulkUpload()
{
IFormFile file = Request.Form.Files.Count > 0 ? Request.Form.Files[0] : null;
int postedPayrollTypeID;
int.TryParse(Request.Form["payrollTypeId"].FirstOrDefault(), out postedPayrollTypeID);
List<EmployeeBulkUploadReplacement> replacements;
if (!TryReadReplacements(out replacements))
{
return BadRequest("The replaced master-data values could not be read. Please upload the file again.");
}
EmployeeBulkUploadReadResult result;
try
{
using (Stream stream = file == null ? null : file.OpenReadStream())
{
result = this._employeeBulkUploadService.ReadUpload(stream,
file == null ? null : file.FileName,
file == null ? 0 : file.Length,
Request.Form["subGroups"].ToList(),
this.CurrentPayrollTypeID(postedPayrollTypeID),
replacements);
}
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(result);
}
/// <summary>
/// The optional "replacements" form field: a JSON list of the master-data values the user
/// chose to swap for existing records in the master-data dialog. No field means none;
/// a field that is not such a list is refused.
/// </summary>
private bool TryReadReplacements(out List<EmployeeBulkUploadReplacement> replacements)
{
replacements = new List<EmployeeBulkUploadReplacement>();
string json = Request.Form["replacements"].FirstOrDefault();
if (string.IsNullOrWhiteSpace(json))
{
return true;
}
try
{
replacements = JsonConvert.DeserializeObject<List<EmployeeBulkUploadReplacement>>(json)
?? new List<EmployeeBulkUploadReplacement>();
return true;
}
catch (JsonException)
{
return false;
}
}
/// <summary>
/// Saves a filled Employee Bulk Upload workbook (same multipart form as the read, plus
/// "closeMatchesConfirmed"). The service validates the file again and saves every row in
/// one transaction — all or nothing. A file that no longer passes, or unconfirmed close
/// matches, come back as Saved = false with the reason; nothing is written then.
/// </summary>
[HttpPost("employee-bulk-upload-save")]
[ProducesResponseType(StatusCodes.Status200OK)]
public ActionResult SaveEmployeeBulkUpload()
{
IFormFile file = Request.Form.Files.Count > 0 ? Request.Form.Files[0] : null;
if (file == null)
{
return BadRequest("No file was received.");
}
int postedPayrollTypeID;
int.TryParse(Request.Form["payrollTypeId"].FirstOrDefault(), out postedPayrollTypeID);
bool closeMatchesConfirmed;
bool.TryParse(Request.Form["closeMatchesConfirmed"].FirstOrDefault(), out closeMatchesConfirmed);
List<EmployeeBulkUploadReplacement> replacements;
if (!TryReadReplacements(out replacements))
{
return BadRequest("The replaced master-data values could not be read. Nothing was saved.");
}
try
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
using (Stream stream = file.OpenReadStream())
{
return Ok(this._employeeBulkUploadService.SaveUpload(stream, file.FileName, file.Length,
Request.Form["subGroups"].ToList(), this.CurrentPayrollTypeID(postedPayrollTypeID),
currentUser.UserID, closeMatchesConfirmed, replacements));
}
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
}
/// <summary>
/// Adds missing values to one master table (the "Add missing master data" dialog sends one
/// request per table). Each value is saved on its own; the reply says, per value, whether
/// it was added, already there, or why it could not be added.
/// </summary>
[HttpPost("employee-bulk-upload-add-master-data")]
[ProducesResponseType(StatusCodes.Status200OK)]
public ActionResult AddEmployeeBulkUploadMasterData(EmployeeBulkUploadMasterAddRequest request)
{
if (request == null || request.Items == null || request.Items.Count == 0)
{
return BadRequest("Nothing to add.");
}
try
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
return Ok(this._employeeBulkUploadService.AddMasterData(request,
this.CurrentPayrollTypeID(request.PayrollTypeID), currentUser.UserID));
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
}
/// <summary>The active records of a master table, for the add dialog's pickers (Division, District, ...).</summary>
[HttpGet("employee-bulk-upload-master-options/{masterData}/{payrollTypeId}")]
[ProducesResponseType(StatusCodes.Status200OK)]
public ActionResult GetEmployeeBulkUploadMasterOptions(EnumBulkUploadMasterData masterData, int payrollTypeId)
{
try
{
return Ok(this._employeeBulkUploadService.GetMasterOptions(masterData,
this.CurrentPayrollTypeID(payrollTypeId)));
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
}
/// <summary>
/// The empty Salary Master Data workbook for one salary month. Generated on each request
/// from SalaryMasterBulkUploadTemplate, so the file always matches the validation rules.
/// </summary>
[HttpGet("salary-master-bulk-upload-template/{salaryMonth}")]
[ProducesResponseType(StatusCodes.Status200OK)]
public ActionResult GetSalaryMasterBulkUploadTemplate(DateTime salaryMonth)
{
salaryMonth = GlobalFunctions.LastDateOfMonth(salaryMonth);
byte[] file;
try
{
file = this._salaryMasterBulkUploadService.GetTemplate(salaryMonth);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return File(file, SalaryMasterBulkUploadTemplate.ContentType,
SalaryMasterBulkUploadTemplate.FileName(salaryMonth));
}
/// <summary>
/// Validates a filled Salary Master Data workbook (multipart form: first file, plus
/// "salaryMonth", the month picked on the page) and returns every validation layer,
/// every problem and the rows. A failed check is a normal 200 result. Nothing is saved.
/// </summary>
[HttpPost("salary-master-bulk-upload-read")]
[ProducesResponseType(StatusCodes.Status200OK)]
public ActionResult ReadSalaryMasterBulkUpload()
{
IFormFile file = Request.Form.Files.Count > 0 ? Request.Form.Files[0] : null;
DateTime salaryMonth;
if (!TryGetPostedSalaryMonth(out salaryMonth))
{
return BadRequest("Please pick a valid salary month.");
}
int postedPayrollTypeID;
int.TryParse(Request.Form["payrollTypeId"].FirstOrDefault(), out postedPayrollTypeID);
try
{
using (Stream stream = file == null ? null : file.OpenReadStream())
{
return Ok(this._salaryMasterBulkUploadService.ReadUpload(stream,
file == null ? null : file.FileName,
file == null ? 0 : file.Length,
salaryMonth, this.CurrentPayrollTypeID(postedPayrollTypeID)));
}
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
}
/// <summary>
/// Saves a filled Salary Master Data workbook (same multipart form as the read). The
/// service validates the file again and saves every row in one transaction — all or
/// nothing. A file that no longer passes comes back as Saved = false with the reason.
/// </summary>
[HttpPost("salary-master-bulk-upload-save")]
[ProducesResponseType(StatusCodes.Status200OK)]
public ActionResult SaveSalaryMasterBulkUpload()
{
IFormFile file = Request.Form.Files.Count > 0 ? Request.Form.Files[0] : null;
if (file == null)
{
return BadRequest("No file was received.");
}
DateTime salaryMonth;
if (!TryGetPostedSalaryMonth(out salaryMonth))
{
return BadRequest("Please pick a valid salary month.");
}
int postedPayrollTypeID;
int.TryParse(Request.Form["payrollTypeId"].FirstOrDefault(), out postedPayrollTypeID);
try
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
using (Stream stream = file.OpenReadStream())
{
return Ok(this._salaryMasterBulkUploadService.SaveUpload(stream, file.FileName, file.Length,
salaryMonth, this.CurrentPayrollTypeID(postedPayrollTypeID), currentUser.UserID));
}
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
}
#region Employee Profile Picture Bulk Upload
/// <summary>The picture folder on the server and the rules, for the instructions.</summary>
[HttpGet("employee-photo-bulk-upload-info")]
public ActionResult GetEmployeePhotoBulkUploadInfo()
{
try
{
return Ok(this._employeePhotoBulkUploadService.GetInfo());
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
}
/// <summary>Checks every picture in the folder against the login's payroll type. Nothing is saved.</summary>
[HttpGet("employee-photo-bulk-upload-read")]
public ActionResult ReadEmployeePhotoBulkUpload()
{
try
{
return Ok(this._employeePhotoBulkUploadService.ReadFolder(this.CurrentPayrollTypeID(0)));
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
}
/// <summary>
/// Starts saving every picture of the folder — all or nothing — and returns at once with the
/// run, which the screen then follows. 15,000 pictures take minutes, far too long to hold
/// one request open, so the work runs on its own thread (as mail batches do).
/// </summary>
[HttpPost("employee-photo-bulk-upload-save")]
public ActionResult SaveEmployeePhotoBulkUpload()
{
try
{
int payrollTypeID = this.CurrentPayrollTypeID(0);
EmployeePhotoBulkUploadRun run = this._employeePhotoBulkUploadService.BeginSave(payrollTypeID);
IEmployeePhotoBulkUploadService service = this._employeePhotoBulkUploadService;
ICacheManager cashManager = this._cashManager;
EmailLogBackgroundRunner.Run(() =>
{
service.RunSave(run.RunID, payrollTypeID);
// As on approving a profile-picture request: the dashboard caches each employee's
// row (with the profile-completion percent), so drop it for every changed employee.
EmployeePhotoBulkUploadRun done = service.GetRun(run.RunID);
if (done != null && done.Status == EmployeePhotoBulkUploadRun.Saved)
{
foreach (int employeeID in done.SavedEmployeeIDs)
{
cashManager.Remove(enumMemoryCashType.LandingPageEmployee, enumMemoryCashNature.EmployeeWise, employeeID);
}
}
});
return Ok(run);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
}
/// <summary>How a save is getting on, and at the end its outcome.</summary>
[HttpGet("employee-photo-bulk-upload-run/{runId}")]
public ActionResult GetEmployeePhotoBulkUploadRun(string runId)
{
EmployeePhotoBulkUploadRun run = this._employeePhotoBulkUploadService.GetRun(runId);
if (run == null)
{
return NotFound("The save could not be found. The application may have restarted; check the folder again.");
}
return Ok(run);
}
/// <summary>The save running now, if any, so a reopened screen follows it instead of starting another. Empty when none.</summary>
[HttpGet("employee-photo-bulk-upload-active-run")]
public ActionResult GetEmployeePhotoBulkUploadActiveRun()
{
return Ok(this._employeePhotoBulkUploadService.GetActiveRun());
}
#endregion
/// <summary>The "salaryMonth" form field (the month picked on the page) as the last date of that month.</summary>
private bool TryGetPostedSalaryMonth(out DateTime salaryMonth)
{
if (!DateTime.TryParse(Request.Form["salaryMonth"].FirstOrDefault(), out salaryMonth))
{
return false;
}
salaryMonth = GlobalFunctions.LastDateOfMonth(salaryMonth);
return true;
}
/// <summary>
/// The login's payroll type from the token; the page's own value only when the token has
/// none, so a page cannot read or write another payroll type's data.
/// </summary>
private int CurrentPayrollTypeID(int postedPayrollTypeID)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
if (currentUser != null && currentUser.PayrollTypeID.HasValue && currentUser.PayrollTypeID.Value > 0)
{
return currentUser.PayrollTypeID.Value;
}
return postedPayrollTypeID > 0 ? postedPayrollTypeID : 0;
}
2026-11-04 19:03:36 +06:00
//[HttpPost]
//[Route("get-download-file")]
//[AllowAnonymous]
//[IgnoreAntiforgeryToken]
//[ProducesResponseType(StatusCodes.Status200OK)]
//public async Task<IActionResult> EmployeeDownload(dynamic data)
//{
// //var uploads = Path.Combine(_hostingEnvironment.WebRootPath, "uploads");
// //var filePath = Path.Combine(uploads, file);
2026-11-03 13:06:00 +06:00
2026-11-04 19:03:36 +06:00
// var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
// string tempfileName = (string) item["fileName"].ToObject<string>();
// string tempmappingpath = (string) item["mappingPath"].ToObject<string>();
2026-11-03 13:06:00 +06:00
2026-11-04 19:03:36 +06:00
// var fileName = _filePath + tempmappingpath;
// var contentType = GetFileType(data);
// string fullPath = System.IO.Path.Combine(System.Environment.CurrentDirectory, fileName);
2026-11-03 13:06:00 +06:00
2026-11-04 19:03:36 +06:00
// if (!System.IO.File.Exists(fullPath))
// return NotFound();
2026-11-03 13:06:00 +06:00
2026-11-04 19:03:36 +06:00
// var memory = new MemoryStream();
// using (var stream = new FileStream(fullPath, FileMode.Open))
// {
// await stream.CopyToAsync(memory);
// }
2026-11-03 13:06:00 +06:00
2026-11-04 19:03:36 +06:00
// memory.Position = 0;
2026-11-03 13:06:00 +06:00
2026-11-04 19:03:36 +06:00
// return File(memory, GetContentType(fullPath));
//}
2026-11-03 13:06:00 +06:00
2026-11-04 19:03:36 +06:00
//[HttpPost]
//[Route("get-file-type")]
//[AllowAnonymous]
//[IgnoreAntiforgeryToken]
//[ProducesResponseType(StatusCodes.Status200OK)]
//public string GetFileType(dynamic data)
//{
// var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
// string fileName = (string) item["fileName"].ToObject<string>();
// string contentType;
// new FileExtensionContentTypeProvider().TryGetContentType(fileName, out contentType);
// return contentType ?? "application/octet-stream";
//}
2026-11-03 13:06:00 +06:00
private string GetContentType(string path)
{
var provider = new FileExtensionContentTypeProvider();
string contentType;
if (!provider.TryGetContentType(path, out contentType))
{
contentType = "application/octet-stream";
}
return contentType;
}
}
}