///
/// 顯示公司簡介
///
///
[HttpGet]
public IActionResult Index()
{
using var comp = new z_sqlCompanys();
var model = comp.GetDataList().FirstOrDefault();
return View(model);
}
/// <summary>
/// 修改公司簡介
/// </summary>
/// <param name="id">公司記錄Id</param>
/// <returns></returns>
[HttpGet]
public IActionResult Edit(int id)
{
using var comp = new z_sqlCompanys();
var model = comp.GetDataList().Where(m => m.Id == id).FirstOrDefault();
return View(model);
}
/// <summary>
/// 儲存公司簡介修改資料
/// </summary>
/// <param name="model">修改資料的資料</param>
/// <returns></returns>
[HttpPost]
public IActionResult Edit(Companys model)
{
using var comp = new z_sqlCompanys();
comp.UpdateAboutUs(model.Id, model.AboutusText);
return RedirectToAction("Index", "Company", new { area = "" });
}
/// <summary>
/// 圖片上傳
/// </summary>
/// <param name="upload">上傳檔案</param>
/// <returns></returns>
[HttpPost]
public JsonResult CKEditorUploadImage(IFormFile upload)
{
// 取得目前專案資料夾目錄路徑
string str_pathName = Directory.GetCurrentDirectory();
// 專案路徑加入要存入的資料夾路徑
str_pathName += "\\wwwroot\\images\\Company\\";
string str_pathUrl = "..\\..\\images\\Company\\";
//如果目錄不存在則建立此目錄
if (!Directory.Exists(str_pathName)) Directory.CreateDirectory(str_pathName);
// 以亂數名稱存入
string str_guidNo = Guid.NewGuid().ToString().Replace("-", "");
string str_extName = Path.GetExtension(upload.FileName);
string str_fileName = $"{str_guidNo}{str_extName}";
string str_fileUrl = Path.Combine(str_pathName, str_fileName);
string str_imegeUrl = Path.Combine(str_pathUrl, str_fileName);
//如果檔案已存在則刪除此檔案
if (!System.IO.File.Exists(str_fileUrl)) System.IO.File.Delete(str_fileUrl);
// 建立一個串流物件
using var stream = System.IO.File.Create(str_fileUrl);
// 將檔案寫入到此串流物件中
upload.CopyTo(stream);
//上傳成功後,返回Json格式的響應
return Json(new
{
uploaded = 1,
fileName = str_fileName,
url = str_imegeUrl
});
}
}
}