mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-10 15:20:48 -05:00
added meta property and service for clients
started workign on a new profile page for clients
This commit is contained in:
18
SharedLibrary/Dtos/ProfileMeta.cs
Normal file
18
SharedLibrary/Dtos/ProfileMeta.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibrary.Dtos
|
||||
{
|
||||
public class ProfileMeta
|
||||
{
|
||||
public DateTime When { get; set; }
|
||||
public string WhenString => Utilities.GetTimePassed(When, false);
|
||||
public string Key { get; set; }
|
||||
public dynamic Value { get; set; }
|
||||
public virtual string Class => Value.GetType().ToString();
|
||||
}
|
||||
}
|
18
SharedLibrary/Dtos/ProfilePenalty.cs
Normal file
18
SharedLibrary/Dtos/ProfilePenalty.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibrary.Dtos
|
||||
{
|
||||
public class ProfilePenalty
|
||||
{
|
||||
public string OffenderName { get; set; }
|
||||
public int OffenderId { get; set; }
|
||||
public string PunisherName { get; set; }
|
||||
public int PunisherId { get; set; }
|
||||
public string Offense { get; set; }
|
||||
public string Type { get; set; }
|
||||
}
|
||||
}
|
@ -75,6 +75,8 @@ namespace SharedLibrary.Objects
|
||||
public Server CurrentServer { get; set; }
|
||||
[NotMapped]
|
||||
public int Score { get; set; }
|
||||
[NotMapped]
|
||||
public IList<Dtos.ProfileMeta> Meta { get; set; }
|
||||
|
||||
private int _ipaddress;
|
||||
public override int IPAddress
|
||||
|
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())
|
||||
|
@ -103,6 +103,8 @@
|
||||
<Compile Include="Database\Models\EFClient.cs" />
|
||||
<Compile Include="Database\Models\EFPenalty.cs" />
|
||||
<Compile Include="Database\Models\SharedEntity.cs" />
|
||||
<Compile Include="Dtos\ProfileMeta.cs" />
|
||||
<Compile Include="Dtos\ProfilePenalty.cs" />
|
||||
<Compile Include="Exceptions\DatabaseException.cs" />
|
||||
<Compile Include="Helpers\AsyncStatus.cs" />
|
||||
<Compile Include="Commands\NativeCommands.cs" />
|
||||
@ -139,6 +141,7 @@
|
||||
<Compile Include="Services\AliasService.cs" />
|
||||
<Compile Include="Services\ClientService.cs" />
|
||||
<Compile Include="Services\GenericRepository.cs" />
|
||||
<Compile Include="Services\MetaService.cs" />
|
||||
<Compile Include="Services\PenaltyService.cs" />
|
||||
<Compile Include="Utilities.cs" />
|
||||
<Compile Include="WebService.cs" />
|
||||
|
Reference in New Issue
Block a user