diff --git a/Controllers/ApiController.cs b/Controllers/ApiController.cs new file mode 100644 index 0000000..60cbcdc --- /dev/null +++ b/Controllers/ApiController.cs @@ -0,0 +1,92 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Microsoft.AspNetCore.Cors; +using Dapper; +using System.Data; +using System.Data.SqlClient; +using System.Web; +using System.Text; +using System.Net; +using System.Net.Http; +using System.Net.Http.Headers; +using Dapper.Contrib.Extensions; + +using System.IO; +using System.Threading; +using System.Dynamic; +using NPOI; +using NPOI.HPSF; +using NPOI.HSSF; +using NPOI.HSSF.UserModel; +using NPOI.XSSF; +using NPOI.XSSF.UserModel; +using NPOI.POIFS; +using NPOI.Util; +using Microsoft.Extensions.Configuration; +using System.Security.Policy; +using NPOI.SS.Formula.Functions; +using static DbTableClass; +using System.Runtime.InteropServices.ObjectiveC; +using static System.Net.WebRequestMethods; +using System.Diagnostics.Eventing.Reader; +using static Journeys_WantHome.Controllers.AuthApiController; + + +namespace Journeys_WantHome.Controllers +{ + [Route("Api")] + public class ApiController : ControllerBase + { + private readonly IHttpContextAccessor _httpContextAccessor; + + DbConn dbConn = new DbConn(); + SqlConnection conn = new SqlConnection(GlobalClass.appsettings("ConnectionStrings:SQLConnectionString")); + SqlConnection elabConn = new SqlConnection(GlobalClass.appsettings("ConnectionStrings:ElabConnectionString")); + + + public ApiController(IHttpContextAccessor httpContextAccessor) + { + this._httpContextAccessor = httpContextAccessor; + } + + [Route("optionItemList")] + public ActionResult OptionItemList(IFormCollection obj) + { + optionListResult ret = new optionListResult(); + + authToken token = new authToken(this._httpContextAccessor); + if (token.user_isLogin == false) + { + HttpContext.Response.Cookies.Delete("token_key"); + ret.ret = "no"; + ret.err_code = "99999"; + ret.message = "非登入狀態!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + + + string option_uid = obj["option_uid"].ToString(); + + if (option_uid == "") + { + ret.ret = "no"; + ret.err_code = "00001"; + ret.message = "無option_uid資料!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + ret.optionItems = conn.Query("select * from optionItem where optionItem_ishide = 'N' and option_uid = @option_uid order by optionItem_order ", new { option_uid = option_uid }).ToList(); + ret.ret = "yes"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + + } +} diff --git a/Controllers/AuthApiController.cs b/Controllers/AuthApiController.cs index f24f99b..17ec2a2 100644 --- a/Controllers/AuthApiController.cs +++ b/Controllers/AuthApiController.cs @@ -55,6 +55,8 @@ namespace Journeys_WantHome.Controllers public AuthApiController(IHttpContextAccessor httpContextAccessor) { this._httpContextAccessor = httpContextAccessor; + + } [Route("optionItemOrder")] @@ -685,6 +687,29 @@ namespace Journeys_WantHome.Controllers return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); } + [Route("logout")] + public ActionResult Logout() { + signinResult ret = new signinResult(); + + authToken _objToken = new authToken(this._httpContextAccessor); + + if (_objToken.user_isLogin == true) + { + string token_key = _httpContextAccessor.HttpContext.Request.Cookies["token_key"]; + + + conn.Execute("delete token where token_key = @token_key", new { token_key = token_key}); + + } + + HttpContext.Response.Cookies.Delete("token_key"); + + ret.ret = "yes"; + + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + [Route("signin")] public ActionResult Signin(IFormCollection obj) { signinResult ret = new signinResult(); diff --git a/Controllers/HomeController.cs b/Controllers/HomeController.cs index 96bb22e..f74e3a0 100644 --- a/Controllers/HomeController.cs +++ b/Controllers/HomeController.cs @@ -28,6 +28,18 @@ namespace Journeys_WantHome.Controllers kolDetial kolD = new kolDetial(myKol); } + public IActionResult KolList() + { + if (checkToken() == false) + { + HttpContext.Response.Cookies.Delete("token_key"); + return Redirect("~/Root/Login"); + } + + + return View(); + } + public IActionResult OptionList() { if (checkToken() == false) diff --git a/Models/DbTableClass.cs b/Models/DbTableClass.cs index 904d3c1..2732c47 100644 --- a/Models/DbTableClass.cs +++ b/Models/DbTableClass.cs @@ -19,6 +19,8 @@ public class DbTableClass public string kol_name { get; set; } = ""; + public string kol_photo { get; set; } = ""; + public string kol_descript { get; set; } = ""; public string kol_men_ratio { get; set; } = ""; diff --git a/Models/kolCooperateTypeDetail.cs b/Models/kolCooperateTypeDetail.cs index b05d563..f40c5e2 100644 --- a/Models/kolCooperateTypeDetail.cs +++ b/Models/kolCooperateTypeDetail.cs @@ -77,10 +77,22 @@ public class kolCooperateTypeDetail : kolCooperateType { public bool dataUpdate() { if (this._kolCooperateType != null) { + Type dataType = _kolCooperateType.GetType(); + + foreach (var prop in dataType.GetProperties()) + { + string propName = prop.Name; + var valueProperty = dataType.GetProperty(propName); + object propValue = valueProperty.GetValue(this, null); + + _kolCooperateType.GetType().GetProperty(propName).SetValue(_kolCooperateType, propValue); + } + if (this._kolCooperateType.kolCooperateType_uid == "") { + this._kolCooperateType.kolCooperateType_uid = "KCT_" + GlobalClass.CreateRandomCode(16); - + this.kolCooperateType_uid = this._kolCooperateType.kolCooperateType_uid; try { conn.Insert(this._kolCooperateType); diff --git a/Models/kolDetial.cs b/Models/kolDetial.cs index 12c5056..b0f8b79 100644 --- a/Models/kolDetial.cs +++ b/Models/kolDetial.cs @@ -1,4 +1,5 @@ using Dapper; +using Dapper.Contrib.Extensions; using NPOI.SS.Formula.Functions; using System.Data.SqlClient; using static DbTableClass; @@ -8,14 +9,16 @@ public class kolDetial : kol DbConn dbConn = new DbConn(); SqlConnection conn = new SqlConnection(GlobalClass.appsettings("ConnectionStrings:SQLConnectionString")); - public List cooperateTypes = new List(); - public List fansTypes = new List(); - public List makeups = new List(); - public List medias = new List(); - public List styles = new List(); + public List cooperateTypes = new List(); + public List fansTypes = new List(); + public List makeups = new List(); + public List medias = new List(); + public List styles = new List(); + public string updateResult { get; set; } = ""; + private kol _kol; - public kolDetial() { - + public kolDetial() { + _kol = new kol(); } public kolDetial(kol kolObj) @@ -31,21 +34,150 @@ public class kolDetial : kol this.GetType().GetProperty(propName).SetValue(this, propValue); } - + _kol = kolObj; + loadList(); } - private void loadList() { - if (this.kol_uid != "") { - this.cooperateTypes.Clear(); - this.fansTypes.Clear(); - this.makeups.Clear(); - this.medias.Clear(); - this.styles.Clear(); + public kolDetial(string kol_uid) + { + _kol = conn.QueryFirstOrDefault("select * from kol where kol_uid = @kol_uid", new { kol_uid = kol_uid}); - this.cooperateTypes = conn.Query("select * from ").ToList(); + if (_kol != null) { + Type dataType = _kol.GetType(); + foreach (var prop in dataType.GetProperties()) + { + string propName = prop.Name; + var valueProperty = dataType.GetProperty(propName); + object propValue = valueProperty.GetValue(_kol, null); + this.GetType().GetProperty(propName).SetValue(this, propValue); + } + + loadList(); } } + private void loadList() { + if (this.kol_uid != "") { + cooperateTypes.Clear(); + fansTypes.Clear(); + makeups.Clear(); + medias.Clear(); + styles.Clear(); + + List kolCooperateTypes = conn.Query("select A.* from kolCooperateType A, optionItem B where A.option_uid = B.option_uid and A.optionItem_uid = B.optionItem_uid and A.kol_uid = @kol_uid order by B.optionItem_order", new { kol_uid = this.kol_uid} ).ToList(); + List kolFansTypes = conn.Query("select A.* from kolFansType A, optionItem B where A.option_uid = B.option_uid and A.optionItem_uid = B.optionItem_uid and A.kol_uid = @kol_uid order by B.optionItem_order", new { kol_uid = this.kol_uid }).ToList(); + List kolMakeups = conn.Query("select A.* from kolMakeup A, optionItem B where A.option_uid = B.option_uid and A.optionItem_uid = B.optionItem_uid and A.kol_uid = @kol_uid order by B.optionItem_order", new { kol_uid = this.kol_uid }).ToList(); + List kolMedias = conn.Query("select A.* from kolMedia A, optionItem B where A.option_uid = B.option_uid and A.optionItem_uid = B.optionItem_uid and A.kol_uid = @kol_uid order by B.optionItem_order", new { kol_uid = this.kol_uid }).ToList(); + List kolStyles = conn.Query("select A.* from kolStyle A, optionItem B where A.option_uid = B.option_uid and A.optionItem_uid = B.optionItem_uid and A.kol_uid = @kol_uid order by B.optionItem_order", new { kol_uid = this.kol_uid }).ToList(); + + foreach (kolCooperateType objItem in kolCooperateTypes) + { + kolCooperateTypeDetail objDetail = new kolCooperateTypeDetail(objItem); + cooperateTypes.Add(objDetail); + } + + foreach (kolFansType objItem in kolFansTypes) { + kolFansTypeDetail objDetail = new kolFansTypeDetail(objItem); + fansTypes.Add(objDetail); + } + + foreach (kolMakeup objItem in kolMakeups) + { + kolMakeupDetail objDetail = new kolMakeupDetail(objItem); + kolMakeups.Add(objDetail); + } + + foreach (kolMedia objItem in kolMedias) + { + kolMediaDetail objDetail = new kolMediaDetail(objItem); + kolMedias.Add(objDetail); + } + + foreach (kolStyle objItem in kolStyles) + { + kolStyleDetail objDetail = new kolStyleDetail(objItem); + kolStyles.Add(objDetail); + } + } + } + + public bool dataUpdate() + { + if (_kol != null) + { + Type dataType = _kol.GetType(); + + foreach (var prop in dataType.GetProperties()) + { + string propName = prop.Name; + var valueProperty = dataType.GetProperty(propName); + object propValue = valueProperty.GetValue(this, null); + + _kol.GetType().GetProperty(propName).SetValue(_kol, propValue); + } + + if (_kol.kol_uid == "") { + this._kol.kol_uid = "KOL_" + GlobalClass.CreateRandomCode(12); + this.kol_uid = this._kol.kol_uid; + try + { + conn.Insert(this._kol); + updateResult = "success"; + return true; + } + catch (Exception ex) + { + updateResult = ex.Message; + return false; + } + } + else + { + try + { + conn.Update(this._kol); + updateResult = "success"; + return true; + } + catch (Exception ex) + { + updateResult = ex.Message; + return false; + } + } + } + else { + updateResult = "null 物件無法更新"; + return false; + } + } + + private void updateList() + { + foreach (var item in cooperateTypes) { + item.dataUpdate(); + } + + foreach (var item in fansTypes) + { + item.dataUpdate(); + } + + foreach (var item in makeups) + { + item.dataUpdate(); + } + + foreach (var item in medias) + { + item.dataUpdate(); + } + + foreach (var item in styles) + { + item.dataUpdate(); + } + } } diff --git a/Models/kolFansTypeDetail.cs b/Models/kolFansTypeDetail.cs index b1789b9..29aaf52 100644 --- a/Models/kolFansTypeDetail.cs +++ b/Models/kolFansTypeDetail.cs @@ -78,9 +78,21 @@ public class kolFansTypeDetail : kolFansType { if (this._kolFansType != null) { + Type dataType = _kolFansType.GetType(); + + foreach (var prop in dataType.GetProperties()) + { + string propName = prop.Name; + var valueProperty = dataType.GetProperty(propName); + object propValue = valueProperty.GetValue(this, null); + + _kolFansType.GetType().GetProperty(propName).SetValue(_kolFansType, propValue); + } + if (this._kolFansType.kolFansType_uid == "") { this._kolFansType.kolFansType_uid = "KFT_" + GlobalClass.CreateRandomCode(16); + this.kolFansType_uid = this._kolFansType.kolFansType_uid; try { diff --git a/Models/kolMakeupDetail.cs b/Models/kolMakeupDetail.cs index 380f546..37b313f 100644 --- a/Models/kolMakeupDetail.cs +++ b/Models/kolMakeupDetail.cs @@ -79,10 +79,21 @@ public class kolMakeupDetail : kolMakeup { if (this._kolMakeup != null) { + Type dataType = _kolMakeup.GetType(); + + foreach (var prop in dataType.GetProperties()) + { + string propName = prop.Name; + var valueProperty = dataType.GetProperty(propName); + object propValue = valueProperty.GetValue(this, null); + + _kolMakeup.GetType().GetProperty(propName).SetValue(_kolMakeup, propValue); + } + if (this._kolMakeup.kolMakeup_uid == "") { this._kolMakeup.kolMakeup_uid = "KMK_" + GlobalClass.CreateRandomCode(16); - + this.kolMakeup_uid = this._kolMakeup.kolMakeup_uid; try { conn.Insert(this._kolMakeup); diff --git a/Models/kolMediaDetail.cs b/Models/kolMediaDetail.cs index f544662..ffc987c 100644 --- a/Models/kolMediaDetail.cs +++ b/Models/kolMediaDetail.cs @@ -79,9 +79,21 @@ public class kolMediaDetail : kolMedia { if (this._kolMedia != null) { + Type dataType = _kolMedia.GetType(); + + foreach (var prop in dataType.GetProperties()) + { + string propName = prop.Name; + var valueProperty = dataType.GetProperty(propName); + object propValue = valueProperty.GetValue(this, null); + + _kolMedia.GetType().GetProperty(propName).SetValue(_kolMedia, propValue); + } + if (this._kolMedia.kolMedia_uid == "") { this._kolMedia.kolMedia_uid = "KME_" + GlobalClass.CreateRandomCode(16); + this.kolMedia_uid = this._kolMedia.kolMedia_uid; try { diff --git a/Models/kolStyleDetail.cs b/Models/kolStyleDetail.cs index eb77269..e37f723 100644 --- a/Models/kolStyleDetail.cs +++ b/Models/kolStyleDetail.cs @@ -22,7 +22,7 @@ public class kolStyleDetail : kolStyle public kolStyleDetail(string kolMakeup_uid) { - _kolStyle = conn.QueryFirstOrDefault("select * from kolStyle where kolStyle_uid = @kolStyle_uid", new { kolStyle_uid = kolStyle_uid }); + _kolStyle = conn.QueryFirstOrDefault("select * from kolStyle where kolStyle_uid = @kolStyle_uid", new { kolStyle_uid = kolStyle_uid }); if (_kolStyle != null) { @@ -79,10 +79,21 @@ public class kolStyleDetail : kolStyle { if (this._kolStyle != null) { + Type dataType = _kolStyle.GetType(); + + foreach (var prop in dataType.GetProperties()) + { + string propName = prop.Name; + var valueProperty = dataType.GetProperty(propName); + object propValue = valueProperty.GetValue(this, null); + + _kolStyle.GetType().GetProperty(propName).SetValue(_kolStyle, propValue); + } + if (this._kolStyle.kolStyle_uid == "") { this._kolStyle.kolStyle_uid = "KST_" + GlobalClass.CreateRandomCode(16); - + this.kolStyle_uid = this._kolStyle.kolStyle_uid; try { conn.Insert(this._kolStyle); diff --git a/Views/Home/Dashboard.cshtml b/Views/Home/Dashboard.cshtml index b70b877..863d754 100644 --- a/Views/Home/Dashboard.cshtml +++ b/Views/Home/Dashboard.cshtml @@ -10,7 +10,7 @@ } @section Script { - + + + + + +} + +
+ +
+ + + +

KOL清單

+

+
+ +
+ + +
+ +
+ + + + + + + + + + + +
名稱 組成類型 KOL類型
+
+
+
+
+ + + +
+ +
\ No newline at end of file diff --git a/Views/Home/OptionList.cshtml b/Views/Home/OptionList.cshtml index 797a441..31e1402 100644 --- a/Views/Home/OptionList.cshtml +++ b/Views/Home/OptionList.cshtml @@ -12,7 +12,7 @@ @section Script { - + }
diff --git a/Views/Home/UserList.cshtml b/Views/Home/UserList.cshtml index bb0dd3d..54c292c 100644 --- a/Views/Home/UserList.cshtml +++ b/Views/Home/UserList.cshtml @@ -14,7 +14,7 @@ - + } diff --git a/Views/Shared/_LooperLayout.cshtml b/Views/Shared/_LooperLayout.cshtml index 80f2fdf..617df9e 100644 --- a/Views/Shared/_LooperLayout.cshtml +++ b/Views/Shared/_LooperLayout.cshtml @@ -50,6 +50,7 @@ // add flag class to html immediately if (isCompact == true) document.querySelector('html').classList.add('preparing-compact-menu'); + @@ -93,8 +94,8 @@
@@ -129,6 +130,10 @@ Dashboard + +