2018-02-21 20:29:23 -05:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2018-10-07 22:34:30 -04:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2018-04-08 02:44:42 -04:00
|
|
|
|
using SharedLibraryCore;
|
2018-10-07 22:34:30 -04:00
|
|
|
|
using SharedLibraryCore.Database;
|
2018-04-08 02:44:42 -04:00
|
|
|
|
using SharedLibraryCore.Dtos;
|
2019-12-02 16:52:36 -05:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
2018-02-21 20:29:23 -05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2019-05-29 17:55:35 -04:00
|
|
|
|
using static SharedLibraryCore.Database.Models.EFPenalty;
|
2018-02-21 20:29:23 -05:00
|
|
|
|
|
|
|
|
|
namespace WebfrontCore.Controllers
|
|
|
|
|
{
|
2018-03-06 02:22:19 -05:00
|
|
|
|
public class PenaltyController : BaseController
|
2018-02-21 20:29:23 -05:00
|
|
|
|
{
|
2020-11-27 22:52:52 -05:00
|
|
|
|
private readonly IDatabaseContextFactory _contextFactory;
|
|
|
|
|
|
|
|
|
|
public PenaltyController(IManager manager, IDatabaseContextFactory contextFactory) : base(manager)
|
2019-12-02 16:52:36 -05:00
|
|
|
|
{
|
2020-11-27 22:52:52 -05:00
|
|
|
|
_contextFactory = contextFactory;
|
2019-12-02 16:52:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-12 14:13:59 -05:00
|
|
|
|
public IActionResult List(PenaltyType showOnly = PenaltyType.Any, bool hideAutomatedPenalties = true)
|
2018-02-21 20:29:23 -05:00
|
|
|
|
{
|
2021-01-08 20:21:23 -05:00
|
|
|
|
ViewBag.Description = Localization["WEBFRONT_DESCRIPTION_PENALTIES"];
|
2018-05-05 18:52:04 -04:00
|
|
|
|
ViewBag.Title = Localization["WEBFRONT_PENALTY_TITLE"];
|
2021-01-08 20:21:23 -05:00
|
|
|
|
ViewBag.Keywords = Localization["WEBFRONT_KEYWORDS_PENALTIES"];
|
2020-02-12 14:13:59 -05:00
|
|
|
|
ViewBag.HideAutomatedPenalties = hideAutomatedPenalties;
|
2018-03-13 17:30:22 -04:00
|
|
|
|
|
2019-05-02 23:33:38 -04:00
|
|
|
|
return View(showOnly);
|
2018-02-21 20:29:23 -05:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-12 14:13:59 -05:00
|
|
|
|
public async Task<IActionResult> ListAsync(int offset = 0, PenaltyType showOnly = PenaltyType.Any, bool hideAutomatedPenalties = true)
|
2018-02-21 20:29:23 -05:00
|
|
|
|
{
|
2018-05-04 00:22:10 -04:00
|
|
|
|
return await Task.FromResult(View("_List", new ViewModels.PenaltyFilterInfo()
|
|
|
|
|
{
|
|
|
|
|
Offset = offset,
|
2020-02-12 14:13:59 -05:00
|
|
|
|
ShowOnly = showOnly,
|
|
|
|
|
IgnoreAutomated = hideAutomatedPenalties
|
2018-05-04 00:22:10 -04:00
|
|
|
|
}));
|
2018-02-21 20:29:23 -05:00
|
|
|
|
}
|
2018-03-13 17:30:22 -04:00
|
|
|
|
|
2019-03-24 22:34:20 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// retrieves all permanent bans ordered by ban date
|
|
|
|
|
/// if request is authorized, it will include the client's ip address.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2018-03-13 17:30:22 -04:00
|
|
|
|
public async Task<IActionResult> PublicAsync()
|
|
|
|
|
{
|
2019-03-24 22:34:20 -04:00
|
|
|
|
IList<PenaltyInfo> penalties;
|
2018-10-07 22:34:30 -04:00
|
|
|
|
|
2020-11-27 22:52:52 -05:00
|
|
|
|
await using var ctx = _contextFactory.CreateContext(false);
|
|
|
|
|
var iqPenalties = ctx.Penalties
|
|
|
|
|
.AsNoTracking()
|
|
|
|
|
.Where(p => p.Type == PenaltyType.Ban && p.Active)
|
|
|
|
|
.OrderByDescending(_penalty => _penalty.When)
|
|
|
|
|
.Select(p => new PenaltyInfo()
|
|
|
|
|
{
|
|
|
|
|
Id = p.PenaltyId,
|
|
|
|
|
OffenderId = p.OffenderId,
|
|
|
|
|
OffenderName = p.Offender.CurrentAlias.Name,
|
|
|
|
|
OffenderNetworkId = (ulong)p.Offender.NetworkId,
|
|
|
|
|
OffenderIPAddress = Authorized ? p.Offender.CurrentAlias.IPAddress.ConvertIPtoString() : null,
|
|
|
|
|
Offense = p.Offense,
|
|
|
|
|
PunisherId = p.PunisherId,
|
|
|
|
|
PunisherNetworkId = (ulong)p.Punisher.NetworkId,
|
|
|
|
|
PunisherName = p.Punisher.CurrentAlias.Name,
|
|
|
|
|
PunisherIPAddress = Authorized ? p.Punisher.CurrentAlias.IPAddress.ConvertIPtoString() : null,
|
|
|
|
|
TimePunished = p.When,
|
|
|
|
|
AutomatedOffense = Authorized ? p.AutomatedOffense : null,
|
|
|
|
|
});
|
2018-03-13 17:30:22 -04:00
|
|
|
|
|
2020-11-27 22:52:52 -05:00
|
|
|
|
penalties = await iqPenalties.ToListAsync();
|
2018-03-13 17:30:22 -04:00
|
|
|
|
|
2019-03-24 22:34:20 -04:00
|
|
|
|
return Json(penalties);
|
2018-03-13 17:30:22 -04:00
|
|
|
|
}
|
2018-02-21 20:29:23 -05:00
|
|
|
|
}
|
|
|
|
|
}
|