Add some Faction commands, Try EF error fix
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using GTANetworkAPI;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using reallife_gamemode.Model;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using System;
|
||||
@@ -16,19 +17,33 @@ namespace reallife_gamemode.Server.Extensions
|
||||
{
|
||||
public static class ClientExtension
|
||||
{
|
||||
public static User GetUser(this Client client)
|
||||
public static User GetUser(this Client client, DatabaseContext context = null)
|
||||
{
|
||||
using(DatabaseContext dbContext = new DatabaseContext())
|
||||
if(context == null)
|
||||
{
|
||||
return dbContext.Users.FirstOrDefault(u => u.Name == client.Name);
|
||||
using (DatabaseContext dbContext = new DatabaseContext())
|
||||
{
|
||||
return dbContext.Users.FirstOrDefault(u => u.Name == client.Name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return context.Users.FirstOrDefault(u => u.Name == client.Name);
|
||||
}
|
||||
}
|
||||
|
||||
public static Faction GetFaction(this Client client)
|
||||
public static Faction GetFaction(this Client client, DatabaseContext context = null)
|
||||
{
|
||||
using (DatabaseContext dbContext = new DatabaseContext())
|
||||
if(context == null)
|
||||
{
|
||||
return dbContext.Factions.Find(client.GetUser().Faction);
|
||||
using (DatabaseContext dbContext = new DatabaseContext())
|
||||
{
|
||||
return dbContext.Factions.Find(client.GetUser(context).Faction);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return context.Factions.Find(client.GetUser(context).Faction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user