forked from adam/discord-bot-shtik
Some checks failed
gitea.arg.rip/vassago/pipeline/head There was a failure building this commit
FUCK this is what I get for saying I like entity framework. *adds thing* *hits save* "(unrelated shit) is already here, why are you trying to add it again you dumbass?" FUCK IF I KNOW, you're supposed to be straightening this shit out!
79 lines
2.4 KiB
C#
79 lines
2.4 KiB
C#
namespace vassago;
|
|
|
|
using System.Linq.Expressions;
|
|
using vassago.Models;
|
|
|
|
public static class Rememberer
|
|
{
|
|
public static Account SearchAccount(Expression<Func<Account, bool>> predicate)
|
|
{
|
|
return (new ChattingContext()).Accounts.FirstOrDefault(predicate);
|
|
}
|
|
public static List<Account> SearchAccounts(Expression<Func<Account, bool>> predicate)
|
|
{
|
|
return (new ChattingContext()).Accounts.Where(predicate).ToList();
|
|
}
|
|
public static Attachment SearchAttachment(Expression<Func<Attachment, bool>> predicate)
|
|
{
|
|
return (new ChattingContext()).Attachments.FirstOrDefault(predicate);
|
|
}
|
|
public static Channel SearchChannel(Expression<Func<Channel, bool>> predicate)
|
|
{
|
|
return (new ChattingContext()).Channels.FirstOrDefault(predicate);
|
|
}
|
|
public static Message SearchMessage(Expression<Func<Message, bool>> predicate)
|
|
{
|
|
return (new ChattingContext()).Messages.FirstOrDefault(predicate);
|
|
}
|
|
public static User SearchUser(Expression<Func<User, bool>> predicate)
|
|
{
|
|
return (new ChattingContext()).Users.FirstOrDefault(predicate);
|
|
}
|
|
public static void RememberAccount(Account toRemember)
|
|
{
|
|
var db = new ChattingContext();
|
|
if (toRemember.Id == Guid.Empty)
|
|
db.Accounts.Add(toRemember);
|
|
|
|
db.SaveChanges();
|
|
}
|
|
public static void RememberAttachment(Attachment toRemember)
|
|
{
|
|
var db = new ChattingContext();
|
|
if (toRemember.Id == Guid.Empty)
|
|
db.Attachments.Add(toRemember);
|
|
|
|
db.SaveChanges();
|
|
}
|
|
public static void RememberChannel(Channel toRemember)
|
|
{
|
|
var db = new ChattingContext();
|
|
if (toRemember.Id == Guid.Empty)
|
|
db.Channels.Add(toRemember);
|
|
|
|
db.SaveChanges();
|
|
}
|
|
public static void RememberMessage(Message toRemember)
|
|
{
|
|
var db = new ChattingContext();
|
|
if (toRemember.Id == Guid.Empty)
|
|
{
|
|
db.Messages.Add(toRemember);
|
|
}
|
|
db.SaveChanges();
|
|
}
|
|
public static void RememberUser(User toRemember)
|
|
{
|
|
var db = new ChattingContext();
|
|
if (toRemember.Id == Guid.Empty)
|
|
db.Users.Add(toRemember);
|
|
|
|
db.SaveChanges();
|
|
}
|
|
public static void ForgetUser(User toForget)
|
|
{
|
|
var db = new ChattingContext();
|
|
db.Users.Remove(toForget);
|
|
db.SaveChanges();
|
|
}
|
|
} |