public MySqlCommand GetInsertQuery(GuildMap database) { var command = new MySqlCommand($"INSERT INTO guilds(Id, Name, Lang, IconUrl, PermittedRolesCSV, TicketsBin, SetupMessagesBin) VALUES({database.Id},'{database.Name}',{(int)database.Lang},'{database.IconUrl}','{database.PermittedRolesCSV}',@tbin,@smbin);", Connection); command.Parameters.Add("@tbin", MySqlDbType.LongBlob).Value = database.TicketsBin; command.Parameters.Add("@smbin", MySqlDbType.LongBlob).Value = database.SetupMessagesBin; return(command); }
public MySqlCommand GetUpdateQuery(GuildMap database) { var command = new MySqlCommand($"UPDATE guilds SET Name = '{database.Name}', Lang = '{(int)database.Lang}', IconUrl = '{database.IconUrl}', PermittedRolesCSV = '{database.PermittedRolesCSV}', TicketsBin = @tbin, SetupMessagesBin = @smbin where Id = {database.Id};", Connection); command.Parameters.Add("@tbin", MySqlDbType.LongBlob).Value = database.TicketsBin; command.Parameters.Add("@smbin", MySqlDbType.LongBlob).Value = database.SetupMessagesBin; return(command); }
public static GuildMap MapGuild(GuildEngine guild) { var map = new GuildMap() { Id = guild.Id, Name = guild.Name, Lang = guild.Lang, IconUrl = guild.IconUrl, TicketsBin = FormatterExtensions.ToBinary(guild.Tickets.Values.ToList()), SetupMessagesBin = FormatterExtensions.ToBinary(guild.SetupMessages.Values.ToList()), RolesMessagesBin = FormatterExtensions.ToBinary(guild.RolesMessagesData.Values.ToList()), PermittedRolesCSV = guild.PermittedRoles.ToCSV(";") }; return(map); }
public static GuildEngine UnMapGuild(GuildMap database) { var tickets = FormatterExtensions.ToObject <List <Ticket> >(database.TicketsBin); var smessages = FormatterExtensions.ToObject <List <SetupMessage> >(database.SetupMessagesBin); var sroles = FormatterExtensions.ToObject <List <RolesMessageData> >(database.RolesMessagesBin); GuildEngine info = new GuildEngine(database.Id, database.Name) { Lang = database.Lang, IconUrl = database.IconUrl, Tickets = tickets.ToDictionary(x => x.Id), SetupMessages = smessages.ToDictionary(x => x.MessageId), RolesMessagesData = sroles.ToDictionary(x => x.MessageId), PermittedRoles = FormatterExtensions.FromCSV <ulong>(database.PermittedRolesCSV, ";").ToList() }; return(info); }
public void Insert(GuildMap database) { var query = GetInsertQuery(database); query.ExecuteNonQuery(); }
public void Save(GuildMap database) { var query = GetUpdateQuery(database); query.ExecuteNonQuery(); }