starting a tagger component

This commit is contained in:
2017-10-02 13:15:01 +02:00
parent 78881fbbf0
commit 15d10c0ecc
9 changed files with 291 additions and 3 deletions

View File

@ -4,11 +4,13 @@ using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using Newtonsoft.Json;
using Yavsc.Interfaces;
using Yavsc.Models.Access;
using Yavsc.Models.Relationship;
namespace Yavsc.Models
{
public partial class Blog : IBlog, ICircleAuthorized
public partial class Blog : IBlog, ICircleAuthorized, ITaggable<long>, IIdentified<long>
{
[Key(), DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Display(Name="Identifiant du post")]
@ -74,5 +76,25 @@ namespace Yavsc.Models
{
return ACL.ToArray();
}
public void Tag(Tag tag)
{
var existent = Tags.SingleOrDefault(t => t.PostId == Id && t.TagId == tag.Id);
if (existent==null) Tags.Add(new BlogTag { PostId = Id, Tag = tag } );
}
public void Detag(Tag tag)
{
var existent = Tags.SingleOrDefault(t => (( t.TagId == tag.Id) && t.PostId == Id));
if (existent!=null) Tags.Remove(existent);
}
public string[] GetTags()
{
return Tags.Select(t=>t.Tag.Name).ToArray();
}
[JsonIgnore][InverseProperty("Post")]
public virtual List<BlogTag> Tags { get; set; }
}
}