The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AdminController.cs 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. SearchResultViewModel model = new SearchResultViewModel();
  61. model.Username = user.Username;
  62. if (Config.EmailConfig.Enabled)
  63. {
  64. model.Email = string.Format("{0}@{1}", user.Username, Config.EmailConfig.Domain);
  65. }
  66. model.JoinDate = user.JoinDate;
  67. model.LastSeen = UserHelper.GetLastAccountActivity(db, Config, user);
  68. models.Add(model);
  69. }
  70. }
  71. return PartialView("~/Areas/Admin/Views/Admin/SearchResults.cshtml", models);
  72. }
  73. [HttpPost]
  74. public ActionResult GetUploadSearchResults(string url)
  75. {
  76. Upload.Models.Upload foundUpload = db.Uploads.Where(u => u.Url == url).FirstOrDefault();
  77. if (foundUpload != null)
  78. {
  79. UploadResultViewModel model = new UploadResultViewModel();
  80. model.Url = foundUpload.Url;
  81. model.ContentType = foundUpload.ContentType;
  82. model.ContentLength = foundUpload.ContentLength;
  83. model.DateUploaded = foundUpload.DateUploaded;
  84. model.Downloads = foundUpload.Downloads;
  85. model.DeleteKey = foundUpload.DeleteKey;
  86. return PartialView("~/Areas/Admin/Views/Admin/UploadResult.cshtml", model);
  87. }
  88. return Json(new { error = new { message = "Upload does not exist" } });
  89. }
  90. [HttpPost]
  91. [ValidateAntiForgeryToken]
  92. public ActionResult EditUserAccountType(string username, AccountType accountType)
  93. {
  94. if (UserHelper.UserExists(db, username))
  95. {
  96. // Edit the user's account type
  97. UserHelper.EditAccountType(db, Config, username, accountType);
  98. return Json(new { result = new { success = true } });
  99. }
  100. return Redirect(Url.SubRouteUrl("error", "Error.Http404"));
  101. }
  102. }
  103. }