public void Test() { using (var context = new mashDbContext()) { // Add user. context.Users.Add(new Users { Name = "pmash2", EntryDate = DateTime.Now }); context.Users.Add(new Users { Name = "hunter2140", EntryDate = DateTime.Now }); context.SaveChanges(); // Fetch Reminders var users = context.Users.ToArray(); foreach (var user in users) { Console.WriteLine($"We found user {user.Name}!"); } } }
public UserPoints GetPointsRecord(string user) { UserPoints pointsRecord; using (var context = new mashDbContext()) { pointsRecord = context.UserPoints .Where(x => x.Viewer == user.ToLower()) .FirstOrDefault(); if (pointsRecord == null) { UserPoints newRecord = new() { Viewer = user.ToLower(), Points = 0 }; context.UserPoints.Add(newRecord); pointsRecord = newRecord; context.SaveChanges(); } } return(pointsRecord); }
public void AddUser(string username) { var user = new Users { Name = username, EntryDate = DateTime.Now }; using (var context = new mashDbContext()) { context.Users.Add(user); context.SaveChanges(); } }
public static void DeleteCommand(StaticCommands cmd) { if (string.IsNullOrEmpty(cmd.Keyword)) { throw new System.ArgumentException(); } cmd.Keyword = CheckForBang(cmd.Keyword); using (var context = new mashDbContext()) { context.Remove(GetCommand(cmd.Keyword)); context.SaveChanges(); } }
public static void UpdateCommand(StaticCommands cmd) { if (string.IsNullOrEmpty(cmd.Keyword) || string.IsNullOrEmpty(cmd.Text)) { throw new System.ArgumentException(); } cmd.Keyword = CheckForBang(cmd.Keyword); using (var context = new mashDbContext()) { var existing = GetCommand(cmd.Keyword); existing.Text = cmd.Text; context.Update(existing); context.SaveChanges(); } }
public static string PlayGame(bool betEven, string userName, int wager, UserPointsRepo mgr) { var rand = new Random(); var number = rand.Next(0, 1000); var didWin = false; Console.WriteLine($"The random number for this round is {number}"); var isEven = number % 2 == 0 ? true : false; string result = $"The number was {number}. "; if (betEven && isEven || !betEven && !isEven) { result += "YOU WIN!!!!"; didWin = true; mgr.ChangePoints(userName, "", wager, "Won OddOrEven"); } else { result += "Oh no, you lose! :("; didWin = false; mgr.ChangePoints(userName, "", wager * -1, "Lost OddOrEven"); } using (var context = new mashDbContext()) { context.WinLoss.Add(new WinLoss { UserName = userName, DidWin = didWin, Date = DateTime.Now, Game = "OddOrEven" }); context.SaveChanges(); } return(result); }
public string Execute(string username, string[] args, BotSettings settings) { // !addconfig PTS multiplier 2 if (args.Length < 4) { return($"@{username}, try !addcommand PTS multiplier 2"); } string key = args[1]; string description = args[2]; string value = args[3]; GlobalConfigsManager cfgMgr = new(); if (cfgMgr.GetConfig(key) != null) { return($"@{username}, that configuration already exists : {key}"); } using (var context = new mashDbContext()) { GlobalConfigs cfg = new() { Key = key, Description = description, Value = value, DateUpdated = DateTime.Now }; context.GlobalConfigs.Add(cfg); context.SaveChanges(); } return($"@{username}, configuration saved"); } }
public string Execute(string username, string[] args, BotSettings settings) { string result; if (username == "pmash2") { var message = new TodaysMessage { Message = String.Join(' ', args, 1, args.Length - 1), Date = DateTime.Now }; using (var context = new mashDbContext()) { context.TodaysMessage.Add(message); context.SaveChanges(); } try { PostMessage(settings.Endpoint, message.Message); } catch (Exception ex) { Console.WriteLine($"Error posting today's message: {ex.Message}"); } result = "Today's message has been updated"; } else { result = "Sorry, you're not allowed to do that"; } return(result); }