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.

124 lines
4.1 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. using Microsoft.AspNet.Identity;
  2. using Microsoft.AspNet.Identity.EntityFramework;
  3. using Sevomin.Models;
  4. using Sevomin.Models.Enums;
  5. using Sevomin.Models.Helpers;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Web.Mvc;
  12. using Sevomin.Models.Repositories;
  13. namespace Sevomin.WebFrontend.Controllers
  14. {
  15. public class GodController : AuthorizedController
  16. {
  17. IAdRepository _adRepository;
  18. public GodController() : this(AdRepository.Current)
  19. {
  20. }
  21. public GodController(IAdRepository adRepository)
  22. {
  23. _adRepository = adRepository;
  24. }
  25. [Authorize(Roles = "God")]
  26. public ActionResult Index()
  27. {
  28. return View();
  29. }
  30. [AllowAnonymous]
  31. public async Task<ActionResult> iddqd()
  32. {
  33. UserManager.UserValidator = new UserValidator<User>(UserManager);
  34. RoleManager<IdentityRole> roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(SevominDbContext.Current));
  35. if (!(await roleManager.RoleExistsAsync("God")))
  36. await roleManager.CreateAsync(new IdentityRole("God"));
  37. if ((await UserManager.FindByNameAsync("sevomin")) == null)
  38. {
  39. var user = new User("sevomin");
  40. user.SignUpDate = DateTime.UtcNow;
  41. await UserManager.CreateAsync(user, "wePwntheNight");
  42. }
  43. var res = await UserManager.AddToRoleAsync((await UserManager.FindByNameAsync("sevomin")).Id, "God");
  44. return HttpNotFound();
  45. }
  46. [Authorize(Roles = "God")]
  47. public ActionResult RecalculateAffinity()
  48. {
  49. decimal a = 0;
  50. var dovJob = SevominDbContext.Current.DovominJobs;
  51. foreach (var dj in dovJob)
  52. {
  53. var oldAffy = dj.Affinity;
  54. dj.CalculateAffinity();
  55. if (dj.Affinity > 1)
  56. throw new InvalidOperationException();
  57. if (oldAffy != dj.Affinity)
  58. a++;
  59. }
  60. SevominDbContext.Current.SaveChanges();
  61. return Content("boogh: " + a.ToString());
  62. }
  63. [Authorize(Roles = "God")]
  64. [HttpPost]
  65. public void UpdateParam(long paramId, string commentAvalin, string commentDovomin, ParameterType type)
  66. {
  67. var param = SevominDbContext.Current.Parameters.FirstOrDefault(p => p.Id == paramId);
  68. if (param != null)
  69. {
  70. param.CommentAvalin = commentAvalin;
  71. param.CommentDovomin = commentDovomin;
  72. SevominDbContext.Current.SaveChanges();
  73. }
  74. }
  75. [Authorize(Roles = "God")]
  76. public ActionResult AddAd(int duration, string link, string title, string description)
  77. {
  78. var ad = new Ad { Active = true, CreatedDate = DateTime.Now, Description = description, Link = link, Duration = duration, Title = title };
  79. _adRepository.Add(ad);
  80. return RedirectToAction("Index");
  81. }
  82. [Authorize(Roles = "God")]
  83. public ActionResult AdManagementPanel()
  84. {
  85. var model = _adRepository.ListAll();
  86. return View(model);
  87. }
  88. [HttpPost]
  89. [Authorize(Roles = "God")]
  90. public ActionResult ChangeDays(long id, int days)
  91. {
  92. var ad = _adRepository.Find(id);
  93. if (ad == null)
  94. {
  95. throw new NullReferenceException();
  96. }
  97. _adRepository.ChangeDays(id, days);
  98. return RedirectToAction("Index", "God");
  99. }
  100. [Authorize(Roles = "God")]
  101. public ActionResult ToggleAd(long id)
  102. {
  103. var ad = _adRepository.Find(id);
  104. if (ad == null)
  105. {
  106. throw new NullReferenceException();
  107. }
  108. _adRepository.ToggleActive(id);
  109. return RedirectToAction("Index", "God");
  110. }
  111. }
  112. }