77 lines
2.3 KiB
C#
77 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using ChaosBot.Database.Entity;
|
|
|
|
namespace ChaosBot.Database.Repository
|
|
{
|
|
public static class PointsRepository
|
|
{
|
|
private static readonly string Table = "PointsTable";
|
|
|
|
public static Points[] All()
|
|
{
|
|
List<Points> pointsList = Points.Query().All();
|
|
|
|
return pointsList.ToArray();
|
|
}
|
|
|
|
public static Points[] All(long guildId)
|
|
{
|
|
List<Points> pointsList = Points.Query().Where("guildId", guildId).All();
|
|
|
|
return pointsList.ToArray();
|
|
}
|
|
|
|
|
|
public static int Total(long userId, long guildId)
|
|
{
|
|
Points userPoints = Points.Query().Where("userId", userId).Where("guildId", guildId).First();
|
|
|
|
if (userPoints != null)
|
|
return userPoints.points;
|
|
|
|
Points emptyUserPoints = new Points(userId, guildId, 0);
|
|
Points.Query().Insert(emptyUserPoints);
|
|
return 0;
|
|
}
|
|
|
|
|
|
public static int Count(long userId, long guildId)
|
|
{
|
|
return Points.Query().Where("userId", userId).Where("guildId", guildId).Count();
|
|
}
|
|
|
|
|
|
public static int Add(long userId, int points, long guildId)
|
|
{
|
|
Points userPoints = Points.Query().Where("userId", userId).Where("guildId", guildId).First();
|
|
if (userPoints != null)
|
|
{
|
|
Points.Query().Where("userId", userId).Where("guildId", guildId).Set("points", userPoints.points + points).Update();
|
|
return userPoints.points + points;
|
|
|
|
}
|
|
|
|
Points newUserPoints = new Points(userId, guildId, points);
|
|
|
|
Points.Query().Insert(newUserPoints);
|
|
return points;
|
|
}
|
|
|
|
public static int Remove(long userId, int points, long guildId)
|
|
{
|
|
Points userPoints = Points.Query().Where("userId", userId).Where("guildId", guildId).First();
|
|
|
|
Points.Query().Where("userId", userId).Where("guildId", guildId).Set("points", userPoints.points - points).Update();
|
|
|
|
return userPoints.points - points;
|
|
}
|
|
|
|
public static void Delete(int userId)
|
|
{
|
|
Points.Query().Where("userId", userId).Delete();
|
|
}
|
|
}
|
|
}
|