yavsc/src/Server/Models/Blog/BlogPost.cs

115 lines
3.1 KiB
C#
Raw Normal View History

2016-05-17 18:22:18 +02:00
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
2016-08-03 23:25:57 +02:00
using Newtonsoft.Json;
2025-06-29 19:53:56 +01:00
using Yavsc.Abstract.Identity;
2018-07-16 02:36:44 +02:00
using Yavsc.Abstract.Identity.Security;
2017-10-02 13:15:01 +02:00
using Yavsc.Interfaces;
2017-01-20 14:20:44 +01:00
using Yavsc.Models.Access;
2017-10-02 13:15:01 +02:00
using Yavsc.Models.Relationship;
2016-05-17 18:22:18 +02:00
2017-10-04 23:53:47 +02:00
namespace Yavsc.Models.Blog
2016-05-17 18:22:18 +02:00
{
2026-02-22 19:54:10 +00:00
public class BlogPostEditViewModel : BlogPost
{
public BlogPostEditViewModel(BlogPost post, bool publish)
{
Id = post.Id;
AuthorId = post.AuthorId;
ACL = post.ACL;
Content = post.Content;
Title = post.Title;
Publish = publish;
}
public bool Publish { get; set; }
}
public class BlogPost :
IBlogPost, ICircleAuthorized, ITaggable<long>
2016-05-17 18:22:18 +02:00
{
[Key(), DatabaseGenerated(DatabaseGeneratedOption.Identity)]
2026-02-22 19:54:10 +00:00
[Display(Name = "Identifiant du post")]
public long Id { get; set; }
[StringLength(1024)]
public string? Photo { get; set; }
[StringLength(1024)]
[Required]
public string Title { get; set; }
[StringLength(56224)]
public string? Content { get; set; }
[InverseProperty("Target")]
[Display(Name = "Liste de contrôle d'accès")]
public virtual List<CircleAuthorizationToBlogPost>? ACL { get; set; }
2016-07-27 10:55:44 +02:00
2026-02-22 19:54:10 +00:00
[Display(Name = "Identifiant de l'auteur")]
2023-03-26 21:48:25 +01:00
[ForeignKey("Author")]
2026-02-22 19:54:10 +00:00
public string? AuthorId { get; set; }
2017-03-10 16:42:57 +01:00
2026-02-22 19:54:10 +00:00
[Display(Name = "Auteur")]
public virtual ApplicationUser? Author { set; get; }
2017-10-04 23:53:47 +02:00
2017-01-17 14:56:53 +01:00
2026-02-22 19:54:10 +00:00
[Display(Name = "Date de création")]
2017-01-17 14:56:53 +01:00
public DateTime DateCreated
{
get; set;
}
2026-02-22 19:54:10 +00:00
[Display(Name = "Créateur")]
2025-06-13 15:22:02 +01:00
public string? UserCreated
2017-01-17 14:56:53 +01:00
{
get; set;
}
2026-02-22 19:54:10 +00:00
[Display(Name = "Dernière modification")]
2017-01-17 14:56:53 +01:00
public DateTime DateModified
{
get; set;
}
2026-02-22 19:54:10 +00:00
[Display(Name = "Utilisateur ayant modifé le dernier")]
public string? UserModified
2017-01-17 14:56:53 +01:00
{
get; set;
}
2017-05-27 16:22:58 +02:00
public bool AuthorizeCircle(long circleId)
{
2026-02-22 19:54:10 +00:00
return ACL?.Any(i => i.CircleId == circleId) ?? true;
}
public ICircleAuthorization[] GetACL()
{
return ACL.ToArray();
}
2017-10-02 13:15:01 +02:00
public void Tag(Tag tag)
{
2026-02-22 19:54:10 +00:00
var existent = Tags.SingleOrDefault(t => t.PostId == Id && t.TagId == tag.Id);
if (existent == null) Tags.Add(new BlogTag { PostId = Id, Tag = tag });
2017-10-02 13:15:01 +02:00
}
2025-02-23 20:23:23 +00:00
public void DeTag(Tag tag)
2017-10-02 13:15:01 +02:00
{
2026-02-22 19:54:10 +00:00
var existent = Tags.SingleOrDefault(t => ((t.TagId == tag.Id) && t.PostId == Id));
if (existent != null) Tags.Remove(existent);
2017-10-02 13:15:01 +02:00
}
public string[] GetTags()
{
2026-02-22 19:54:10 +00:00
return Tags.Select(t => t.Tag.Name).ToArray();
2017-10-02 13:15:01 +02:00
}
2017-10-04 23:53:47 +02:00
[InverseProperty("Post")]
2026-02-22 19:54:10 +00:00
public virtual List<BlogTag> Tags { get; set; }
2017-10-04 23:53:47 +02:00
[InverseProperty("Post")]
2026-02-22 19:54:10 +00:00
public virtual List<Comment> Comments { get; set; }
2025-02-08 20:06:24 +00:00
2025-06-29 19:53:56 +01:00
IApplicationUser IBlogPost.Author { get => this.Author; }
2016-05-17 18:22:18 +02:00
}
}