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); } }
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; }
public DbRepository(GypsyContext gypsyContext) { _gypsyContext = gypsyContext; }
public GypsyService(JsonRepository <GypsyModel> gypsyRepository, GypsyContext gypsyContext, DiscordSocketClient client) => (_gypsyRepository, _dbContext, _client) = (gypsyRepository, gypsyContext, client);