123 lines
3.9 KiB
C#
123 lines
3.9 KiB
C#
using System;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using REPORT_API_ver6.Services;
|
|
using REPORT_API_ver6.Models;
|
|
using System.Net;
|
|
using System.Collections.Generic;
|
|
|
|
namespace REPORT_API_ver6.Controllers
|
|
{
|
|
[Route("api/v1/import")]
|
|
[ApiController]
|
|
public class ImportAPI : ControllerBase
|
|
{
|
|
[Route("data")]
|
|
[HttpPost]
|
|
[DisableRequestSizeLimit]
|
|
public IActionResult ImportData([FromHeader] string token, [FromHeader] string skey)
|
|
{
|
|
UserInfo userInfo = Security.ValidateToken(token);
|
|
if (userInfo != null)
|
|
{
|
|
if (Request.Form.Files.Count > 0)
|
|
{
|
|
string returnString = "업로드 성공";
|
|
|
|
Project project = new Project();
|
|
PkeyInfo pkeyInfo = new PkeyInfo(skey);
|
|
|
|
var file = Request.Form.Files[0];
|
|
string extension = System.IO.Path.GetExtension(file.FileName);
|
|
string fileName = "DATA_" + pkeyInfo.Pkey + "_" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + extension;
|
|
|
|
Log.InsertSiteLog(userInfo.ID, pkeyInfo.Pkey, "Upload File", "{\"Type\":\"DATA\", \"Origin\": \"" + file.FileName + "\", \"FileName\":\"" + fileName + "\"}");
|
|
fileName = Common.uploadFile(fileName, file);
|
|
|
|
returnString = project.uploadProjectData(pkeyInfo.Pkey, pkeyInfo.isKiwi, fileName, extension);
|
|
|
|
Response.StatusCode = (int)HttpStatusCode.OK;
|
|
return Content(returnString);
|
|
}
|
|
}
|
|
|
|
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
|
|
return Content(null);
|
|
}
|
|
|
|
[Route("question")]
|
|
[HttpPost]
|
|
[DisableRequestSizeLimit]
|
|
public IActionResult ImportQuestion([FromHeader] string token, [FromHeader] string skey)
|
|
{
|
|
UserInfo userInfo = Security.ValidateToken(token);
|
|
if (userInfo != null)
|
|
{
|
|
if (Request.Form.Files.Count > 0)
|
|
{
|
|
string returnString = "업로드 성공";
|
|
|
|
Project project = new Project();
|
|
PkeyInfo pkeyInfo = new PkeyInfo(skey);
|
|
|
|
var file = Request.Form.Files[0];
|
|
string extension = System.IO.Path.GetExtension(file.FileName);
|
|
string fileName = "QUESTION_" + pkeyInfo.Pkey + "_" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + extension;
|
|
|
|
Log.InsertSiteLog(userInfo.ID, pkeyInfo.Pkey, "Upload File", "{\"Type\":\"QUESTION\", \"Origin\": \"" + file.FileName + "\", \"FileName\":\"" + fileName + "\"}");
|
|
fileName = Common.uploadFile(fileName, file);
|
|
|
|
returnString = project.resetQuestion(pkeyInfo.Pkey, pkeyInfo.isKiwi);
|
|
if (String.IsNullOrEmpty(returnString))
|
|
{
|
|
returnString = project.uploadQuestion(pkeyInfo.Pkey, pkeyInfo.isKiwi, fileName, extension);
|
|
}
|
|
|
|
Response.StatusCode = (int)HttpStatusCode.OK;
|
|
return Content(returnString);
|
|
}
|
|
}
|
|
|
|
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
|
|
return Content(null);
|
|
}
|
|
|
|
[Route("title")]
|
|
[HttpPost]
|
|
[DisableRequestSizeLimit]
|
|
public IActionResult ImportTitle([FromHeader] string token, [FromHeader] string skey)
|
|
{
|
|
UserInfo userInfo = Security.ValidateToken(token);
|
|
if (userInfo != null)
|
|
{
|
|
if (Request.Form.Files.Count > 0)
|
|
{
|
|
string returnString = "업로드 성공";
|
|
|
|
Project project = new Project();
|
|
PkeyInfo pkeyInfo = new PkeyInfo(skey);
|
|
|
|
var file = Request.Form.Files[0];
|
|
string extension = System.IO.Path.GetExtension(file.FileName);
|
|
string fileName = "TITLE_" + pkeyInfo.Pkey + "_" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + extension;
|
|
|
|
Log.InsertSiteLog(userInfo.ID, pkeyInfo.Pkey, "Upload File", "{\"Type\":\"TITLE\", \"Origin\": \"" + file.FileName + "\", \"FileName\":\"" + fileName + "\"}");
|
|
fileName = Common.uploadFile(fileName, file);
|
|
|
|
returnString = project.resetExplain(pkeyInfo.Pkey, pkeyInfo.isKiwi);
|
|
if (String.IsNullOrEmpty(returnString))
|
|
{
|
|
returnString = project.uploadExplain(pkeyInfo.Pkey, pkeyInfo.isKiwi, fileName, extension);
|
|
}
|
|
|
|
Response.StatusCode = (int)HttpStatusCode.OK;
|
|
return Content(returnString);
|
|
}
|
|
}
|
|
|
|
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
|
|
return Content(null);
|
|
}
|
|
}
|
|
}
|