Add more types of moneytransfer
This commit is contained in:
@@ -1099,18 +1099,18 @@ namespace reallife_gamemode.Server.Commands
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//TODO
|
//TODO
|
||||||
[Command("pay")]
|
[Command("fpay")]
|
||||||
public void getType(Client player, string receiver, float amount)
|
public void FPay(Client player, string receiver, float amount)
|
||||||
{
|
{
|
||||||
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||||
{
|
{
|
||||||
ChatService.NotAuthorized(player);
|
ChatService.NotAuthorized(player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
using (var getUser = new DatabaseContext())
|
using (var getFaction = new DatabaseContext())
|
||||||
{
|
{
|
||||||
User receiverUser = getUser.Users.FirstOrDefault(u => u.Name == receiver);
|
Entities.Faction receiverUser = getFaction.Factions.FirstOrDefault(u => u.Name == receiver);
|
||||||
BankManager.TransferUserMoneyToUser(player.GetUser(), receiverUser, amount, "/PAY");
|
BankManager.TransferUserMoneyToFaction(player.GetUser(), receiverUser, amount, "/FPAY");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace reallife_gamemode.Server.Entities
|
|||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
[StringLength(32)]
|
[StringLength(32)]
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public int BankAccount { get; set; }
|
public float BankAccount { get; set; }
|
||||||
public bool StateOwned { get; set; }
|
public bool StateOwned { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,22 +34,6 @@ namespace reallife_gamemode.Server.Extensions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UserBankAccount GetUserBankAccount(this User user, DatabaseContext context = null)
|
|
||||||
{
|
|
||||||
using (DatabaseContext dbContext = new DatabaseContext())
|
|
||||||
if (context == null)
|
|
||||||
{
|
|
||||||
using (context = new DatabaseContext())
|
|
||||||
{
|
|
||||||
return context.UserBankAccounts.FirstOrDefault(u => u.UserId == user.Id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return context.UserBankAccounts.FirstOrDefault(u => u.UserId == user.Id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool IsLoggedIn(this Client player)
|
public static bool IsLoggedIn(this Client player)
|
||||||
{
|
{
|
||||||
return player.HasData("isLoggedIn") ? player.GetData("isLoggedIn") : false;
|
return player.HasData("isLoggedIn") ? player.GetData("isLoggedIn") : false;
|
||||||
|
|||||||
36
Server/Extensions/FactionExtension.cs
Normal file
36
Server/Extensions/FactionExtension.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
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 - Faction Extension (FactionExtension.cs)
|
||||||
|
* @author VegaZ
|
||||||
|
* @copyright (c) 2008 - 2018 Life of German
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace reallife_gamemode.Server.Extensions
|
||||||
|
{
|
||||||
|
public static class FactionExtension
|
||||||
|
{
|
||||||
|
public static FactionBankAccount GetFactionBankAccount(this Faction faction, DatabaseContext context = null)
|
||||||
|
{
|
||||||
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
|
if (context == null)
|
||||||
|
{
|
||||||
|
using (context = new DatabaseContext())
|
||||||
|
{
|
||||||
|
return context.FactionBankAccounts.FirstOrDefault(u => u.FactionId == faction.Id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return context.FactionBankAccounts.FirstOrDefault(u => u.FactionId == faction.Id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
36
Server/Extensions/UserExtension.cs
Normal file
36
Server/Extensions/UserExtension.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
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 - User Extension (UserExtension.cs)
|
||||||
|
* @author VegaZ
|
||||||
|
* @copyright (c) 2008 - 2018 Life of German
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace reallife_gamemode.Server.Extensions
|
||||||
|
{
|
||||||
|
public static class UserExtension
|
||||||
|
{
|
||||||
|
public static UserBankAccount GetUserBankAccount(this User user, DatabaseContext context = null)
|
||||||
|
{
|
||||||
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
|
if (context == null)
|
||||||
|
{
|
||||||
|
using (context = new DatabaseContext())
|
||||||
|
{
|
||||||
|
return context.UserBankAccounts.FirstOrDefault(u => u.UserId == user.Id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return context.UserBankAccounts.FirstOrDefault(u => u.UserId == user.Id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,8 +35,80 @@ namespace reallife_gamemode.Server.Managers
|
|||||||
};
|
};
|
||||||
|
|
||||||
transferMoney.BankAccountTransactionLogs.Add(transactionLog);
|
transferMoney.BankAccountTransactionLogs.Add(transactionLog);
|
||||||
sender.GetUserBankAccount().Balance -= amount;
|
sender.GetUserBankAccount(transferMoney).Balance -= amount;
|
||||||
receiver.GetUserBankAccount().Balance += amount;
|
receiver.GetUserBankAccount(transferMoney).Balance += amount;
|
||||||
|
transferMoney.SaveChanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void TransferUserMoneyToFaction(User sender, Faction receiver, float amount, string origin)
|
||||||
|
{
|
||||||
|
using (var transferMoney = new Model.DatabaseContext())
|
||||||
|
{
|
||||||
|
var transactionLog = new Logs.BankAccountTransactionHistory
|
||||||
|
{
|
||||||
|
Sender = sender.Name,
|
||||||
|
SenderBalance = sender.GetUserBankAccount().Balance,
|
||||||
|
MoneySent = amount,
|
||||||
|
Receiver = receiver.Name,
|
||||||
|
ReceiverBalance = receiver.BankAccount,
|
||||||
|
NewReceiverBalance = receiver.BankAccount += amount,
|
||||||
|
NewSenderBalance = sender.GetUserBankAccount().Balance -= amount,
|
||||||
|
Fee = 0,
|
||||||
|
Origin = origin
|
||||||
|
};
|
||||||
|
|
||||||
|
transferMoney.BankAccountTransactionLogs.Add(transactionLog);
|
||||||
|
sender.GetUserBankAccount(transferMoney).Balance -= amount;
|
||||||
|
receiver.BankAccount += amount;
|
||||||
|
transferMoney.SaveChanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void TransferFactionMoneyToUser(Faction sender, User receiver, float amount, string origin)
|
||||||
|
{
|
||||||
|
using (var transferMoney = new Model.DatabaseContext())
|
||||||
|
{
|
||||||
|
var transactionLog = new Logs.BankAccountTransactionHistory
|
||||||
|
{
|
||||||
|
Sender = sender.Name,
|
||||||
|
SenderBalance = sender.BankAccount,
|
||||||
|
MoneySent = amount,
|
||||||
|
Receiver = receiver.Name,
|
||||||
|
ReceiverBalance = receiver.GetUserBankAccount().Balance,
|
||||||
|
NewReceiverBalance = receiver.GetUserBankAccount().Balance += amount,
|
||||||
|
NewSenderBalance = sender.BankAccount -= amount,
|
||||||
|
Fee = 0,
|
||||||
|
Origin = origin
|
||||||
|
};
|
||||||
|
|
||||||
|
transferMoney.BankAccountTransactionLogs.Add(transactionLog);
|
||||||
|
sender.BankAccount -= amount;
|
||||||
|
receiver.GetUserBankAccount(transferMoney).Balance += amount;
|
||||||
|
transferMoney.SaveChanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void TransferFactionMoneyToFaction(Faction sender, Faction receiver, float amount, string origin)
|
||||||
|
{
|
||||||
|
using (var transferMoney = new Model.DatabaseContext())
|
||||||
|
{
|
||||||
|
var transactionLog = new Logs.BankAccountTransactionHistory
|
||||||
|
{
|
||||||
|
Sender = sender.Name,
|
||||||
|
SenderBalance = sender.GetFactionBankAccount().Balance,
|
||||||
|
MoneySent = amount,
|
||||||
|
Receiver = receiver.Name,
|
||||||
|
ReceiverBalance = receiver.BankAccount,
|
||||||
|
NewReceiverBalance = receiver.BankAccount += amount,
|
||||||
|
NewSenderBalance = sender.BankAccount -= amount,
|
||||||
|
Fee = 0,
|
||||||
|
Origin = origin
|
||||||
|
};
|
||||||
|
|
||||||
|
transferMoney.BankAccountTransactionLogs.Add(transactionLog);
|
||||||
|
sender.BankAccount -= amount;
|
||||||
|
receiver.BankAccount += amount;
|
||||||
transferMoney.SaveChanges();
|
transferMoney.SaveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user