Notification.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. namespace HyperCube.Models
  6. {
  7. public enum NotificationType {System = 0, User }
  8. public class Notification
  9. {
  10. public int ID { get; set; }
  11. public NotificationType NotifiType { get; set; }
  12. public string Header { get; set; }
  13. public string Body { get; set; }
  14. public string RecipientID { get; private set; }
  15. public string SendertID { get; private set; }
  16. public bool IsRead { get; set; }
  17. public DateTime? DateRead { get; set; }
  18. public bool IsApproved { get; set; }
  19. public DateTime? DateApprove { get; set; }
  20. public bool IsRejected { get; set; }
  21. public DateTime? DateReject { get; set; }
  22. public Notification(NotificationType type, string header, string body, string recipientid, string senderid)
  23. {
  24. NotifiType = type;
  25. Header = header;
  26. Body = body;
  27. RecipientID = recipientid;
  28. SendertID = senderid;
  29. IsRead = false;
  30. IsApproved = false;
  31. IsRejected = false;
  32. }
  33. public async Task<int> Send()
  34. {
  35. string sql = $"INSERT INTO notifications (type, header, body, recipientid, senderid) " +
  36. $"VALUES ('{(int)NotifiType}','{Header}','{Body}','{RecipientID}','{SendertID}')";
  37. long id = await MySQLConnector.Instance().SQLInsert(sql);
  38. ID = (int)id;
  39. return ID;
  40. }
  41. public async Task Update()
  42. {
  43. int isread = Convert.ToInt32(IsRead);
  44. int isapproved = Convert.ToInt32(IsApproved);
  45. int isrejected = Convert.ToInt32(IsRejected);
  46. string dateread = DateRead?.ToString("yyyy-MM-dd HH:mm:ss");
  47. string dateapprove = DateApprove?.ToString("yyyy-MM-dd HH:mm:ss");
  48. string datereject = DateReject?.ToString("yyyy-MM-dd HH:mm:ss");
  49. string sql = $"UPDATE notifications" +
  50. $" SET isread='{isread}', dateread='{dateread}', isapproved='{isapproved}', dateapprove='{dateapprove}', isrejected='{isrejected}', datereject='{datereject}' " +
  51. $" WHERE id ='{ID}'";
  52. await MySQLConnector.Instance().SQLInsert(sql);
  53. }
  54. }
  55. }