SchoolMakerStudyController.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. /*
  2. * 商学院创客学堂
  3. */
  4. using System;
  5. using System.Web;
  6. using System.Collections.Generic;
  7. using System.Diagnostics;
  8. using System.Linq;
  9. using System.Threading.Tasks;
  10. using Microsoft.AspNetCore.Mvc;
  11. using Microsoft.AspNetCore.Http;
  12. using Microsoft.Extensions.Logging;
  13. using Microsoft.Extensions.Options;
  14. using MySystem.Models;
  15. using Library;
  16. using LitJson;
  17. using MySystemLib;
  18. namespace MySystem.Areas.Admin.Controllers
  19. {
  20. [Area("Admin")]
  21. [Route("Admin/[controller]/[action]")]
  22. public class SchoolMakerStudyController : BaseController
  23. {
  24. public SchoolMakerStudyController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  25. {
  26. OtherMySqlConn.connstr = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  27. }
  28. #region 商学院创客学堂列表
  29. /// <summary>
  30. /// 根据条件查询商学院创客学堂列表
  31. /// </summary>
  32. /// <returns></returns>
  33. public IActionResult Index(SchoolMakerStudy data, string right)
  34. {
  35. ViewBag.RightInfo = RightInfo;
  36. ViewBag.right = right;
  37. return View();
  38. }
  39. #endregion
  40. #region 根据条件查询商学院创客学堂列表
  41. /// <summary>
  42. /// 商学院创客学堂列表
  43. /// </summary>
  44. /// <returns></returns>
  45. public JsonResult IndexData(SchoolMakerStudy data, int page = 1, int limit = 30)
  46. {
  47. Dictionary<string, string> Fields = new Dictionary<string, string>();
  48. Fields.Add("Title", "1"); //标题
  49. Fields.Add("CreateDate", "3"); //时间
  50. string condition = " and Status>-1";
  51. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("SchoolMakerStudy", Fields, "Id desc", "0", page, limit, condition);
  52. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  53. foreach (Dictionary<string, object> dic in diclist)
  54. {
  55. dic["StatusName"] = dic["Status"].ToString() == "1" ? "正常" : "关闭";
  56. }
  57. return Json(obj);
  58. }
  59. #endregion
  60. #region 增加商学院创客学堂
  61. /// <summary>
  62. /// 增加或修改商学院创客学堂信息
  63. /// </summary>
  64. /// <returns></returns>
  65. public IActionResult Add(string right, string PColId, string CurColId)
  66. {
  67. ViewBag.RightInfo = RightInfo;
  68. ViewBag.right = right;
  69. ViewBag.CurColId = CurColId;
  70. if (string.IsNullOrEmpty(PColId))
  71. {
  72. PColId = "001";
  73. }
  74. ViewBag.PColId = PColId;
  75. // string code = "";
  76. // int len = PColId.Length + 3;
  77. // Col model = bsdb.Col.Where(m => m.ColId.StartsWith(PColId) && m.ColId.Length == len).OrderByDescending(m => m.ColId).FirstOrDefault();
  78. // if (model != null)
  79. // {
  80. // string CurCode = model.ColId;
  81. // int num = int.Parse(CurCode.Substring(CurCode.Length - 3)) + 1;
  82. // code = num.ToString();
  83. // for (int i = 0; i < 3 - num.ToString().Length; i++)
  84. // {
  85. // code = "0" + code;
  86. // }
  87. // code = PColId + code;
  88. // }
  89. // else
  90. // {
  91. // code = PColId + "001";
  92. // }
  93. return View();
  94. }
  95. #endregion
  96. #region 增加商学院创客学堂
  97. /// <summary>
  98. /// 增加或修改商学院创客学堂信息
  99. /// </summary>
  100. /// <returns></returns>
  101. [HttpPost]
  102. public string Add(SchoolMakerStudy data, string PColId = "", string CurColId = "")
  103. {
  104. Dictionary<string, object> Fields = new Dictionary<string, object>();
  105. Fields.Add("Title", data.Title); //标题
  106. Fields.Add("Detail", data.Detail); //介绍
  107. Fields.Add("ListPic", data.ListPic); //列表图片
  108. Fields.Add("Contents", data.Contents); //内容
  109. Fields.Add("QueryCount", data.QueryCount); //学习人数
  110. Fields.Add("Url", data.Url); //外链
  111. Fields.Add("SeoTitle", data.SeoTitle);
  112. Fields.Add("SeoKeyword", data.SeoKeyword);
  113. Fields.Add("SeoDescription", data.SeoDescription);
  114. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("SchoolMakerStudy", Fields, 0);
  115. AddSysLog(data.Id.ToString(), "SchoolMakerStudy", "add");
  116. db.SaveChanges();
  117. return "success";
  118. }
  119. #endregion
  120. #region 修改商学院创客学堂
  121. /// <summary>
  122. /// 增加或修改商学院创客学堂信息
  123. /// </summary>
  124. /// <returns></returns>
  125. public IActionResult Edit(string right, string ColId, string PColId, string CurColId, int Id = 0)
  126. {
  127. ViewBag.RightInfo = RightInfo;
  128. ViewBag.right = right;
  129. SchoolMakerStudy editData = db.SchoolMakerStudy.FirstOrDefault(m => m.Id == Id) ?? new SchoolMakerStudy();
  130. ViewBag.data = editData;
  131. return View();
  132. }
  133. #endregion
  134. #region 修改商学院创客学堂
  135. /// <summary>
  136. /// 增加或修改商学院创客学堂信息
  137. /// </summary>
  138. /// <returns></returns>
  139. [HttpPost]
  140. public string Edit(SchoolMakerStudy data, string PColId = "", string CurColId = "")
  141. {
  142. Dictionary<string, object> Fields = new Dictionary<string, object>();
  143. Fields.Add("Title", data.Title); //标题
  144. Fields.Add("Detail", data.Detail); //介绍
  145. Fields.Add("SeoTitle", data.SeoTitle); //主讲人
  146. Fields.Add("QueryCount", data.QueryCount); //观看人数
  147. Fields.Add("ListPic", data.ListPic); //列表图片
  148. Fields.Add("Contents", data.Contents); //内容
  149. Fields.Add("Url", data.Url); //外链
  150. Fields.Add("SeoKeyword", data.SeoKeyword);
  151. Fields.Add("SeoDescription", data.SeoDescription);
  152. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("SchoolMakerStudy", Fields, data.Id);
  153. AddSysLog(data.Id.ToString(), "SchoolMakerStudy", "update");
  154. db.SaveChanges();
  155. return "success";
  156. }
  157. #endregion
  158. #region 删除商学院创客学堂信息
  159. /// <summary>
  160. /// 删除商学院创客学堂信息
  161. /// </summary>
  162. /// <returns></returns>
  163. public string Delete(string Id)
  164. {
  165. string[] idlist = Id.Split(new char[] { ',' });
  166. AddSysLog(Id, "SchoolMakerStudy", "del");
  167. foreach (string subid in idlist)
  168. {
  169. int id = int.Parse(subid);
  170. Dictionary<string, object> Fields = new Dictionary<string, object>();
  171. Fields.Add("Status", -1);
  172. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("SchoolMakerStudy", Fields, id);
  173. }
  174. db.SaveChanges();
  175. return "success";
  176. }
  177. #endregion
  178. #region 开启
  179. /// <summary>
  180. /// 开启
  181. /// </summary>
  182. /// <returns></returns>
  183. public string Open(string Id)
  184. {
  185. string[] idlist = Id.Split(new char[] { ',' });
  186. AddSysLog(Id, "SchoolMakerStudy", "open");
  187. foreach (string subid in idlist)
  188. {
  189. int id = int.Parse(subid);
  190. Dictionary<string, object> Fields = new Dictionary<string, object>();
  191. Fields.Add("Status", 1);
  192. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("SchoolMakerStudy", Fields, id);
  193. }
  194. db.SaveChanges();
  195. return "success";
  196. }
  197. #endregion
  198. #region 关闭
  199. /// <summary>
  200. /// 关闭
  201. /// </summary>
  202. /// <returns></returns>
  203. public string Close(string Id)
  204. {
  205. string[] idlist = Id.Split(new char[] { ',' });
  206. AddSysLog(Id, "SchoolMakerStudy", "close");
  207. foreach (string subid in idlist)
  208. {
  209. int id = int.Parse(subid);
  210. Dictionary<string, object> Fields = new Dictionary<string, object>();
  211. Fields.Add("Status", 0);
  212. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("SchoolMakerStudy", Fields, id);
  213. }
  214. db.SaveChanges();
  215. return "success";
  216. }
  217. #endregion
  218. #region 排序
  219. /// <summary>
  220. /// 排序
  221. /// </summary>
  222. /// <param name="Id"></param>
  223. public string Sort(int Id, int Sort)
  224. {
  225. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("SchoolMakerStudy", Sort, Id);
  226. AddSysLog(Id.ToString(), "SchoolMakerStudy", "sort");
  227. return "success";
  228. }
  229. #endregion
  230. #region 导入数据
  231. /// <summary>
  232. /// 导入数据
  233. /// </summary>
  234. /// <param name="ExcelData"></param>
  235. public string Import(string ExcelData)
  236. {
  237. ExcelData = HttpUtility.UrlDecode(ExcelData);
  238. JsonData list = JsonMapper.ToObject(ExcelData);
  239. for (int i = 1; i < list.Count; i++)
  240. {
  241. JsonData dr = list[i];
  242. db.SchoolMakerStudy.Add(new SchoolMakerStudy()
  243. {
  244. CreateDate = DateTime.Now,
  245. UpdateDate = DateTime.Now,
  246. });
  247. db.SaveChanges();
  248. }
  249. AddSysLog("0", "SchoolMakerStudy", "Import");
  250. return "success";
  251. }
  252. #endregion
  253. #region 导出Excel
  254. /// <summary>
  255. /// 导出Excel
  256. /// </summary>
  257. /// <returns></returns>
  258. public JsonResult ExportExcel(SchoolMakerStudy data)
  259. {
  260. Dictionary<string, string> Fields = new Dictionary<string, string>();
  261. Fields.Add("Title", "1"); //标题
  262. Fields.Add("CreateDate", "3"); //时间
  263. string condition = " and Status>-1";
  264. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("SchoolMakerStudy", Fields, "Id desc", "0", 1, 20000, condition, "", false);
  265. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  266. foreach (Dictionary<string, object> dic in diclist)
  267. {
  268. dic["StatusName"] = dic["Status"].ToString() == "1" ? "正常" : "关闭";
  269. }
  270. Dictionary<string, object> result = new Dictionary<string, object>();
  271. result.Add("Status", "1");
  272. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  273. result.Add("Obj", diclist);
  274. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  275. result.Add("Fields", ReturnFields);
  276. AddSysLog("0", "SchoolMakerStudy", "ExportExcel");
  277. return Json(result);
  278. }
  279. #endregion
  280. }
  281. }