From 705e996ec6cf4442d6136f6169ec6f0ff0352298 Mon Sep 17 00:00:00 2001 From: Sean Stoves Date: Wed, 3 Jun 2020 19:47:17 -0400 Subject: [PATCH] Adding Raffle Add and massInsert --- .../Database/Repository/RaffleRepository.cs | 13 +++++----- ChaosBot/Discord/Modules/RaffleSystem.cs | 26 +++++++++++-------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/ChaosBot/Database/Repository/RaffleRepository.cs b/ChaosBot/Database/Repository/RaffleRepository.cs index a3df9cd..00ee478 100644 --- a/ChaosBot/Database/Repository/RaffleRepository.cs +++ b/ChaosBot/Database/Repository/RaffleRepository.cs @@ -22,14 +22,15 @@ namespace ChaosBot.Database.Repository Controller.InsertQuery(Table, dict); } - public static void massInsert(Raffle raffle, int amount) + public static void massInsert(List raffles) { - Dictionary dict = new Dictionary(); - - dict.Add("userId", raffle.userId); - - for (int i = 0; i < amount; i++) + foreach (var raf in raffles) + { + Dictionary dict = new Dictionary(); + + dict.Add("userId", raf.userId); Controller.InsertQuery(Table, dict); + } } // public static void delete() diff --git a/ChaosBot/Discord/Modules/RaffleSystem.cs b/ChaosBot/Discord/Modules/RaffleSystem.cs index 1484ad1..b48db2e 100644 --- a/ChaosBot/Discord/Modules/RaffleSystem.cs +++ b/ChaosBot/Discord/Modules/RaffleSystem.cs @@ -3,14 +3,12 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using ChaosBot.Database; using ChaosBot.Database.Entity; -using ChaosBot.Database.Repository; using Discord; using Discord.Commands; -using Discord.WebSocket; using Microsoft.Extensions.Configuration; using NLog; +using ChaosBot.Database.Repository; namespace ChaosBot.Discord.Modules { @@ -129,23 +127,29 @@ namespace ChaosBot.Discord.Modules } } - private void AddRaffle(StringBuilder sb, string user, int amount) + private void AddRaffle(StringBuilder sb, string user, int amount = 1) { ulong userId = Convert.ToUInt64(user.Substring(3, user.Length-4)); - int currentAmount; - if (_currentPot.TryGetValue(userId, out currentAmount)) + + if (amount > 1) { - _currentPot.Remove(userId); - _currentPot.Add(userId, currentAmount + amount); + List raffles = new List(); + + for (int i = 0; i < amount; i++) + raffles.Add(new Raffle(userId.ToString())); + + RaffleRepository.massInsert(raffles); + } else { - _currentPot.Add(userId, amount); + RaffleRepository.insert(new Raffle(userId.ToString())); } - + + sb.AppendLine($"{Context.User.Mention} has added {amount} rafflepoints to <@{userId}>."); sb.AppendLine(); - sb.AppendLine($"<@{userId}> now has {_currentPot.GetValueOrDefault(userId)} rafflepoints!"); + sb.AppendLine($"<@{userId}> now has WIP rafflepoints!"); } private void PickRaffle(StringBuilder sb)