mysimulation/server/FSO.Server.Database/DA/Inbox/SqlInbox.cs
Tony Bark 22191ce648 Removed NioTSO client and server
- NioTSO client isn't needed because we're using RayLib
- Added FreeSO's API server to handle most backend operations
2024-05-01 02:55:43 -04:00

47 lines
1.9 KiB
C#
Executable file

using Dapper;
using System;
using System.Collections.Generic;
using System.Linq;
namespace FSO.Server.Database.DA.Inbox
{
public class SqlInbox : AbstractSqlDA, IInbox
{
public SqlInbox(ISqlContext context) : base(context){
}
public int CreateMessage(DbInboxMsg msg)
{
var result = Context.Connection.Query<int>("INSERT INTO fso_inbox (sender_id, target_id, subject, " +
"body, sender_name, time, msg_type, msg_subtype, read_state) " +
" VALUES (@sender_id, @target_id, @subject, @body, @sender_name, " +
" @time, @msg_type, @msg_subtype, @read_state); SELECT LAST_INSERT_ID();", msg).First();
return result;
}
public bool DeleteMessage(int msgID)
{
return Context.Connection.Execute("DELETE FROM fso_inbox WHERE message_id = @id", new { id = msgID }) > 0;
}
public bool DeleteMessage(int msgID, uint avatarID)
{
return Context.Connection.Execute("DELETE FROM fso_inbox WHERE message_id = @id AND target_id = @aid", new { id = msgID, aid = avatarID }) > 0;
}
public DbInboxMsg Get(int msgID)
{
return Context.Connection.Query<DbInboxMsg>("SELECT * FROM fso_inbox WHERE message_id = @id", new { id = msgID }).FirstOrDefault();
}
public List<DbInboxMsg> GetMessages(uint avatarID)
{
return Context.Connection.Query<DbInboxMsg>("SELECT * FROM fso_inbox WHERE target_id = @id", new { id = avatarID }).ToList();
}
public List<DbInboxMsg> GetMessagesAfter(uint avatarID, DateTime after)
{
return Context.Connection.Query<DbInboxMsg>("SELECT * FROM fso_inbox WHERE target_id = @id AND time > @after", new { id = avatarID, after = after }).ToList();
}
}
}