diff --git a/Bremen_ESG.csproj b/Bremen_ESG.csproj
index 7c18eae..32ab90d 100644
--- a/Bremen_ESG.csproj
+++ b/Bremen_ESG.csproj
@@ -17,4 +17,8 @@
+
+
+
+
diff --git a/Controllers/BackEndApiController.cs b/Controllers/BackEndApiController.cs
new file mode 100644
index 0000000..ba227a4
--- /dev/null
+++ b/Controllers/BackEndApiController.cs
@@ -0,0 +1,294 @@
+using Microsoft.AspNetCore.Mvc;
+using Newtonsoft.Json;
+using Dapper;
+using System.Data.SqlClient;
+using static Bremen_ESG.Controllers.ApiController;
+using static DbTableClass;
+using SixLabors.Fonts.Tables.AdvancedTypographic;
+using Dapper.Contrib.Extensions;
+
+namespace Bremen_ESG.Controllers
+{
+ [Route("BackEndApi")]
+ public class BackEndApiController : ControllerBase
+ {
+ private readonly IHttpContextAccessor _httpContextAccessor;
+ DbConn dbConn = new DbConn();
+ SqlConnection conn = new SqlConnection(GlobalClass.appsettings("ConnectionStrings:SQLConnectionString"));
+
+ public BackEndApiController(IHttpContextAccessor httpContextAccessor)
+ {
+ this._httpContextAccessor = httpContextAccessor;
+ }
+
+ [Route("updateTags")]
+ public ActionResult UpdateTags(IFormCollection obj)
+ {
+ updatTagResult ret = new updatTagResult();
+
+ authToken token = new authToken(this._httpContextAccessor);
+ if (token.user_isLogin == false)
+ {
+ HttpContext.Response.Cookies.Delete("token_key");
+
+ return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
+ }
+
+ string search = obj["search"].ToString();
+
+ if (search.Length < 2)
+ {
+ ret.ret = "no";
+ return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
+ }
+ tags tag = conn.QueryFirstOrDefault("select * from tags where tag_text = @tag_text", new { tag_text = search });
+
+
+
+ if (tag == null)
+ {
+ tags newTag = new tags();
+ newTag.tag_uid = "tag_" + GlobalClass.CreateRandomCode(12);
+ newTag.tag_text = search;
+
+ conn.Insert(newTag);
+
+ ret.data.id = newTag.tag_uid;
+ ret.data.text = search;
+ ret.ret = "yes";
+ }
+ else
+ {
+ ret.data.id = tag.tag_uid;
+ ret.data.text = search;
+ ret.ret = "yes";
+ }
+ return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
+ }
+
+ [Route("queryTags")]
+ public ActionResult QueryTags(IFormCollection obj)
+ {
+ tagListResult ret = new tagListResult();
+
+ authToken token = new authToken(this._httpContextAccessor);
+ if (token.user_isLogin == false)
+ {
+ HttpContext.Response.Cookies.Delete("token_key");
+
+ return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
+ }
+
+ string search = obj["search"].ToString();
+ search = "%" + search + "%";
+ List tagList = conn.Query("select * from tags where tag_text like @tag_text", new { tag_text = search }).ToList();
+
+ foreach (tags tag in tagList)
+ {
+ optionData item = new optionData();
+
+ item.id = tag.tag_uid;
+ item.text = tag.tag_text;
+
+ ret.data.Add(item);
+ }
+
+ return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
+ }
+
+ [Route("mainPhotoUpload")]
+ [RequestFormLimits(MultipartBodyLengthLimit = int.MaxValue)]
+ [RequestSizeLimit(int.MaxValue)]
+ public ActionResult MainPhotoUpload([FromForm(Name = "avatar")] IFormFile file) {
+ authToken token = new authToken(this._httpContextAccessor);
+ if (token.user_isLogin == false)
+ {
+ List files = new List();
+
+ errFile newFile = new errFile();
+ newFile.name = "";
+ newFile.size = 0;
+ newFile.error = "尚未登入";
+
+ files.Add(newFile);
+
+ fileResult obj = new fileResult();
+
+ obj.files = files;
+
+ return Content(JsonConvert.SerializeObject(files), "application/json;charset=utf-8");
+ }
+
+
+ string originFileName = file.FileName;
+ string newFileName = "mainPhoto_" + GlobalClass.CreateRandomCode(8) + Path.GetExtension(originFileName);
+ string fullPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/upload/main/" + newFileName);
+ try
+ {
+ using (var stream = new FileStream(fullPath, FileMode.Create))
+ {
+ file.CopyTo(stream);
+ }
+
+ List files = new List();
+
+ uploadFile newFile = new uploadFile();
+
+ newFile.name = originFileName;
+ newFile.url = "/upload/main/" + newFileName;
+ newFile.size = file.Length;
+ newFile.thumbnailUrl = "/upload/main/" + newFileName;
+ newFile.deleteUrl = "/upload/main/" + newFileName;
+
+
+
+ files.Add(newFile);
+
+ fileResult obj = new fileResult();
+
+ obj.files = files;
+
+
+
+
+
+ return Content(JsonConvert.SerializeObject(obj), "application/json;charset=utf-8");
+ }
+ catch (Exception ex)
+ {
+ List files = new List();
+
+ errFile newFile = new errFile();
+ newFile.name = originFileName;
+ newFile.size = file.Length;
+ newFile.error = ex.Message;
+
+ files.Add(newFile);
+
+ fileResult obj = new fileResult();
+
+ obj.files = files;
+
+ return Content(JsonConvert.SerializeObject(files), "application/json;charset=utf-8");
+ }
+ }
+
+ //後台登入
+ [Route("signin")]
+ public ActionResult Signin(IFormCollection obj)
+ {
+ result ret = new result();
+
+ string input_ID = obj["id"].ToString();
+ string input_PWD = obj["pwd"].ToString();
+
+ string sys_ID = GlobalClass.appsettings("Admin:id");
+ string sys_PWD = GlobalClass.Sha256(GlobalClass.appsettings("Admin:pwd"));
+
+ if (input_ID == sys_ID && input_PWD == sys_PWD)
+ {
+ DbConn dbConn = new DbConn();
+
+ SqlConnection conn = dbConn.sqlConnection();
+
+ string token_key = GlobalClass.CreateRandomCode(24);
+
+ int effCount = conn.Execute("insert into token (token_key, user_uid, user_id, user_perm, token_expireddate) values (@token_key, @user_uid, @user_id, @user_perm, @token_expireddate)", new { token_key = token_key, user_uid = "system", user_id = input_ID, user_perm = "system", token_expireddate = DateTime.Now.AddMinutes(20) });
+
+ CookieOptions options = new CookieOptions();
+
+ options.Secure = true;
+ options.Expires = DateTime.Now.AddMinutes(30);
+
+ HttpContext.Response.Cookies.Delete("token_key");
+
+ _httpContextAccessor.HttpContext.Response.Cookies.Append("token_key", token_key, options);
+
+ dbConn.closeConn();
+
+ ret.ret = "yes";
+ }
+ else
+ {
+ ret.ret = "no";
+ ret.err_code = "0001";
+ ret.message = "帳號或密碼錯誤!";
+ }
+
+ return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
+ }
+
+ [Route("newsList")]
+ public ActionResult NewsList(IFormCollection obj) {
+ newResult ret = new newResult();
+
+ authToken token = new authToken(this._httpContextAccessor);
+
+ if (token.user_isLogin == false)
+ {
+ HttpContext.Response.Cookies.Delete("token_key");
+ ret.ret = "no";
+ ret.err_code = "9999";
+ ret.message = "非登入狀態!";
+ return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
+ }
+
+ DbConn dbConn = new DbConn();
+ SqlConnection conn = dbConn.sqlConnection();
+
+ ret.newsList = conn.Query("select * from news order by news_sn desc").ToList();
+ ret.ret = "yes";
+ return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
+ }
+
+ public class newResult
+ {
+ public string ret = "no";
+ public string err_code = "0000";
+ public string message = "";
+ public List newsList = new List();
+
+ }
+
+ public class fileResult
+ {
+ public object files = new object();
+ }
+
+ public class uploadFile
+ {
+ public string name { get; set; } = "";
+ public long size { get; set; } = 0;
+ public string url { get; set; } = "";
+ public string thumbnailUrl { get; set; } = "";
+ public string deleteUrl { get; set; } = "";
+ public string deleteType { get; set; } = "DELETE";
+ }
+
+ public class errFile
+ {
+ public string name { get; set; } = "";
+ public long size { get; set; } = 0;
+ public string error { get; set; } = "";
+ }
+
+ public class updatTagResult
+ {
+ public string ret { get; set; } = "no";
+ public string err_code { get; set; } = "0000";
+ public string message { get; set; } = "";
+
+ public optionData data = new optionData();
+ }
+ public class tagListResult
+ {
+ public List data = new List();
+ }
+
+ public class optionData
+ {
+ public string id { get; set; } = "";
+ public string text { get; set; } = "";
+ }
+ }
+}
diff --git a/Controllers/BackEndController.cs b/Controllers/BackEndController.cs
new file mode 100644
index 0000000..d92e63e
--- /dev/null
+++ b/Controllers/BackEndController.cs
@@ -0,0 +1,71 @@
+using Microsoft.AspNetCore.Mvc;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Http;
+using System.Net.Http;
+using Dapper;
+using System.Data;
+using System.Data.SqlClient;
+
+namespace Bremen_ESG.Controllers
+{
+ public class BackEndController : Controller
+ {
+ private readonly IHttpContextAccessor _httpContextAccessor;
+ private authToken _objToken;
+
+ public BackEndController(IHttpContextAccessor httpContextAccessor)
+ {
+ this._httpContextAccessor = httpContextAccessor;
+
+ this._objToken = new authToken(this._httpContextAccessor);
+ }
+
+ public IActionResult NewsList() {
+ if (checkToken() == false)
+ {
+ return Redirect("~/BackEnd/Index");
+ }
+
+ return View();
+ }
+
+ public IActionResult Index()
+ {
+ return View();
+ }
+
+ public IActionResult Logout()
+ {
+ string token_key = _httpContextAccessor.HttpContext.Request.Cookies["token_key"];
+
+ DbConn dbConn = new DbConn();
+ dbConn.sqlConnection().Execute("delete token where token_key = @token_key", new { token_key = token_key });
+ dbConn.closeConn();
+
+ HttpContext.Response.Cookies.Delete("token_key");
+
+ HttpContext.Response.Redirect("/BackEnd/Index");
+
+ return View();
+ }
+
+ public Boolean checkToken()
+ {
+ this._objToken = new authToken(this._httpContextAccessor);
+
+ if (this._objToken.user_isLogin == false)
+ {
+ HttpContext.Response.Cookies.Delete("token_key");
+ return false;
+ }
+
+ @ViewData["User_name"] = this._objToken.user_name;
+
+
+ return true;
+ }
+ }
+}
diff --git a/Models/DbTableClass.cs b/Models/DbTableClass.cs
index 40fd892..bab842c 100644
--- a/Models/DbTableClass.cs
+++ b/Models/DbTableClass.cs
@@ -9,6 +9,58 @@ using Org.BouncyCastle.Bcpg;
public class DbTableClass {
+
+ [Table("tags")]
+ public class tags
+ {
+ [JsonIgnore]
+ [Key]
+ public int tag_sn { get; set; }
+ public string tag_uid { get; set; } = "";
+ public string tag_text { get; set; } = "";
+ }
+
+ [Table("photo")]
+ public class photo
+ {
+ [JsonIgnore]
+ [Key]
+ public int photo_sn { get; set; }
+ public string photo_uid { get; set; } = "";
+ public string news_uid { get; set; } = "";
+ public string photo_path { get; set; } = "";
+ public string photo_title { get; set; } = "";
+ }
+
+ [Table("tag")]
+ public class tag
+ {
+ [JsonIgnore]
+ [Key]
+ public int tag_sn { get; set; }
+ public string tag_uid { get; set; } = "";
+ public string news_uid { get; set; } = "";
+ public string tag_text { get; set; } = "";
+ }
+
+ [Table("news")]
+ public class news
+ {
+ [JsonIgnore]
+ [Key]
+ public int news_sn { get; set; }
+ public string news_uid { get; set; } = "";
+ public string news_title { get; set; } = "";
+ public string news_date { get; set; } = "";
+ public string news_subtitle { get; set; } = "";
+ public string news_mainPhoto { get; set; } = "";
+ public string news_content { get; set; } = "";
+ public DateTime news_createdate { get; set; } = DateTime.Now;
+ public DateTime news_modifydate { get; set; } = DateTime.Now;
+ }
+
+
+
[Table("esgMessage")]
public class esgMessage
{
diff --git a/Views/BackEnd/NewsList.cshtml b/Views/BackEnd/NewsList.cshtml
new file mode 100644
index 0000000..7c71574
--- /dev/null
+++ b/Views/BackEnd/NewsList.cshtml
@@ -0,0 +1,168 @@
+@*
+ For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
+*@
+@{
+ Layout = "_BackEnd";
+}
+@section Script {
+
+
+
+
+
+
+}
+
+
+
+
+
+
+
+
+ 最新消息清單
+
+
+
+
+
+
+
+
+
+
+
+
+
+ | 主圖片 |
+ 發布日期 |
+ 標題 |
+ |
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Views/Shared/_BackEnd.cshtml b/Views/Shared/_BackEnd.cshtml
index bb30a43..484140e 100644
--- a/Views/Shared/_BackEnd.cshtml
+++ b/Views/Shared/_BackEnd.cshtml
@@ -18,10 +18,12 @@
+
+
@@ -113,21 +115,10 @@
@@ -168,6 +159,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -187,7 +194,20 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
@RenderSection("Script", required: false)