public async Task Atualizar(Servidores s) { using Kurosawa_DiaContext context = new Kurosawa_DiaContext(); Servidores servidores = await context.Servidores.SingleOrDefaultAsync(x => x.ID == s.ID); if (s.Prefix != "") { servidores.Prefix = s.Prefix; } if (s.Especial != TiposServidores.Inalterado) { servidores.Especial = s.Especial; } await context.SaveChangesAsync(); //IDbContextTransaction transation = await context.Database.BeginTransactionAsync(IsolationLevel.Snapshot); //await context.Database.ExecuteSqlRawAsync("call AtualizarServidor({0}, {1}, {2})", servidor.ID, servidor.Prefix ?? "", servidor.Especial); //await context.Servidores.FromSqlRaw("call AtualizarServidor({0}, {1}, {2})", servidor.ID, servidor.Prefix ?? "", servidor.Especial).LoadAsync(); //_ = context.Set<Void>().FromSqlRaw("call AtualizarServidor({0}, {1}, {2})", servidor.ID, servidor.Prefix ?? "", servidor.Especial).LoadAsync(); //await context.SaveChangesAsync(); //await transation.CommitAsync(); //MySqlCommand command = await context.GetMysqlCommand(); //command.CommandText = "call AtualizarServidor(@si, @sp, @se)"; //command.Parameters.AddWithValue("@si", servidor.ID); //command.Parameters.AddWithValue("@sp", servidor.Prefix ?? ""); //command.Parameters.AddWithValue("@se", servidor.Especial); //await command.ExecuteNonQueryAsync(); }
public async Task <F**k> Get(F**k f) { using Kurosawa_DiaContext context = new Kurosawa_DiaContext(); if (f.Explicit) { F**k[] f***s = await context.F**k.ToArrayAsync(); if (f***s.Count() == 0) { return(null); } Random random = new Random(); return(f***s[random.Next(f***s.Length)]); } else { F**k[] f***s = await context.F**k.Where(x => !x.Explicit).ToArrayAsync(); if (f***s.Count() == 0) { return(null); } Random random = new Random(); return(f***s[random.Next(f***s.Length)]); } //return (await context.F**k.FromSqlRaw("call GetFuck({0})", f**k.Explicit).ToListAsync()).FirstOrDefault(); }
internal static async Task <MySqlCommand> GetMysqlCommand(this Kurosawa_DiaContext contexto) { MySqlCommand cmd = (MySqlCommand)contexto.Database.GetDbConnection().CreateCommand(); await cmd.Connection.OpenAsync(); return(cmd); }
public async Task <Servidores> Get(Servidores servidor) { using Kurosawa_DiaContext context = new Kurosawa_DiaContext(); return(await context.Servidores.SingleOrDefaultAsync(x => x.ID == servidor.ID)); //return (await context.Servidores.FromSqlRaw("call GetServidor({0})", servidor.ID).ToListAsync()).FirstOrDefault(); }
public async Task <Canais> Get(Canais canal) { using Kurosawa_DiaContext context = new Kurosawa_DiaContext(); return(await context.Canais.SingleOrDefaultAsync(x => x.Servidor.ID == canal.Servidor.ID && x.TipoCanal == canal.TipoCanal)); //using (Kurosawa_DiaContext context = new Kurosawa_DiaContext()) //{ // return (await context.Canais.FromSqlRaw("call GetCanal({0}, {1})", canal.Servidor.ID, canal.TipoCanal).ToListAsync()).FirstOrDefault(); //} }
public async Task <AdmsBot> Get(AdmsBot adms) { using Kurosawa_DiaContext context = new Kurosawa_DiaContext(); return(await context.AdmsBots.AsNoTracking().SingleOrDefaultAsync(x => x.Usuario.ID == adms.Usuario.ID)); //using (Kurosawa_DiaContext context = new Kurosawa_DiaContext()) //{ // return (await context.AdmsBots.FromSqlRaw("call LerAdms({0})", adms.Usuario.ID).ToListAsync()).FirstOrDefault(); //} }
public async Task <Servidores> Add(Servidores_Usuarios su) { Kurosawa_DiaContext context = new Kurosawa_DiaContext(); Servidores servidor = await context.Servidores.AsNoTracking().SingleOrDefaultAsync(x => x.ID == su.Servidor.ID); if (servidor == null) { await context.Servidores.AddAsync(servidor = new Servidores { ID = su.Servidor.ID, Nome = su.Servidor.Nome }); await context.SaveChangesAsync(); } Usuarios usuario = await context.Usuarios.AsNoTracking().SingleOrDefaultAsync(x => x.ID == su.Usuario.ID); if (usuario == null) { await context.Usuarios.AddAsync(usuario = new Usuarios { ID = su.Usuario.ID, Nome = su.Usuario.Nome }); await context.SaveChangesAsync(); } Servidores_Usuarios servidor_usuario = await context.Servidores_Usuarios.AsNoTracking().SingleOrDefaultAsync(x => x.Servidor.ID == su.Servidor.ID && x.Usuario.ID == su.Usuario.ID); if (servidor_usuario == null) { await context.Servidores_Usuarios.AddAsync(servidor_usuario = new Servidores_Usuarios { Servidor = servidor, Usuario = usuario }); } return(servidor); //using (Kurosawa_DiaContext context = new Kurosawa_DiaContext()) //{ // return (await context.Servidores.FromSqlRaw("call CadastrarUsuarioServidor({0}, {1}, {2}, {3})", su.Servidor.ID, su.Usuario.ID, su.Servidor.Nome, su.Usuario.Nome).ToListAsync()).FirstOrDefault(); //} }
public async Task <CustomReactions[]> GetPage(CustomReactions cr, uint page) { using Kurosawa_DiaContext context = new Kurosawa_DiaContext(); page = (page - 1) * 10; if (cr.Trigger != "") { return(await context.CustomReactions.Where(x => x.Servidor.ID == cr.Servidor.ID && x.Trigger == cr.Trigger).Skip((int)page).Take(10).ToArrayAsync()); } else { return(await context.CustomReactions.Where(x => x.Servidor.ID == cr.Servidor.ID).Skip((int)page).Take(10).ToArrayAsync()); } //return (await context.CustomReactions.FromSqlRaw("call Lcr({0}, {1}, {2})", cr.Servidor.ID, cr.Trigger, page).ToListAsync()).ToArray(); }
public async Task Adicionar(Canais c) { using Kurosawa_DiaContext context = new Kurosawa_DiaContext(); Canais canal = await context.Canais.SingleOrDefaultAsync(x => x.Servidor.ID == c.Servidor.ID && x.TipoCanal == c.TipoCanal); if (canal == null) { await context.Canais.AddAsync(new Canais { CodServidor = (await context.Servidores.AsNoTracking().FirstOrDefaultAsync(x => x.ID == c.Servidor.ID)).Cod, ID = c.ID, Nome = c.Nome, TipoCanal = c.TipoCanal }); await context.SaveChangesAsync(); } else { context.Canais.Remove(canal); await context.SaveChangesAsync(); } //using (Kurosawa_DiaContext context = new Kurosawa_DiaContext()) //{ // //IDbContextTransaction transation = await context.Database.BeginTransactionAsync(IsolationLevel.Snapshot); // //await context.Database.ExecuteSqlRawAsync("call AddCanal({0}, {1}, {2}, {3})", canal.TipoCanal, canal.Nome, canal.ID, canal.Servidor.ID); // //_ = context.Canais.FromSqlRaw("call AddCanal({0}, {1}, {2}, {3})", canal.TipoCanal, canal.Nome, canal.ID, canal.Servidor.ID); // //await transation.CommitAsync(); // MySqlCommand command = await context.GetMysqlCommand(); // command.CommandText = "call AddCanal(@ct, @cn, @ci, @csi)"; // command.Parameters.AddWithValue("@ct", canal.TipoCanal); // command.Parameters.AddWithValue("@cn", canal.Nome); // command.Parameters.AddWithValue("@ci", canal.ID); // command.Parameters.AddWithValue("@csi", canal.Servidor.ID); // await command.ExecuteNonQueryAsync(); //} }
public async Task <int> Delete(CustomReactions cr) { using Kurosawa_DiaContext context = new Kurosawa_DiaContext(); CustomReactions customReactions = await context.CustomReactions.SingleOrDefaultAsync(x => x.Cod == cr.Cod && x.Servidor.ID == cr.Servidor.ID); context.CustomReactions.Remove(customReactions); return(await context.SaveChangesAsync()); //int res = 0; ////IDbContextTransaction transation = await context.Database.BeginTransactionAsync(IsolationLevel.ReadUncommitted); ////res = await context.Database.ExecuteSqlRawAsync("call DeleteCR({0}, {1})", cr.Servidor.ID, cr.Cod); ////await transation.CommitAsync(); //MySqlCommand command = await context.GetMysqlCommand(); //command.CommandText = "call DeleteCR(@si, @c)"; //command.Parameters.AddWithValue("@si", cr.Servidor.ID); //command.Parameters.AddWithValue("@c", cr.Cod); //res = await command.ExecuteNonQueryAsync(); //return res; }
public async Task Adicionar(CustomReactions cr) { using Kurosawa_DiaContext context = new Kurosawa_DiaContext(); cr.Servidor = await context.Servidores.SingleOrDefaultAsync(x => x.ID == cr.Servidor.ID); await context.CustomReactions.AddAsync(cr); await context.SaveChangesAsync(); //IDbContextTransaction transation = await context.Database.BeginTransactionAsync(IsolationLevel.Snapshot); //await context.Database.ExecuteSqlRawAsync("call AddCR({0}, {1}, {2}, {3})", cr.Trigger, cr.Resposta, cr.Modo, cr.Servidor.ID); //_ = context.CustomReactions.FromSqlRaw("call AddCR({0}, {1}, {2}, {3})", cr.Trigger, cr.Resposta, cr.Modo, cr.Servidor.ID); //await transation.CommitAsync(); //MySqlCommand command = await context.GetMysqlCommand(); //command.CommandText = "call AddCR(@t, @r, @m, @si)"; //command.Parameters.AddWithValue("@t", cr.Trigger); //command.Parameters.AddWithValue("@r", cr.Resposta); //command.Parameters.AddWithValue("@m", cr.Modo); //command.Parameters.AddWithValue("@si", cr.Servidor.ID); //await command.ExecuteNonQueryAsync(); }
public async Task <CustomReactions> Get(CustomReactions cr) { using Kurosawa_DiaContext context = new Kurosawa_DiaContext(); List <CustomReactions> crs = await context.CustomReactions.Where(x => x.Servidor.ID == cr.Servidor.ID && EF.Functions.Like(cr.Trigger.ToLower(), "%" + x.Trigger.ToLower() + "%")).ToListAsync(); if (crs.Count == 0) { return(null); } Random random = new Random(); do { int crIndex = random.Next(crs.Count); CustomReactions customReactions = crs[crIndex]; crs.RemoveAt(crIndex); if (!customReactions.Modo) { if (customReactions.Trigger.ToLower() == cr.Trigger.ToLower()) { return(customReactions); } } else { return(customReactions); } } while (crs.Count != 0); return(null); //return (await context.CustomReactions.FromSqlRaw("call CREvent({0}, {1})", cr.Servidor.ID, cr.Trigger).ToListAsync()).FirstOrDefault(); }
public async Task Iniciar() { CommandsNextConfiguration configNext = new CommandsNextConfiguration { EnableDefaultHelp = false, EnableMentionPrefix = true, CustomPrefixPredicate = new PrefixConfig(Config.Prefixo).PegarPrefixo, }; CommandsNextModule comandos = Cliente.UseCommandsNext(configNext); comandos.SetHelpFormatter <HelpConfig>(); comandos.RegisterCommands(typeof(Kurosawa).Assembly); foreach (KeyValuePair <string, Command> comando in comandos.RegisteredCommands) { Cliente.DebugLogger.LogMessage(LogLevel.Debug, "Kurosawa Dia - Handler", $"Comando Registrado: {comando.Key}", DateTime.Now); } new CommandErrored(ref comandos); Cliente.UseInteractivity(new InteractivityConfiguration { Timeout = TimeSpan.FromMinutes(5) }); Cliente.MessageCreated -= comandos.HandleCommandsAsync; using (Kurosawa_DiaContext ctx = new Kurosawa_DiaContext()) { if (Debugger.IsAttached) { ctx.Database.Migrate(); } else { await ctx.Database.MigrateAsync(); } } await Cliente.ConnectAsync(); await Task.Delay(-1); }
public async Task Add(F**k f) { using Kurosawa_DiaContext context = new Kurosawa_DiaContext(); Usuarios usuarios = await context.Usuarios.SingleOrDefaultAsync(x => x.ID == f.Usuario.ID); f.Usuario = usuarios; await context.F**k.AddAsync(f); await context.SaveChangesAsync(); //IDbContextTransaction transation = await context.Database.BeginTransactionAsync(IsolationLevel.Snapshot); //await context.Database.ExecuteSqlRawAsync("call AddFuck({0}, {1}, {2})", f**k.Usuario.ID, f**k.Url, f**k.Explicit); //_ = context.F**k.FromSqlRaw("call AddFuck({0}, {1}, {2})", f**k.Usuario.ID, f**k.Url, f**k.Explicit); //await transation.CommitAsync(); //MySqlCommand command = await context.GetMysqlCommand(); //command.CommandText = "call AddFuck(@ui, @u, @e)"; //command.Parameters.AddWithValue("@ui", f**k.Usuario.ID); //command.Parameters.AddWithValue("@u", f**k.Url); //command.Parameters.AddWithValue("@e", f**k.Explicit); //await command.ExecuteNonQueryAsync(); }
public async Task Atualizar(AdmsBot adms) { using Kurosawa_DiaContext context = new Kurosawa_DiaContext(); AdmsBot admsBot = await context.AdmsBots.SingleOrDefaultAsync(x => x.Usuario.ID == adms.Usuario.ID); if (admsBot != null) { admsBot.Permissao = adms.Permissao; await context.SaveChangesAsync(); } else { await context.AdmsBots.AddAsync(new AdmsBot { CodUsuario = (await context.Usuarios.AsNoTracking().SingleOrDefaultAsync(x => x.ID == adms.Usuario.ID)).Cod, Permissao = adms.Permissao }); await context.SaveChangesAsync(); } //using (Kurosawa_DiaContext context = new Kurosawa_DiaContext()) //{ // //IDbContextTransaction transation = await context.Database.BeginTransactionAsync(IsolationLevel.Snapshot); // //await context.Database.ExecuteSqlRawAsync("call AtualizarAdm({0}, {1})", adms.Usuario.ID, adms.Permissao); // //_ = context.AdmsBots.FromSqlRaw("call AtualizarAdm({0}, {1})", adms.Usuario.ID, adms.Permissao); // //await transation.CommitAsync(); // MySqlCommand command = await context.GetMysqlCommand(); // command.CommandText = "call AtualizarAdm(@ui, @up)"; // command.Parameters.AddWithValue("@ui", adms.Usuario.ID); // command.Parameters.AddWithValue("@up", adms.Permissao); // await command.ExecuteNonQueryAsync(); //} }