using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace HyperCube.Models { public enum NotificationType {System = 0, User } public class Notification { public int ID { get; set; } public NotificationType NotifiType { get; set; } public string Header { get; set; } public string Body { get; set; } public string RecipientID { get; private set; } public string SendertID { get; private set; } public bool IsRead { get; set; } public DateTime? DateRead { get; set; } public bool IsApproved { get; set; } public DateTime? DateApprove { get; set; } public bool IsRejected { get; set; } public DateTime? DateReject { get; set; } public Notification(NotificationType type, string header, string body, string recipientid, string senderid) { NotifiType = type; Header = header; Body = body; RecipientID = recipientid; SendertID = senderid; IsRead = false; IsApproved = false; IsRejected = false; } public async Task Send() { string sql = $"INSERT INTO notifications (type, header, body, recipientid, senderid) " + $"VALUES ('{(int)NotifiType}','{Header}','{Body}','{RecipientID}','{SendertID}')"; long id = await MySQLConnector.Instance().SQLInsert(sql); ID = (int)id; return ID; } public async Task Update() { int isread = Convert.ToInt32(IsRead); int isapproved = Convert.ToInt32(IsApproved); int isrejected = Convert.ToInt32(IsRejected); string dateread = DateRead?.ToString("yyyy-MM-dd HH:mm:ss"); string dateapprove = DateApprove?.ToString("yyyy-MM-dd HH:mm:ss"); string datereject = DateReject?.ToString("yyyy-MM-dd HH:mm:ss"); string sql = $"UPDATE notifications" + $" SET isread='{isread}', dateread='{dateread}', isapproved='{isapproved}', dateapprove='{dateapprove}', isrejected='{isrejected}', datereject='{datereject}' " + $" WHERE id ='{ID}'"; await MySQLConnector.Instance().SQLInsert(sql); } } }