migrate welcome plugin to .NET Core 2.0
more fixes to stats database for migration last connection set when client connects and disconnects update GeoIP datatbase
This commit is contained in:
@ -193,7 +193,7 @@ namespace SharedLibraryCore.Services
|
||||
{
|
||||
using (var context = new DatabaseContext())
|
||||
return await context.Clients
|
||||
.Where(c => c.Level == Objects.Player.Permission.Owner)
|
||||
.Where(c => c.Level == Player.Permission.Owner)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
@ -229,18 +229,18 @@ namespace SharedLibraryCore.Services
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
var iqClients = (from alias in context.Aliases
|
||||
.AsNoTracking()
|
||||
where alias.Name
|
||||
.Contains(name)
|
||||
join link in context.AliasLinks
|
||||
on alias.LinkId equals link.AliasLinkId
|
||||
join client in context.Clients
|
||||
.AsNoTracking()
|
||||
on alias.LinkId equals client.AliasLinkId
|
||||
select client)
|
||||
.Distinct()
|
||||
.Include(c => c.CurrentAlias)
|
||||
.Include(c => c.AliasLink.Children);
|
||||
.AsNoTracking()
|
||||
where alias.Name
|
||||
.Contains(name)
|
||||
join link in context.AliasLinks
|
||||
on alias.LinkId equals link.AliasLinkId
|
||||
join client in context.Clients
|
||||
.AsNoTracking()
|
||||
on alias.LinkId equals client.AliasLinkId
|
||||
select client)
|
||||
.Distinct()
|
||||
.Include(c => c.CurrentAlias)
|
||||
.Include(c => c.AliasLink.Children);
|
||||
|
||||
return await iqClients.ToListAsync();
|
||||
}
|
||||
@ -251,17 +251,17 @@ namespace SharedLibraryCore.Services
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
var iqClients = (from alias in context.Aliases
|
||||
.AsNoTracking()
|
||||
where alias.IPAddress == ipAddress
|
||||
join link in context.AliasLinks
|
||||
on alias.LinkId equals link.AliasLinkId
|
||||
join client in context.Clients
|
||||
.AsNoTracking()
|
||||
on alias.LinkId equals client.AliasLinkId
|
||||
select client)
|
||||
.Distinct()
|
||||
.Include(c => c.CurrentAlias)
|
||||
.Include(c => c.AliasLink.Children);
|
||||
.AsNoTracking()
|
||||
where alias.IPAddress == ipAddress
|
||||
join link in context.AliasLinks
|
||||
on alias.LinkId equals link.AliasLinkId
|
||||
join client in context.Clients
|
||||
.AsNoTracking()
|
||||
on alias.LinkId equals client.AliasLinkId
|
||||
select client)
|
||||
.Distinct()
|
||||
.Include(c => c.CurrentAlias)
|
||||
.Include(c => c.AliasLink.Children);
|
||||
|
||||
return await iqClients.ToListAsync();
|
||||
}
|
||||
@ -288,7 +288,7 @@ namespace SharedLibraryCore.Services
|
||||
.AsNoTracking()
|
||||
.Where(c => (DateTime.UtcNow - c.LastConnection).TotalDays >= inactiveDays)
|
||||
.ToListAsync();
|
||||
inactive.ForEach(c => c.Level = Objects.Player.Permission.User);
|
||||
inactive.ForEach(c => c.Level = Player.Permission.User);
|
||||
await context.SaveChangesAsync();
|
||||
return inactive;
|
||||
}
|
||||
|
@ -51,11 +51,14 @@ namespace SharedLibraryCore.Services
|
||||
return this.GetQuery(predicate, orderExpression).AsEnumerable();
|
||||
}
|
||||
|
||||
|
||||
public virtual IQueryable<TEntity> GetQuery(Expression<Func<TEntity, bool>> predicate = null, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderExpression = null)
|
||||
{
|
||||
IQueryable<TEntity> qry = this.DBSet;
|
||||
|
||||
foreach (var property in this.Context.Model.FindEntityType(typeof(TEntity)).GetNavigations())
|
||||
qry = qry.Include(property.Name);
|
||||
|
||||
|
||||
if (predicate != null)
|
||||
qry = qry.Where(predicate);
|
||||
|
||||
|
@ -14,36 +14,45 @@ namespace SharedLibraryCore.Services
|
||||
{
|
||||
public class PenaltyService : Interfaces.IEntityService<EFPenalty>
|
||||
{
|
||||
public async Task<EFPenalty> Create(EFPenalty entity)
|
||||
public async Task<EFPenalty> Create(EFPenalty newEntity)
|
||||
{
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
entity.Offender = context.Clients.Single(e => e.ClientId == entity.Offender.ClientId);
|
||||
entity.Punisher = context.Clients.Single(e => e.ClientId == entity.Punisher.ClientId);
|
||||
entity.Link = context.AliasLinks.Single(l => l.AliasLinkId == entity.Link.AliasLinkId);
|
||||
// create the actual EFPenalty
|
||||
EFPenalty addedEntity = new EFPenalty()
|
||||
{
|
||||
OffenderId = newEntity.Offender.ClientId,
|
||||
PunisherId = newEntity.Punisher.ClientId,
|
||||
LinkId = newEntity.Link.AliasLinkId,
|
||||
Type = newEntity.Type,
|
||||
Active = true,
|
||||
Expires = newEntity.Expires,
|
||||
Offense = newEntity.Offense,
|
||||
When = newEntity.When,
|
||||
};
|
||||
|
||||
if (entity.Expires == DateTime.MaxValue)
|
||||
entity.Expires = DateTime.Parse(System.Data.SqlTypes.SqlDateTime.MaxValue.ToString());
|
||||
if (addedEntity.Expires == DateTime.MaxValue)
|
||||
addedEntity.Expires = DateTime.Parse(System.Data.SqlTypes.SqlDateTime.MaxValue.ToString());
|
||||
|
||||
// make bans propogate to all aliases
|
||||
if (entity.Type == Objects.Penalty.PenaltyType.Ban)
|
||||
if (addedEntity.Type == Objects.Penalty.PenaltyType.Ban)
|
||||
{
|
||||
await context.Clients
|
||||
.Where(c => c.AliasLinkId == entity.Link.AliasLinkId)
|
||||
.Where(c => c.AliasLinkId == addedEntity.LinkId)
|
||||
.ForEachAsync(c => c.Level = Objects.Player.Permission.Banned);
|
||||
}
|
||||
|
||||
// make flags propogate to all aliases
|
||||
else if (entity.Type == Objects.Penalty.PenaltyType.Flag)
|
||||
else if (addedEntity.Type == Objects.Penalty.PenaltyType.Flag)
|
||||
{
|
||||
await context.Clients
|
||||
.Where(c => c.AliasLinkId == entity.Link.AliasLinkId)
|
||||
.Where(c => c.AliasLinkId == addedEntity.LinkId)
|
||||
.ForEachAsync(c => c.Level = Objects.Player.Permission.Flagged);
|
||||
}
|
||||
|
||||
context.Penalties.Add(entity);
|
||||
context.Penalties.Add(addedEntity);
|
||||
await context.SaveChangesAsync();
|
||||
return entity;
|
||||
return addedEntity;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user