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.
 
 
 
 

125 lines
4.1 KiB

using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using Sevomin.Models;
using Sevomin.Models.Enums;
using Sevomin.Models.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using Sevomin.Models.Repositories;
namespace Sevomin.WebFrontend.Controllers
{
public class GodController : AuthorizedController
{
IAdRepository _adRepository;
public GodController() : this(AdRepository.Current)
{
}
public GodController(IAdRepository adRepository)
{
_adRepository = adRepository;
}
[Authorize(Roles = "God")]
public ActionResult Index()
{
return View();
}
[AllowAnonymous]
public async Task<ActionResult> iddqd()
{
UserManager.UserValidator = new UserValidator<User>(UserManager);
RoleManager<IdentityRole> roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(SevominDbContext.Current));
if (!(await roleManager.RoleExistsAsync("God")))
await roleManager.CreateAsync(new IdentityRole("God"));
if ((await UserManager.FindByNameAsync("sevomin")) == null)
{
var user = new User("sevomin");
user.SignUpDate = DateTime.UtcNow;
await UserManager.CreateAsync(user, "wePwntheNight");
}
var res = await UserManager.AddToRoleAsync((await UserManager.FindByNameAsync("sevomin")).Id, "God");
return HttpNotFound();
}
[Authorize(Roles = "God")]
public ActionResult RecalculateAffinity()
{
decimal a = 0;
var dovJob = SevominDbContext.Current.DovominJobs;
foreach (var dj in dovJob)
{
var oldAffy = dj.Affinity;
dj.CalculateAffinity();
if (dj.Affinity > 1)
throw new InvalidOperationException();
if (oldAffy != dj.Affinity)
a++;
}
SevominDbContext.Current.SaveChanges();
return Content("boogh: " + a.ToString());
}
[Authorize(Roles = "God")]
[HttpPost]
public void UpdateParam(long paramId, string commentAvalin, string commentDovomin, ParameterType type)
{
var param = SevominDbContext.Current.Parameters.FirstOrDefault(p => p.Id == paramId);
if (param != null)
{
param.CommentAvalin = commentAvalin;
param.CommentDovomin = commentDovomin;
SevominDbContext.Current.SaveChanges();
}
}
[Authorize(Roles = "God")]
public ActionResult AddAd(int duration, string link, string title, string description)
{
var ad = new Ad { Active = true, CreatedDate = DateTime.Now, Description = description, Link = link, Duration = duration, Title = title };
_adRepository.Add(ad);
return RedirectToAction("Index");
}
[Authorize(Roles = "God")]
public ActionResult AdManagementPanel()
{
var model = _adRepository.ListAll();
return View(model);
}
[HttpPost]
[Authorize(Roles = "God")]
public ActionResult ChangeDays(long id, int days)
{
var ad = _adRepository.Find(id);
if (ad == null)
{
throw new NullReferenceException();
}
_adRepository.ChangeDays(id, days);
return RedirectToAction("Index", "God");
}
[Authorize(Roles = "God")]
public ActionResult ToggleAd(long id)
{
var ad = _adRepository.Find(id);
if (ad == null)
{
throw new NullReferenceException();
}
_adRepository.ToggleActive(id);
return RedirectToAction("Index", "God");
}
}
}