Ejemplo n.º 1
0
        static public async Task AddOrUpdateEntity <T>(this GypsyContext dbContext, T newEntity) where T : class, IDiscordServer
        {
            var entity = await dbContext.Set <T>().FindAsync(newEntity.ServerId);

            if (entity == null)
            {
                await dbContext.Set <T>().AddAsync(newEntity);
            }
            else
            {
                dbContext.Entry(entity).State = EntityState.Detached;
                dbContext.Set <T>().Update(newEntity);
            }
        }
Ejemplo n.º 2
0
        public Bot(DiscordSocketClient client, CommandService commands, IConfigurationRoot configuration, IServiceProvider services, IRepository repository,
                   JsonRepository <GypsyModel> gypsyRepository, GypsyContext dbContext, GypsyService gypsyService)
        {
            // It is recommended to Dispose of a client when you are finished
            // using it, at the end of your app's lifetime.
            _client                  = client;
            _commands                = commands;
            _services                = services;
            _repository              = repository;
            _dbContext               = dbContext;
            _gypsyService            = gypsyService;
            _client.Log             += LogAsync;
            _client.Ready           += ReadyAsync;
            _client.MessageReceived += HandleCommandAsync;

            _discordToken = configuration["discordToken"];
            _spawnRate    = configuration.GetValue <int>("SpawnRate");
            _prefix       = configuration.GetValue <string>("Prefix");

            _gypsyModels = gypsyRepository.GetAll().Result;
        }
Ejemplo n.º 3
0
 public DbRepository(GypsyContext gypsyContext)
 {
     _gypsyContext = gypsyContext;
 }
Ejemplo n.º 4
0
 public GypsyService(JsonRepository <GypsyModel> gypsyRepository, GypsyContext gypsyContext, DiscordSocketClient client) =>
 (_gypsyRepository, _dbContext, _client) = (gypsyRepository, gypsyContext, client);