From 632781d1adf54287ecfe7cbcbc17074e14a769b2 Mon Sep 17 00:00:00 2001 From: TrueDoctor Date: Sat, 29 Sep 2018 23:59:42 +0200 Subject: added database methods --- DSACore/Hubs/ChatHub.cs | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'DSACore/Hubs/ChatHub.cs') diff --git a/DSACore/Hubs/ChatHub.cs b/DSACore/Hubs/ChatHub.cs index 6335183..e489b2e 100644 --- a/DSACore/Hubs/ChatHub.cs +++ b/DSACore/Hubs/ChatHub.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using DSACore.FireBase; using DSACore.Models; using DSACore.Models.Network; using Microsoft.AspNetCore.SignalR; @@ -12,7 +13,17 @@ namespace DSACore.Hubs { //private static Dictionary UserGroup = new Dictionary(); - private static List DSAGroups = new List(); + private static List DSAGroups = new List(); + + static ChatHub() + { + DSAGroups = Database.GetGroups().Result; + DSAGroups.Add(new Group("TheCrew", "valid")); + DSAGroups.Add(new Group("HalloWelt", "valid")); + DSAGroups.Add(new Group("DieKrassenGamer", "valid")); + DSAGroups.Add(new Group("DSA", "valid")); + DSAGroups.Add(new Group("DieÜberhelden", "valid")); + } public async Task SendMessage(string user, string message) { @@ -20,15 +31,14 @@ namespace DSACore.Hubs var ident = args.First().Replace("!", ""); if(args.Count>0){args.RemoveAt(0);} - string group; try { - group = getGroup(Context.ConnectionId).Name; + string group = getGroup(Context.ConnectionId).Name; await SendToGroup(group, user, Commands.CommandHandler.ExecuteCommand(new Command { CharId = 0, CmdIdentifier = ident, CmdTexts = args, Name = user })); } catch(InvalidOperationException e) { - await Clients.Caller.SendCoreAsync("ReceiveMessage", new[] {"Nutzer ist in keiner Gruppe. Erst joinen!"}); + await Clients.Caller.SendCoreAsync("ReceiveMessage", new object[] {"Nutzer ist in keiner Gruppe. Erst joinen!"}); } } @@ -38,7 +48,7 @@ namespace DSACore.Hubs return Clients.Group(group).SendCoreAsync("ReceiveMessage", new object[] { user, message }); } - private Group getGroup(string id) + private Models.Network.Group getGroup(string id) { return DSAGroups.First(x => x.Users.Exists(y => y.ConnectionId.Equals(id))); } @@ -51,8 +61,10 @@ namespace DSACore.Hubs public async Task AddGroup(string group, string password) { - DSAGroups.Add(new Group{Name = group, Password = password}); - Clients.Caller.SendCoreAsync("ReceiveMessage", new[] {$"group {group} sucessfully added"}); + DSAGroups.Add(new Group(group, password)); + var Dgroup = new DSACore.Models.Database.Group{Name = group, Id = DSAGroups.Count-1}; + Database.CreateGroup(Dgroup); + await Clients.Caller.SendCoreAsync("ReceiveMessage", new[] {$"group {@group} sucessfully added"}); //throw new NotImplementedException("add database call to add groups"); } -- cgit v1.2.3-54-g00ecf