mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 01:38:27 -04:00
Removed poll repository
This commit is contained in:
@@ -18,7 +18,6 @@ namespace NadekoBot.Core.Services.Database
|
||||
IDiscordUserRepository DiscordUsers { get; }
|
||||
IWarningsRepository Warnings { get; }
|
||||
IXpRepository Xp { get; }
|
||||
IPollsRepository Polls { get; }
|
||||
IPlantedCurrencyRepository PlantedCurrency { get; }
|
||||
|
||||
int SaveChanges();
|
||||
|
@@ -57,6 +57,7 @@ namespace NadekoBot.Core.Services.Database
|
||||
public DbSet<DiscordUser> DiscordUser { get; set; }
|
||||
public DbSet<MusicPlayerSettings> MusicPlayerSettings { get; set; }
|
||||
public DbSet<Repeater> Repeaters { get; set; }
|
||||
public DbSet<Poll> Poll { get; set; }
|
||||
|
||||
public NadekoContext(DbContextOptions<NadekoContext> options) : base(options)
|
||||
{
|
||||
|
@@ -1,11 +0,0 @@
|
||||
using NadekoBot.Core.Services.Database.Models;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NadekoBot.Core.Services.Database.Repositories
|
||||
{
|
||||
public interface IPollsRepository : IRepository<Poll>
|
||||
{
|
||||
IEnumerable<Poll> GetAllPolls();
|
||||
void RemovePoll(int id);
|
||||
}
|
||||
}
|
@@ -2,25 +2,23 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NadekoBot.Core.Services.Database;
|
||||
|
||||
namespace NadekoBot.Core.Services.Database.Repositories.Impl
|
||||
namespace NadekoBot.Modules.Games.Common
|
||||
{
|
||||
public class PollsRepository : Repository<Poll>, IPollsRepository
|
||||
public static class PollExtensions
|
||||
{
|
||||
public PollsRepository(DbContext context) : base(context)
|
||||
public static IEnumerable<Poll> GetAllPolls(this DbSet<Poll> polls)
|
||||
{
|
||||
}
|
||||
|
||||
public IEnumerable<Poll> GetAllPolls()
|
||||
{
|
||||
return _set.Include(x => x.Answers)
|
||||
return polls.Include(x => x.Answers)
|
||||
.Include(x => x.Votes)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
public void RemovePoll(int id)
|
||||
public static void RemovePoll(this NadekoContext ctx, int id)
|
||||
{
|
||||
var p = _set
|
||||
var p = ctx
|
||||
.Poll
|
||||
.Include(x => x.Answers)
|
||||
.Include(x => x.Votes)
|
||||
.FirstOrDefault(x => x.Id == id);
|
||||
@@ -30,17 +28,17 @@ namespace NadekoBot.Core.Services.Database.Repositories.Impl
|
||||
|
||||
if (p.Votes != null)
|
||||
{
|
||||
_context.Set<PollVote>().RemoveRange(p.Votes);
|
||||
ctx.RemoveRange(p.Votes);
|
||||
p.Votes.Clear();
|
||||
}
|
||||
|
||||
if (p.Answers != null)
|
||||
{
|
||||
_context.Set<PollAnswer>().RemoveRange(p.Answers);
|
||||
ctx.RemoveRange(p.Answers);
|
||||
p.Answers.Clear();
|
||||
}
|
||||
|
||||
_set.Remove(p);
|
||||
ctx.Poll.Remove(p);
|
||||
}
|
||||
}
|
||||
}
|
@@ -39,9 +39,6 @@ namespace NadekoBot.Core.Services.Database
|
||||
private IXpRepository _xp;
|
||||
public IXpRepository Xp => _xp ?? (_xp = new XpRepository(_context));
|
||||
|
||||
private IPollsRepository _polls;
|
||||
public IPollsRepository Polls => _polls ?? (_polls = new PollsRepository(_context));
|
||||
|
||||
private IPlantedCurrencyRepository _planted;
|
||||
public IPlantedCurrencyRepository PlantedCurrency => _planted ?? (_planted = new PlantedCurrencyRepository(_context));
|
||||
|
||||
|
Reference in New Issue
Block a user