Add TransferMoney Test
This commit is contained in:
@@ -39,11 +39,12 @@ namespace reallife_gamemode.Model
|
|||||||
//User
|
//User
|
||||||
public DbSet<Server.Entities.User> Users { get; set; }
|
public DbSet<Server.Entities.User> Users { get; set; }
|
||||||
public DbSet<Server.Entities.UserVehicle> UserVehicles { get; set; }
|
public DbSet<Server.Entities.UserVehicle> UserVehicles { get; set; }
|
||||||
public DbSet<Server.Entities.UserBankAccount> BankAccounts { get; set; }
|
public DbSet<Server.Entities.UserBankAccount> UserBankAccounts { get; set; }
|
||||||
public DbSet<Server.Entities.Ban> Bans { get; set; }
|
public DbSet<Server.Entities.Ban> Bans { get; set; }
|
||||||
|
|
||||||
//Faction
|
//Faction
|
||||||
public DbSet<Server.Entities.Faction> Factions { get; set; }
|
public DbSet<Server.Entities.Faction> Factions { get; set; }
|
||||||
|
public DbSet<Server.Entities.FactionBankAccount> FactionBankAccounts { get; set; }
|
||||||
public DbSet<Server.Entities.FactionRank> FactionRanks { get; set; }
|
public DbSet<Server.Entities.FactionRank> FactionRanks { get; set; }
|
||||||
public DbSet<Server.Entities.FactionVehicle> FactionVehicles { get; set; }
|
public DbSet<Server.Entities.FactionVehicle> FactionVehicles { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ using reallife_gamemode.Server.Events;
|
|||||||
using reallife_gamemode.Server.Extensions;
|
using reallife_gamemode.Server.Extensions;
|
||||||
using reallife_gamemode.Server.Services;
|
using reallife_gamemode.Server.Services;
|
||||||
using reallife_gamemode.Server.Util;
|
using reallife_gamemode.Server.Util;
|
||||||
|
using reallife_gamemode.Server.Managers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @overview Life of German Reallife - Admin Commands (Admin.cs)
|
* @overview Life of German Reallife - Admin Commands (Admin.cs)
|
||||||
@@ -1097,6 +1098,21 @@ namespace reallife_gamemode.Server.Commands
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//TODO
|
||||||
|
[Command("pay")]
|
||||||
|
public void getType(Client player, string receiver, float amount)
|
||||||
|
{
|
||||||
|
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||||
|
{
|
||||||
|
ChatService.NotAuthorized(player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
using (var getUser = new DatabaseContext())
|
||||||
|
{
|
||||||
|
User receiverUser = getUser.Users.FirstOrDefault(u => u.Name == receiver);
|
||||||
|
BankManager.TransferUserMoneyToUser(player.GetUser(), receiverUser, amount, "/PAY");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
[Command("restart")]
|
[Command("restart")]
|
||||||
|
|||||||
31
Server/Entities/FactionBankAccount.cs
Normal file
31
Server/Entities/FactionBankAccount.cs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
using GTANetworkAPI;
|
||||||
|
using reallife_gamemode.Server.Util;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @overview Life of German Reallife - Entities FactionBankAccount (FactionBankAccount.cs)
|
||||||
|
* @author VegaZ
|
||||||
|
* @copyright (c) 2008 - 2018 Life of German
|
||||||
|
*/
|
||||||
|
namespace reallife_gamemode.Server.Entities
|
||||||
|
{
|
||||||
|
public class FactionBankAccount
|
||||||
|
{
|
||||||
|
[Key]
|
||||||
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
[ForeignKey("Faction")]
|
||||||
|
public int FactionId { get; set; }
|
||||||
|
public Faction Faction { get; set; }
|
||||||
|
[StringLength(12)]
|
||||||
|
public string Bic { get; set; }
|
||||||
|
[StringLength(32)]
|
||||||
|
public string Iban { get; set; }
|
||||||
|
public float Balance { get; set; }
|
||||||
|
public bool Active { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -34,6 +34,22 @@ 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;
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ namespace reallife_gamemode.Server.Logs
|
|||||||
public float NewSenderBalance { get; set; }
|
public float NewSenderBalance { get; set; }
|
||||||
public float NewReceiverBalance { get; set; }
|
public float NewReceiverBalance { get; set; }
|
||||||
public float Fee { get; set; }
|
public float Fee { get; set; }
|
||||||
|
[StringLength(32)]
|
||||||
|
public string Origin { get; set; }
|
||||||
[Timestamp]
|
[Timestamp]
|
||||||
public byte[] Timestamp { get; set; }
|
public byte[] Timestamp { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
44
Server/Managers/BankManager.cs
Normal file
44
Server/Managers/BankManager.cs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using GTANetworkAPI;
|
||||||
|
using reallife_gamemode.Server.Entities;
|
||||||
|
using reallife_gamemode.Server.Extensions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @overview Life of German Reallife - Managers BankManager (BankManager.cs)
|
||||||
|
* @author VegaZ
|
||||||
|
* @copyright (c) 2008 - 2018 Life of German
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
namespace reallife_gamemode.Server.Managers
|
||||||
|
{
|
||||||
|
public class BankManager : Script
|
||||||
|
{
|
||||||
|
public static void TransferUserMoneyToUser(User sender, User 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.GetUserBankAccount().Balance,
|
||||||
|
NewReceiverBalance = receiver.GetUserBankAccount().Balance += amount,
|
||||||
|
NewSenderBalance = sender.GetUserBankAccount().Balance -= amount,
|
||||||
|
Fee = 0,
|
||||||
|
Origin = origin
|
||||||
|
};
|
||||||
|
|
||||||
|
transferMoney.BankAccountTransactionLogs.Add(transactionLog);
|
||||||
|
sender.GetUserBankAccount().Balance -= amount;
|
||||||
|
receiver.GetUserBankAccount().Balance += amount;
|
||||||
|
transferMoney.SaveChanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user