|
@@ -1,11 +1,12 @@
|
|
|
using System;
|
|
|
+using System.Collections.Generic;
|
|
|
using System.ComponentModel;
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
using System.Threading.Tasks;
|
|
|
using Console = HyperCube.Utils.AdvConsole;
|
|
|
|
|
|
namespace HyperCube.Models
|
|
|
-{
|
|
|
+{
|
|
|
public enum ArticleStatus {
|
|
|
[Display(Name = "Новая")]
|
|
|
New = 0,
|
|
@@ -22,6 +23,21 @@ namespace HyperCube.Models
|
|
|
|
|
|
public class ArticleModel : ICloneable
|
|
|
{
|
|
|
+ public static Dictionary<int, ArticleModel> articleModels;
|
|
|
+ public static async Task LoadArticles()
|
|
|
+ {
|
|
|
+ MySQLConnector dbCon = MySQLConnector.Instance();
|
|
|
+
|
|
|
+ string stringSQL = $"SELECT a.id, filename, article_name, date_publish, authors, ah.action_type " +
|
|
|
+ $"FROM articles a " +
|
|
|
+ $"LEFT JOIN actions_history ah ON a.id = ah.article_id " +
|
|
|
+ $"AND EXISTS (SELECT 1 FROM actions_history ah1 WHERE ah.article_id = ah1.article_id HAVING MAX(ah1.date_add) = ah.date_add) " +
|
|
|
+ $"ORDER BY a.id";
|
|
|
+ articleModels = await dbCon.SQLSelectArticles(stringSQL);
|
|
|
+ //dbCon.Close();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public int ID { get; set; }
|
|
|
public string Filename { get; set; }
|
|
|
[Required]
|
|
@@ -52,6 +68,16 @@ namespace HyperCube.Models
|
|
|
private int? rating;
|
|
|
private string initiatorUUID = "";
|
|
|
|
|
|
+ public static ArticleModel Find(int id)
|
|
|
+ {
|
|
|
+ if (id > 0) {
|
|
|
+
|
|
|
+ if (articleModels.ContainsKey(id))
|
|
|
+ return articleModels[id];
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
public async Task<int> GetEditsCount(string acc_id = "")
|
|
|
{
|
|
|
MySQLConnector dbCon = MySQLConnector.Instance();
|