The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

AdminController.cs 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using Teknik.Areas.Admin.ViewModels;
  7. using Teknik.Areas.Users.Models;
  8. using Teknik.Areas.Users.Utility;
  9. using Teknik.Attributes;
  10. using Teknik.Controllers;
  11. using Teknik.Models;
  12. using Teknik.Utilities;
  13. using Teknik.ViewModels;
  14. namespace Teknik.Areas.Admin.Controllers
  15. {
  16. [TeknikAuthorize(Roles = "Admin")]
  17. public class AdminController : DefaultController
  18. {
  19. private TeknikEntities db = new TeknikEntities();
  20. [HttpGet]
  21. public ActionResult Dashboard()
  22. {
  23. DashboardViewModel model = new DashboardViewModel();
  24. return View(model);
  25. }
  26. [HttpGet]
  27. public ActionResult Search()
  28. {
  29. SearchViewModel model = new SearchViewModel();
  30. return View(model);
  31. }
  32. [HttpGet]
  33. public ActionResult UserInfo(string username)
  34. {
  35. if (UserHelper.UserExists(db, username))
  36. {
  37. User user = UserHelper.GetUser(db, username);
  38. UserInfoViewModel model = new UserInfoViewModel();
  39. model.Username = user.Username;
  40. model.AccountType = user.AccountType;
  41. return View(model);
  42. }
  43. return Redirect(Url.SubRouteUrl("error", "Error.Http404"));
  44. }
  45. [HttpGet]
  46. public ActionResult UploadSearch()
  47. {
  48. UploadSearchViewModel model = new UploadSearchViewModel();
  49. return View(model);
  50. }
  51. [HttpPost]
  52. public ActionResult GetSearchResults(string query)
  53. {
  54. List<SearchResultViewModel> models = new List<SearchResultViewModel>();
  55. var results = db.Users.Where(u => u.Username.Contains(query)).ToList();
  56. if (results != null)
  57. {
  58. foreach (Users.Models.User user in results)
  59. {
  60. try
  61. {
  62. SearchResultViewModel model = new SearchResultViewModel();
  63. model.Username = user.Username;
  64. if (Config.EmailConfig.Enabled)
  65. {
  66. model.Email = string.Format("{0}@{1}", user.Username, Config.EmailConfig.Domain);
  67. }
  68. model.JoinDate = user.JoinDate;
  69. model.LastSeen = UserHelper.GetLastAccountActivity(db, Config, user);
  70. models.Add(model);
  71. }
  72. catch (Exception ex)
  73. {
  74. // Skip this result
  75. }
  76. }
  77. }
  78. return PartialView("~/Areas/Admin/Views/Admin/SearchResults.cshtml", models);
  79. }
  80. [HttpPost]
  81. public ActionResult GetUploadSearchResults(string url)
  82. {
  83. Upload.Models.Upload foundUpload = db.Uploads.Where(u => u.Url == url).FirstOrDefault();
  84. if (foundUpload != null)
  85. {
  86. UploadResultViewModel model = new UploadResultViewModel();
  87. model.Url = foundUpload.Url;
  88. model.ContentType = foundUpload.ContentType;
  89. model.ContentLength = foundUpload.ContentLength;
  90. model.DateUploaded = foundUpload.DateUploaded;
  91. model.Downloads = foundUpload.Downloads;
  92. model.DeleteKey = foundUpload.DeleteKey;
  93. return PartialView("~/Areas/Admin/Views/Admin/UploadResult.cshtml", model);
  94. }
  95. return Json(new { error = new { message = "Upload does not exist" } });
  96. }
  97. [HttpPost]
  98. [ValidateAntiForgeryToken]
  99. public ActionResult EditUserAccountType(string username, AccountType accountType)
  100. {
  101. if (UserHelper.UserExists(db, username))
  102. {
  103. // Edit the user's account type
  104. UserHelper.EditAccountType(db, Config, username, accountType);
  105. return Json(new { result = new { success = true } });
  106. }
  107. return Redirect(Url.SubRouteUrl("error", "Error.Http404"));
  108. }
  109. }
  110. }