diff --git a/Sevomin.Models/DovominJob.cs b/Sevomin.Models/DovominJob.cs index fde65e1..b192aac 100644 --- a/Sevomin.Models/DovominJob.cs +++ b/Sevomin.Models/DovominJob.cs @@ -98,9 +98,9 @@ namespace Sevomin.Models // sum += m * ((jpv.Value - dpv.Value) / (jpv.Value == 0 ? (decimal)0.000001 : jpv.Value)); } if (maxPoint == 0) - this.Affinity = 100; - - this.Affinity = Math.Round( sum / maxPoint, 2, MidpointRounding.ToEven) * 100; + this.Affinity = 1; + else + this.Affinity = Math.Round(sum / maxPoint, 2, MidpointRounding.ToEven); } } } diff --git a/Sevomin.WebFrontend.Controllers/GodController.cs b/Sevomin.WebFrontend.Controllers/GodController.cs index 5eaf6ac..6519a46 100644 --- a/Sevomin.WebFrontend.Controllers/GodController.cs +++ b/Sevomin.WebFrontend.Controllers/GodController.cs @@ -1,56 +1,74 @@ -using Microsoft.AspNet.Identity; -using Microsoft.AspNet.Identity.EntityFramework; -using Sevomin.Models; -using Sevomin.Models.Helpers; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Web.Mvc; - -namespace Sevomin.WebFrontend.Controllers -{ - public class GodController : AuthorizedController - { - [Authorize(Roles = "God")] - public ActionResult Index() - { - return View(); - } - - [AllowAnonymous] - public async Task iddqd() - { - UserManager.UserValidator = new UserValidator(UserManager); - RoleManager roleManager = new RoleManager(new RoleStore(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")] - [HttpPost] - public void UpdateParam(long paramId, string commentAvalin, string commentDovomin) - { - var param = SevominDbContext.Current.Parameters.FirstOrDefault(p => p.Id == paramId); - if (param != null) - { - param.CommentAvalin = commentAvalin; - param.CommentDovomin = commentDovomin; - - SevominDbContext.Current.SaveChanges(); - } - } - - } -} +using Microsoft.AspNet.Identity; +using Microsoft.AspNet.Identity.EntityFramework; +using Sevomin.Models; +using Sevomin.Models.Helpers; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web.Mvc; + +namespace Sevomin.WebFrontend.Controllers +{ + public class GodController : AuthorizedController + { + [Authorize(Roles = "God")] + public ActionResult Index() + { + return View(); + } + + [AllowAnonymous] + public async Task iddqd() + { + UserManager.UserValidator = new UserValidator(UserManager); + RoleManager roleManager = new RoleManager(new RoleStore(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) + { + var param = SevominDbContext.Current.Parameters.FirstOrDefault(p => p.Id == paramId); + if (param != null) + { + param.CommentAvalin = commentAvalin; + param.CommentDovomin = commentDovomin; + + SevominDbContext.Current.SaveChanges(); + } + } + + } +}