public static Error AddPlayer(String uid, String name, PersonDb db, String steamID = "", int points = 0) { CasinoPlayer tempPlayer = new CasinoPlayer { Id = uid, Name = name, Points = points, SteamID64 = steamID }; if (IsRegistered(tempPlayer, db).GetAwaiter().GetResult()) { return(Error.DUPLICATE); } if (db.Players.Where(p => p.Name.ToLower() == tempPlayer.Name.ToLower()) == null) { return(Error.INVALIDNAME); } db.Players.Add(tempPlayer); int savedCount = db.SaveChanges(); if (savedCount < 1) { return(Error.SAVEERROR); } //Console.WriteLine("{0} records saved to database", savedCount); return(Error.OK); }
public static Error ChangePlayer(String uid, PersonDb db, String name = "", String steamID = "") { CasinoPlayer player = GetPlayer(uid, db); if (player == null) { return(Error.NOTFOUND); } if (name != "") { player.Name = name; } if (steamID != "") { player.SteamID64 = steamID; } if (db.SaveChanges() < 1) { return(Error.SAVEERROR); } return(Error.OK); }
public static bool GiveItem(CasinoPlayer player, String itemID) { StringBuilder inv = new StringBuilder(player.Inventory); inv.Append(inv.Length > 0 ? $";{itemID}" : $"{itemID}"); player.Inventory = inv.ToString(); return(true); }
public static bool SetPoints(CasinoPlayer player, int amount, PersonDb db) { if (amount < 0) { return(false); } //db.Players.Find(player.Id).Points = amount; player.Points = amount; return(true); }
public static bool AlterPoints(CasinoPlayer player, int amount) { if (player.Points + amount < 0) { return(false); } player.Points += amount; return(true); }
public static Error DeletePlayer(String uid, PersonDb db) { CasinoPlayer player = GetPlayer(uid, db); if (player == null) { return(Error.NOTFOUND); } db.Players.Remove(player); int savedCount = db.SaveChanges(); if (savedCount < 1) { return(Error.SAVEERROR); } return(Error.OK); }
public static async Task <bool> IsRegistered(CasinoPlayer myPlayer, PersonDb db) { return((await db.Players.FindAsync(myPlayer.Id)) != null); }