TestController.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * 测试
  3. */
  4. using System;
  5. using System.Web;
  6. using System.Collections.Generic;
  7. using Microsoft.AspNetCore.Mvc;
  8. using Microsoft.AspNetCore.Http;
  9. using MySystem.Models.Bs;
  10. using Library;
  11. using LitJson;
  12. using Microsoft.AspNetCore.Authorization;
  13. using MySystem.Service.Bs;
  14. using System.Linq;
  15. namespace MySystem.Areas.Api.Controllers.v1
  16. {
  17. [Area("Api")]
  18. [Route("Api/v1/[controller]/[action]")]
  19. public class TestController : BaseController
  20. {
  21. public TestController(IHttpContextAccessor accessor) : base(accessor)
  22. {
  23. }
  24. #region 测试方法
  25. /// <summary>
  26. /// 产品库列表
  27. /// </summary>
  28. /// <returns></returns>
  29. // [HttpPost]
  30. // [Authorize]
  31. [Route("/main/test/all")]
  32. public JsonResult List(string value)
  33. {
  34. value = PublicFunction.DesDecrypt(value);
  35. JsonData jsonObj = JsonMapper.ToObject(value);
  36. // Dictionary<string, object> obj = new Dictionary<string, object>(); //返回字段
  37. // var anths = BaseClass.GetRightJson();
  38. // obj.Add("AuthsTree", anths); //主token,用于刷新apiToken
  39. List<RelationData> relationData = new List<RelationData>();
  40. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  41. var Other = new Dictionary<string, object>();
  42. int count = 0;
  43. List<Dictionary<string, object>> source = SysAdminService.List(relationData, "", out count, 1, 999);
  44. foreach (Dictionary<string, object> subdata in source)
  45. {
  46. Dictionary<string, object> curData = new Dictionary<string, object>();
  47. curData.Add("Id", subdata["Id"].ToString()); //Id
  48. curData.Add("AdminName", subdata["AdminName"].ToString()); //用户名
  49. curData.Add("RealName", subdata["RealName"].ToString()); //名称
  50. curData.Add("RoleId", subdata["Role"].ToString()); //角色
  51. curData.Add("LastLoginDate", subdata["LastLoginDate"] == null ? "" : DateTime.Parse(subdata["LastLoginDate"].ToString()).ToString("yyyy-MM-dd HH:mm:ss")); //最后登录时间
  52. dataList.Add(curData);
  53. }
  54. Other.Add("Count", count); //总数
  55. int SysAdminId = 6; //系统用户Id
  56. string AdminName = "AHHA"; //用户名
  57. string RealName = "ABBA"; //名称
  58. string PassWord = "123456"; //密码
  59. string RoleId = "1"; //角色
  60. var sysAdmin = bsdb.SysAdmin.FirstOrDefault(m => m.Id == SysAdminId) ?? new SysAdmin();
  61. if (sysAdmin.Id > 0)
  62. {
  63. if (!string.IsNullOrEmpty(AdminName))
  64. {
  65. sysAdmin.AdminName = AdminName;
  66. }
  67. if (!string.IsNullOrEmpty(RealName))
  68. {
  69. sysAdmin.RealName = RealName;
  70. }
  71. if (!string.IsNullOrEmpty(PassWord))
  72. {
  73. sysAdmin.Password = function.MD5_32(PassWord);
  74. }
  75. if (!string.IsNullOrEmpty(RoleId) && RoleId != sysAdmin.Role)
  76. {
  77. sysAdmin.Role = RoleId;
  78. }
  79. }
  80. bsdb.SaveChanges();
  81. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  82. }
  83. #endregion
  84. }
  85. }