Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        public void Insert(GuildMap database)
        {
            var query = GetInsertQuery(database);

            query.ExecuteNonQuery();
        }
Exemple #6
0
        public void Save(GuildMap database)
        {
            var query = GetUpdateQuery(database);

            query.ExecuteNonQuery();
        }