mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-11 07:40:54 -05:00
added meta property and service for clients
started workign on a new profile page for clients
This commit is contained in:
27
SharedLibrary/Services/MetaService.cs
Normal file
27
SharedLibrary/Services/MetaService.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using SharedLibrary.Dtos;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibrary.Services
|
||||
{
|
||||
public class MetaService
|
||||
{
|
||||
private static List<Func<int, Task<List<ProfileMeta>>>> MetaActions = new List<Func<int, Task<List<ProfileMeta>>>>();
|
||||
|
||||
public static void AddMeta(Func<int, Task<List<ProfileMeta>>> metaAction)
|
||||
{
|
||||
MetaActions.Add(metaAction);
|
||||
}
|
||||
|
||||
public static async Task<List<ProfileMeta>> GetMeta(int clientId)
|
||||
{
|
||||
var meta = new List<ProfileMeta>();
|
||||
foreach (var action in MetaActions)
|
||||
meta.AddRange(await action(clientId));
|
||||
return meta;
|
||||
}
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ using System.Data.Entity;
|
||||
using SharedLibrary.Database;
|
||||
using SharedLibrary.Database.Models;
|
||||
using System.Linq.Expressions;
|
||||
using SharedLibrary.Dtos;
|
||||
|
||||
namespace SharedLibrary.Services
|
||||
{
|
||||
@ -56,6 +57,8 @@ namespace SharedLibrary.Services
|
||||
|
||||
public async Task<IList<EFPenalty>> Find(Func<EFPenalty, bool> expression)
|
||||
{
|
||||
return await Task.FromResult(new List<EFPenalty>());
|
||||
// fixme: this is so slow!
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
using (var context = new DatabaseContext())
|
||||
@ -109,6 +112,86 @@ namespace SharedLibrary.Services
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a read-only copy of client penalties
|
||||
/// </summary>
|
||||
/// <param name="clientI"></param>
|
||||
/// <param name="victim">Retreive penalties for clients receiving penalties, other wise given</param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<ProfileMeta>> ReadGetClientPenaltiesAsync(int clientId, bool victim = true)
|
||||
{
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
context.Configuration.LazyLoadingEnabled = false;
|
||||
context.Configuration.ProxyCreationEnabled = false;
|
||||
context.Configuration.AutoDetectChangesEnabled = false;
|
||||
|
||||
if (victim)
|
||||
{
|
||||
var iqPenalties = from penalty in context.Penalties.AsNoTracking()
|
||||
where penalty.OffenderId == clientId
|
||||
join victimClient in context.Clients.AsNoTracking()
|
||||
on penalty.OffenderId equals victimClient.ClientId
|
||||
join victimAlias in context.Aliases
|
||||
on victimClient.CurrentAliasId equals victimAlias.AliasId
|
||||
join punisherClient in context.Clients
|
||||
on penalty.PunisherId equals punisherClient.ClientId
|
||||
join punisherAlias in context.Aliases
|
||||
on punisherClient.CurrentAliasId equals punisherAlias.AliasId
|
||||
//orderby penalty.When descending
|
||||
select new ProfileMeta()
|
||||
{
|
||||
Key = "Event.Penalty",
|
||||
Value = new ProfilePenalty
|
||||
{
|
||||
OffenderName = victimAlias.Name,
|
||||
OffenderId = victimClient.ClientId,
|
||||
PunisherName = punisherAlias.Name,
|
||||
PunisherId = penalty.PunisherId,
|
||||
Offense = penalty.Offense,
|
||||
Type = penalty.Type.ToString()
|
||||
},
|
||||
When = penalty.When
|
||||
};
|
||||
// fixme: is this good and fast?
|
||||
return await iqPenalties.ToListAsync();
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
var iqPenalties = from penalty in context.Penalties.AsNoTracking()
|
||||
where penalty.PunisherId == clientId
|
||||
join victimClient in context.Clients.AsNoTracking()
|
||||
on penalty.OffenderId equals victimClient.ClientId
|
||||
join victimAlias in context.Aliases
|
||||
on victimClient.CurrentAliasId equals victimAlias.AliasId
|
||||
join punisherClient in context.Clients
|
||||
on penalty.PunisherId equals punisherClient.ClientId
|
||||
join punisherAlias in context.Aliases
|
||||
on punisherClient.CurrentAliasId equals punisherAlias.AliasId
|
||||
//orderby penalty.When descending
|
||||
select new ProfileMeta()
|
||||
{
|
||||
Key = "Event.Penalty",
|
||||
Value = new ProfilePenalty
|
||||
{
|
||||
OffenderName = victimAlias.Name,
|
||||
OffenderId = victimClient.ClientId,
|
||||
PunisherName = punisherAlias.Name,
|
||||
PunisherId = penalty.PunisherId,
|
||||
Offense = penalty.Offense,
|
||||
Type = penalty.Type.ToString()
|
||||
},
|
||||
When = penalty.When
|
||||
};
|
||||
// fixme: is this good and fast?
|
||||
return await iqPenalties.ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public async Task RemoveActivePenalties(int aliasLinkId)
|
||||
{
|
||||
using (var context = new DatabaseContext())
|
||||
|
Reference in New Issue
Block a user