Files
reallife-gamemode/Server/Extensions/ClientExtension.cs

55 lines
1.6 KiB
C#

using GTANetworkAPI;
using Microsoft.EntityFrameworkCore;
using reallife_gamemode.Model;
using reallife_gamemode.Server.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
/**
* @overview Life of German Reallife - Client Extension (ClientExtension.cs)
* @author hydrant
* @copyright (c) 2008 - 2018 Life of German
*/
namespace reallife_gamemode.Server.Extensions
{
public static class ClientExtension
{
public static User GetUser(this Client client, DatabaseContext context = null)
{
if(context == null)
{
using (context = new DatabaseContext())
{
return context.Users.FirstOrDefault(u => u.Name == client.Name);
}
}
else
{
return context.Users.FirstOrDefault(u => u.Name == client.Name);
}
}
public static Faction GetFaction(this Client client, DatabaseContext context = null)
{
if(context == null)
{
using(context = new DatabaseContext())
{
User u = client.GetUser();
if (u == null) return null;
return context.Factions.FirstOrDefault(f => f.Id == u.FactionId);
}
}
else
{
User u = client.GetUser();
if (u == null) return null;
return context.Factions.FirstOrDefault(f => f.Id == u.FactionId);
}
}
}
}