Simplified bank money transfer
This commit is contained in:
@@ -1631,7 +1631,7 @@ namespace reallife_gamemode.Server.Commands
|
|||||||
|
|
||||||
using (var dbContext = new DatabaseContext())
|
using (var dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
target.GetUser().GetUserBankAccount(dbContext).Balance = amount;
|
target.GetUser().GetBankAccount(dbContext).Balance = amount;
|
||||||
dbContext.SaveChanges();
|
dbContext.SaveChanges();
|
||||||
}
|
}
|
||||||
player.SendChatMessage("~b~[ADMIN]~s~ Du hast das Geld von " + target.Name + " auf ~g~$" + amount + "~s~ gesetzt.");
|
player.SendChatMessage("~b~[ADMIN]~s~ Du hast das Geld von " + target.Name + " auf ~g~$" + amount + "~s~ gesetzt.");
|
||||||
@@ -1655,7 +1655,7 @@ namespace reallife_gamemode.Server.Commands
|
|||||||
|
|
||||||
using (var dbContext = new DatabaseContext())
|
using (var dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
target.GetUser().GetUserBankAccount(dbContext).Balance += amount;
|
target.GetUser().GetBankAccount(dbContext).Balance += amount;
|
||||||
dbContext.SaveChanges();
|
dbContext.SaveChanges();
|
||||||
}
|
}
|
||||||
player.SendChatMessage("~b~[ADMIN]~s~ Du hast " + target.Name + " ~g~$" + amount + "~s~ gegeben.");
|
player.SendChatMessage("~b~[ADMIN]~s~ Du hast " + target.Name + " ~g~$" + amount + "~s~ gegeben.");
|
||||||
@@ -1752,7 +1752,14 @@ namespace reallife_gamemode.Server.Commands
|
|||||||
using (var getFaction = new DatabaseContext())
|
using (var getFaction = new DatabaseContext())
|
||||||
{
|
{
|
||||||
Entities.Faction receiverUser = getFaction.Factions.FirstOrDefault(u => u.Name == receiver);
|
Entities.Faction receiverUser = getFaction.Factions.FirstOrDefault(u => u.Name == receiver);
|
||||||
BankManager.TransferUserMoneyToFaction(player.GetUser(), receiverUser, amount, "/FPAY");
|
|
||||||
|
if(receiverUser == null)
|
||||||
|
{
|
||||||
|
player.SendChatMessage("~r~[FEHLER]~s~ Diese Fraktion existiert nicht.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BankManager.TransferMoney(player.GetUser(), receiverUser, amount, "/FPAY");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1774,7 +1781,7 @@ namespace reallife_gamemode.Server.Commands
|
|||||||
{
|
{
|
||||||
ShopVehicle sVehicle = getShopVehicle.ShopVehicles.FirstOrDefault(u => u.Id == shopVehicleId);
|
ShopVehicle sVehicle = getShopVehicle.ShopVehicles.FirstOrDefault(u => u.Id == shopVehicleId);
|
||||||
Entities.Faction receiverUser = getShopVehicle.Factions.FirstOrDefault(u => u.Name == "LSPD");
|
Entities.Faction receiverUser = getShopVehicle.Factions.FirstOrDefault(u => u.Name == "LSPD");
|
||||||
BankManager.TransferUserMoneyToFaction(player.GetUser(), receiverUser, sVehicle.Price, "Fahrzeug gekauft: " + sVehicle.ModelName);
|
BankManager.TransferMoney(player.GetUser(), receiverUser, sVehicle.Price, "Fahrzeug gekauft: " + sVehicle.ModelName);
|
||||||
//TODO Anpassen
|
//TODO Anpassen
|
||||||
Vehicle boughtVehicle = NAPI.Vehicle.CreateVehicle(sVehicle.Model, new Vector3(sVehicle.PositionX, sVehicle.PositionY + 10, sVehicle.PositionZ + 0.5), sVehicle.Heading,
|
Vehicle boughtVehicle = NAPI.Vehicle.CreateVehicle(sVehicle.Model, new Vector3(sVehicle.PositionX, sVehicle.PositionY + 10, sVehicle.PositionZ + 0.5), sVehicle.Heading,
|
||||||
sVehicle.PrimaryColor, sVehicle.SecondaryColor, "LoG", sVehicle.Alpha, false, true, 0);
|
sVehicle.PrimaryColor, sVehicle.SecondaryColor, "LoG", sVehicle.Alpha, false, true, 0);
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using reallife_gamemode.Model;
|
||||||
|
using reallife_gamemode.Server.Util;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -13,14 +16,28 @@ using System.Text;
|
|||||||
|
|
||||||
namespace reallife_gamemode.Server.Entities
|
namespace reallife_gamemode.Server.Entities
|
||||||
{
|
{
|
||||||
public class Faction
|
public class Faction : IBankAccountOwner
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||||
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 bool StateOwned { get; set; }
|
public bool StateOwned { get; set; }
|
||||||
|
|
||||||
|
public IBankAccount GetBankAccount(DatabaseContext databaseContext = null)
|
||||||
|
{
|
||||||
|
if (databaseContext == null)
|
||||||
|
{
|
||||||
|
using (databaseContext = new DatabaseContext())
|
||||||
|
{
|
||||||
|
return databaseContext.FactionBankAccounts.FirstOrDefault(u => u.FactionId == this.Id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return databaseContext.FactionBankAccounts.FirstOrDefault(u => u.FactionId == this.Id);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ using System.Text;
|
|||||||
*/
|
*/
|
||||||
namespace reallife_gamemode.Server.Entities
|
namespace reallife_gamemode.Server.Entities
|
||||||
{
|
{
|
||||||
public class FactionBankAccount
|
public class FactionBankAccount : IBankAccount
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ using System.Text;
|
|||||||
|
|
||||||
namespace reallife_gamemode.Server.Entities
|
namespace reallife_gamemode.Server.Entities
|
||||||
{
|
{
|
||||||
public class User
|
public class User : IBankAccountOwner
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||||
@@ -28,8 +28,8 @@ namespace reallife_gamemode.Server.Entities
|
|||||||
[StringLength(64)]
|
[StringLength(64)]
|
||||||
public string Password { get; set; }
|
public string Password { get; set; }
|
||||||
public int LogUserId { get; set; }
|
public int LogUserId { get; set; }
|
||||||
[Timestamp]
|
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
|
||||||
public byte[] RegistrationDate { get; set; }
|
public DateTime RegistrationDate { get; set; }
|
||||||
|
|
||||||
[EmailAddress]
|
[EmailAddress]
|
||||||
[StringLength(64)]
|
[StringLength(64)]
|
||||||
@@ -131,5 +131,20 @@ namespace reallife_gamemode.Server.Entities
|
|||||||
}
|
}
|
||||||
|
|
||||||
public bool IsAdmin(AdminLevel level) => AdminLevel >= level;
|
public bool IsAdmin(AdminLevel level) => AdminLevel >= level;
|
||||||
|
|
||||||
|
public IBankAccount GetBankAccount(DatabaseContext databaseContext = null)
|
||||||
|
{
|
||||||
|
if (databaseContext == null)
|
||||||
|
{
|
||||||
|
using (databaseContext = new DatabaseContext())
|
||||||
|
{
|
||||||
|
return databaseContext.UserBankAccounts.FirstOrDefault(u => u.UserId == this.Id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return databaseContext.UserBankAccounts.FirstOrDefault(u => u.UserId == this.Id);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,9 @@ using System.Linq;
|
|||||||
|
|
||||||
namespace reallife_gamemode.Server.Entities
|
namespace reallife_gamemode.Server.Entities
|
||||||
{
|
{
|
||||||
public class UserBankAccount
|
public class UserBankAccount : IBankAccount
|
||||||
{
|
{
|
||||||
|
[NotMapped]
|
||||||
private int _balance;
|
private int _balance;
|
||||||
|
|
||||||
[Key]
|
[Key]
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
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
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Gibt das Bankkonto einer Fraktion zurück
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="faction">Die Fraktion, dessen Bankkonto man bekommen möchte</param>
|
|
||||||
/// <param name="context">Ein eventuell vorhandener Datenbank-Context, falls man Änderungen in der Datenbank vornehmen will</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static FactionBankAccount GetFactionBankAccount(this Faction faction, DatabaseContext context = null)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
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
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Gibt das Bankkonto eines Users zurück
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="user">Der User, dessen Bankkonto man bekommen möchte</param>
|
|
||||||
/// <param name="context">Ein eventuell vorhandener Datenbank-Context, falls man Änderungen in der Datenbank vornehmen will</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static UserBankAccount GetUserBankAccount(this User user, DatabaseContext context = null)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gibt den Character eines Users zurück
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="user">Der Client, dessen Character man bekommen möchte</param>
|
|
||||||
/// <param name="context">Ein eventuell vorhandener Datenbank-Context, falls man Änderungen in der Datenbank vornehmen will</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static Character GetUserCharacter(this User user, DatabaseContext context = null)
|
|
||||||
{
|
|
||||||
if (context == null)
|
|
||||||
{
|
|
||||||
using (context = new DatabaseContext())
|
|
||||||
{
|
|
||||||
return context.Characters.FirstOrDefault(u => u.UserId == user.Id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return context.Characters.FirstOrDefault(u => u.UserId == user.Id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -30,7 +30,7 @@ namespace reallife_gamemode.Server.Logs
|
|||||||
public int Fee { get; set; }
|
public int Fee { get; set; }
|
||||||
[StringLength(32)]
|
[StringLength(32)]
|
||||||
public string Origin { get; set; }
|
public string Origin { get; set; }
|
||||||
[Timestamp]
|
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
|
||||||
public byte[] Timestamp { get; set; }
|
public DateTime Timestamp { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using System.Text;
|
|||||||
using GTANetworkAPI;
|
using GTANetworkAPI;
|
||||||
using reallife_gamemode.Server.Entities;
|
using reallife_gamemode.Server.Entities;
|
||||||
using reallife_gamemode.Server.Extensions;
|
using reallife_gamemode.Server.Extensions;
|
||||||
|
using reallife_gamemode.Server.Util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @overview Life of German Reallife - Managers BankManager (BankManager.cs)
|
* @overview Life of German Reallife - Managers BankManager (BankManager.cs)
|
||||||
@@ -17,127 +18,42 @@ namespace reallife_gamemode.Server.Managers
|
|||||||
{
|
{
|
||||||
public class BankManager : Script
|
public class BankManager : Script
|
||||||
{
|
{
|
||||||
/// <summary>
|
public static TransactionResult TransferMoney(IBankAccountOwner sender, IBankAccountOwner receiver, int amount, string origin)
|
||||||
/// Transferiert Geld von einem User zu einem anderen User
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender">Der Sender des Geldes</param>
|
|
||||||
/// <param name="receiver">Der Empfänger des Geldes</param>
|
|
||||||
/// <param name="amount">Der Geldbetrag</param>
|
|
||||||
/// <param name="origin">Der Überweisungsgrund</param>
|
|
||||||
public static void TransferUserMoneyToUser(User sender, User receiver, int amount, string origin)
|
|
||||||
{
|
{
|
||||||
using (var transferMoney = new Model.DatabaseContext())
|
using (var transferMoney = new Model.DatabaseContext())
|
||||||
{
|
{
|
||||||
|
if (amount < 0) return TransactionResult.NEGATIVE_MONEY_SENT;
|
||||||
|
|
||||||
|
IBankAccount senderAccount = sender.GetBankAccount(transferMoney);
|
||||||
|
IBankAccount receiverAccount = receiver.GetBankAccount(transferMoney);
|
||||||
|
|
||||||
|
if (senderAccount == null) return TransactionResult.SENDER_NO_BANKACCOUNT;
|
||||||
|
if (receiverAccount == null) return TransactionResult.RECEIVER_NO_BANKACCOUNT;
|
||||||
|
|
||||||
|
if (senderAccount.Balance < amount) return TransactionResult.SENDER_NOT_ENOUGH_MONEY;
|
||||||
|
|
||||||
var transactionLog = new Logs.BankAccountTransactionHistory
|
var transactionLog = new Logs.BankAccountTransactionHistory
|
||||||
{
|
{
|
||||||
Sender = sender.Name,
|
Sender = sender.Name,
|
||||||
SenderBalance = sender.GetUserBankAccount().Balance,
|
SenderBalance = senderAccount.Balance,
|
||||||
MoneySent = amount,
|
|
||||||
Receiver = receiver.Name,
|
Receiver = receiver.Name,
|
||||||
ReceiverBalance = receiver.GetUserBankAccount().Balance,
|
ReceiverBalance = receiverAccount.Balance,
|
||||||
NewReceiverBalance = receiver.GetUserBankAccount().Balance + amount,
|
NewReceiverBalance = receiverAccount.Balance + amount,
|
||||||
NewSenderBalance = sender.GetUserBankAccount().Balance - amount,
|
NewSenderBalance = senderAccount.Balance - amount,
|
||||||
|
MoneySent = amount,
|
||||||
Fee = 0,
|
Fee = 0,
|
||||||
Origin = origin
|
Origin = origin
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// add log
|
||||||
transferMoney.BankAccountTransactionLogs.Add(transactionLog);
|
transferMoney.BankAccountTransactionLogs.Add(transactionLog);
|
||||||
sender.GetUserBankAccount(transferMoney).Balance -= amount;
|
|
||||||
receiver.GetUserBankAccount(transferMoney).Balance += amount;
|
senderAccount.Balance -= amount;
|
||||||
|
receiverAccount.Balance += amount;
|
||||||
|
|
||||||
transferMoney.SaveChanges();
|
transferMoney.SaveChanges();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
return TransactionResult.SUCCESS;
|
||||||
/// Transferiert Geld von einem User zu einer Fraktion
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender">Der Sender des Geldes</param>
|
|
||||||
/// <param name="receiver">Der Empfänger des Geldes</param>
|
|
||||||
/// <param name="amount">Der Geldbetrag</param>
|
|
||||||
/// <param name="origin">Der Überweisungsgrund</param>
|
|
||||||
public static void TransferUserMoneyToFaction(User sender, Faction receiver, int 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Transferiert Geld von einer Fraktion zu einem User
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender">Der Sender des Geldes</param>
|
|
||||||
/// <param name="receiver">Der Empfänger des Geldes</param>
|
|
||||||
/// <param name="amount">Der Geldbetrag</param>
|
|
||||||
/// <param name="origin">Der Überweisungsgrund</param>
|
|
||||||
public static void TransferFactionMoneyToUser(Faction sender, User receiver, int 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Transferiert Geld von einer Fraktion zu einer anderen Fraktion
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender">Der Sender des Geldes</param>
|
|
||||||
/// <param name="receiver">Der Empfänger des Geldes</param>
|
|
||||||
/// <param name="amount">Der Geldbetrag</param>
|
|
||||||
/// <param name="origin">Der Überweisungsgrund</param>
|
|
||||||
public static void TransferFactionMoneyToFaction(Faction sender, Faction receiver, int 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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
11
Server/Util/IBankAccount.cs
Normal file
11
Server/Util/IBankAccount.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace reallife_gamemode.Server.Util
|
||||||
|
{
|
||||||
|
public interface IBankAccount
|
||||||
|
{
|
||||||
|
int Balance { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
14
Server/Util/IBankAccountOwner.cs
Normal file
14
Server/Util/IBankAccountOwner.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using reallife_gamemode.Model;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace reallife_gamemode.Server.Util
|
||||||
|
{
|
||||||
|
public interface IBankAccountOwner
|
||||||
|
{
|
||||||
|
string Name { get; }
|
||||||
|
|
||||||
|
IBankAccount GetBankAccount(DatabaseContext databaseContext = null);
|
||||||
|
}
|
||||||
|
}
|
||||||
15
Server/Util/TransactionResult.cs
Normal file
15
Server/Util/TransactionResult.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace reallife_gamemode.Server.Util
|
||||||
|
{
|
||||||
|
public enum TransactionResult
|
||||||
|
{
|
||||||
|
SUCCESS,
|
||||||
|
SENDER_NO_BANKACCOUNT,
|
||||||
|
RECEIVER_NO_BANKACCOUNT,
|
||||||
|
SENDER_NOT_ENOUGH_MONEY,
|
||||||
|
NEGATIVE_MONEY_SENT
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user