diff --git a/Yavsc/Controllers/BlogspotController.cs b/Yavsc/Controllers/BlogspotController.cs index cebd5cdd..11e6cd59 100644 --- a/Yavsc/Controllers/BlogspotController.cs +++ b/Yavsc/Controllers/BlogspotController.cs @@ -106,7 +106,9 @@ namespace Yavsc.Controllers Blog blog = _context.Blogspot.Include( b => b.Author - ).Include(p => p.ACL).Single(m => m.Id == id); + ) + .Include(p=>p.Tags) + .Include(p => p.ACL).Single(m => m.Id == id); if (blog == null) { return HttpNotFound(); diff --git a/Yavsc/Interfaces/ITaggable.cs b/Yavsc/Interfaces/ITaggable.cs new file mode 100644 index 00000000..106c6aca --- /dev/null +++ b/Yavsc/Interfaces/ITaggable.cs @@ -0,0 +1,14 @@ +using Yavsc.Models.Relationship; + +namespace Yavsc.Interfaces +{ + public interface ITaggable + { + void Tag(Tag tag); + void Detag(Tag tag); + + string [] GetTags(); + + K Id { get; } + } +} \ No newline at end of file diff --git a/Yavsc/Models/Blog/Blog.cs b/Yavsc/Models/Blog/Blog.cs index 64b4fefb..6fd19ade 100644 --- a/Yavsc/Models/Blog/Blog.cs +++ b/Yavsc/Models/Blog/Blog.cs @@ -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, IIdentified { [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 Tags { get; set; } } } diff --git a/Yavsc/Resources/Yavsc.ViewComponents.TaggerViewComponent.en.resx b/Yavsc/Resources/Yavsc.ViewComponents.TaggerViewComponent.en.resx new file mode 100644 index 00000000..609000da --- /dev/null +++ b/Yavsc/Resources/Yavsc.ViewComponents.TaggerViewComponent.en.resx @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + a test + \ No newline at end of file diff --git a/Yavsc/Resources/Yavsc.ViewComponents.TaggerViewComponent.fr.resx b/Yavsc/Resources/Yavsc.ViewComponents.TaggerViewComponent.fr.resx new file mode 100644 index 00000000..d1d8e94d --- /dev/null +++ b/Yavsc/Resources/Yavsc.ViewComponents.TaggerViewComponent.fr.resx @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + un test + \ No newline at end of file diff --git a/Yavsc/Resources/Yavsc.ViewComponents.TaggerViewComponent.resx b/Yavsc/Resources/Yavsc.ViewComponents.TaggerViewComponent.resx new file mode 100644 index 00000000..6cba09d6 --- /dev/null +++ b/Yavsc/Resources/Yavsc.ViewComponents.TaggerViewComponent.resx @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + tagblog + \ No newline at end of file diff --git a/Yavsc/ViewComponents/TaggerComponent.cs b/Yavsc/ViewComponents/TaggerComponent.cs new file mode 100644 index 00000000..1edd1b4a --- /dev/null +++ b/Yavsc/ViewComponents/TaggerComponent.cs @@ -0,0 +1,33 @@ +using System.Linq; +using Microsoft.AspNet.Mvc; +using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Logging; +using Yavsc.Interfaces; +using Yavsc.Models; + +namespace Yavsc.ViewComponents +{ + public class TaggerViewComponent : ViewComponent + + { + ApplicationDbContext dbContext; + IStringLocalizer localizer; + ILogger logger ; + public TaggerViewComponent( + ApplicationDbContext pdbContext, + IStringLocalizer pLocalizer, + ILoggerFactory loggerFactory) + { + dbContext = pdbContext; + this.localizer = pLocalizer; + this.logger = loggerFactory.CreateLogger(); + } + public IViewComponentResult Invoke(ITaggable longTaggable) + { + ViewData["Tags"] = longTaggable.GetTags(); + ViewData["at"] = localizer["at"]; + ViewData["apictlr"] = "~/api/"+localizer["apiRouteTag"+longTaggable.GetType().Name]; + return View(longTaggable); + } + } +} \ No newline at end of file diff --git a/Yavsc/Views/Blogspot/Details.cshtml b/Yavsc/Views/Blogspot/Details.cshtml index 700a77ec..95bee352 100644 --- a/Yavsc/Views/Blogspot/Details.cshtml +++ b/Yavsc/Views/Blogspot/Details.cshtml @@ -1,5 +1,4 @@ @model Blog - @{ ViewData["Title"]=Model.Title; } @@ -21,6 +20,8 @@ @Html.DisplayNameFor(model => model.DateCreated) : @Html.DisplayFor(model => model.DateCreated) + + @Component.Invoke("Tagger",Model) diff --git a/Yavsc/Views/Shared/Components/Tagger/Default.cshtml b/Yavsc/Views/Shared/Components/Tagger/Default.cshtml new file mode 100644 index 00000000..5cfbe23e --- /dev/null +++ b/Yavsc/Views/Shared/Components/Tagger/Default.cshtml @@ -0,0 +1,30 @@ +@using Yavsc.Interfaces; +@using System; +@model ITaggable + +
+ + + +
+
+
+
+
@ViewData["apictlr"]
+ +
+
@ViewData["at"]
+
+
+
+
    + @foreach (string tag in (string[]) ViewData["Tags"]) { +
  • @tag
  • + } +
+
+ +
+ +
+
\ No newline at end of file