AppData.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using HyperCube.Models;
  6. using Microsoft.AspNetCore.Components;
  7. using Microsoft.AspNetCore.Components.Authorization;
  8. using Microsoft.AspNetCore.Identity;
  9. using Console = HyperCube.Utils.AdvConsole;
  10. namespace HyperCube
  11. {
  12. /// <summary>
  13. /// Синглтон приложения
  14. /// </summary>
  15. public class AppData
  16. {
  17. public ReportModel Report { get; set; } = new();
  18. public AccountModel CurrentAccount { get; set; }
  19. public ArticleModel CurrentArticle { get; set; }
  20. public ArticleModel CurrentArticleClone { get; set; }
  21. private static Dictionary<int, ArticleModel> _articles;
  22. public static Dictionary<int, ArticleModel> Articles
  23. {
  24. get
  25. {
  26. if (_articles == null)
  27. LoadArticles();
  28. return _articles;
  29. }
  30. }
  31. public static async Task LoadArticles()
  32. {
  33. Console.WriteLine("GetArticles()");
  34. MySQLConnector dbCon = MySQLConnector.Instance();
  35. string stringSQL = $"SELECT a.id, filename, article_name, date_publish, authors, ah.action_type " +
  36. $"FROM articles a " +
  37. $"LEFT JOIN actions_history ah ON a.id = ah.article_id " +
  38. $"AND EXISTS (SELECT 1 FROM actions_history ah1 WHERE ah.article_id = ah1.article_id HAVING MAX(ah1.date_add) = ah.date_add) " +
  39. $"ORDER BY a.id";
  40. _articles = await dbCon.SQLSelectArticles(stringSQL);
  41. }
  42. }
  43. }