1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- using System;
- 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,
- [Display(Name = "Добавлена")]
- Added,
- [Display(Name = "Отредактирована")]
- Edited,
- [Display(Name = "Проверена")]
- Verified,
- [Display(Name = "Отклонена")]
- Rejected,
- [Display(Name = "Удалена")]
- Deleted }
- public class ArticleModel : ICloneable
- {
- public int ID { get; set; }
- public string Filename { get; set; }
- [Required]
- public string Name { get; set; }
- [Required]
- public DateTime PublishDate { get; set; } = DateTime.Now.Date;
- [Required]
- public string Authors { get; set; }
- [Required]
- public string Keywords { get; set; }
- [Required]
- public string Annotation { get; set; }
- public string Text { get; set; }
- public ArticleStatus Status { get; set; } = ArticleStatus.New;
- public int? Rating
- {
- get { return rating; }
- set
- {
- rating = value;
- if (rating < 1) rating = 1;
- if (rating > 5) rating = 5;
- }
- }
- private int? rating;
- private string initiatorUUID = "";
- public async Task<int> GetEditsCount(string acc_id = "")
- {
- MySQLConnector dbCon = MySQLConnector.Instance();
- string stringSQL = $"SELECT COUNT(*) " +
- $"FROM articles_edit_log ";
- if (acc_id.Length < 36)
- stringSQL += $"WHERE article_id={this.ID}";
- else
- stringSQL += $"WHERE article_id={this.ID} AND acc_id='{acc_id}'";
- int count = await dbCon.SQLSelectCount(stringSQL);
- dbCon.Close();
- return count;
- }
- public async Task<string> GetInitiatorUUID()
- {
- if (initiatorUUID.Length < 36)
- {
- Console.WriteLine("initiatorUUID is null, getting it from DB");
- MySQLConnector dbCon = MySQLConnector.Instance();
- string stringSQL = $"SELECT acc_id " +
- $"FROM articles " +
- $"JOIN actions_history ON actions_history.article_id = articles.id " +
- $"WHERE articles.id={this.ID} AND action_type={(int)ArticleStatus.Added}";
- initiatorUUID = await dbCon.SQLSelectUUID(stringSQL);
- dbCon.Close();
- }
- else
- Console.WriteLine("initiatorUUID already set");
- return initiatorUUID;
- }
- public object Clone()
- {
- return MemberwiseClone();
- }
- }
- }
|