From 3487aa2a967a7ffd71d4c6c07d6fc86fc9cdecf5 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Thu, 5 Oct 2017 11:58:51 +0200 Subject: [PATCH] displaying blog comments --- Yavsc/ViewComponents/AvatarViewComponent.cs | 11 ++++++++++- Yavsc/ViewModels/Account/ShortUserInfo.cs | 11 +++++++++++ Yavsc/Views/Blogspot/Details.cshtml | 12 ++++++++++-- Yavsc/Views/Shared/Components/Avatar/Default.cshtml | 7 +++++-- .../Shared/DisplayTemplates/ApplicationUser.cshtml | 3 +-- .../DisplayTemplates/ApplicationUserLink.cshtml | 5 +++++ Yavsc/Views/Shared/_LoginPartial.cshtml | 2 +- Yavsc/wwwroot/css/main/site.css | 10 +++++++++- Yavsc/wwwroot/js/site.min.js | 2 +- 9 files changed, 53 insertions(+), 10 deletions(-) create mode 100644 Yavsc/ViewModels/Account/ShortUserInfo.cs create mode 100644 Yavsc/Views/Shared/DisplayTemplates/ApplicationUserLink.cshtml diff --git a/Yavsc/ViewComponents/AvatarViewComponent.cs b/Yavsc/ViewComponents/AvatarViewComponent.cs index fa90daec..42bd193a 100644 --- a/Yavsc/ViewComponents/AvatarViewComponent.cs +++ b/Yavsc/ViewComponents/AvatarViewComponent.cs @@ -1,6 +1,8 @@ +using System.Linq; using Microsoft.AspNet.Mvc; using Yavsc.Helpers; using Yavsc.Models; +using Yavsc.ViewModels.Account; namespace Yavsc.ViewComponents { @@ -14,7 +16,14 @@ namespace Yavsc.ViewComponents public IViewComponentResult Invoke ( string userId, string imgFmt ) { - return View ( "Default", dbContext.AvatarUri(userId, imgFmt)); + var user = dbContext.Users.Single(u=>u.Id == userId); + + return View ( "Default", new ShortUserInfo + { + Avatar = dbContext.AvatarUri(userId, imgFmt), + UserName = user.UserName, + UserId = userId + } ); } } diff --git a/Yavsc/ViewModels/Account/ShortUserInfo.cs b/Yavsc/ViewModels/Account/ShortUserInfo.cs new file mode 100644 index 00000000..1bf39cfe --- /dev/null +++ b/Yavsc/ViewModels/Account/ShortUserInfo.cs @@ -0,0 +1,11 @@ +namespace Yavsc.ViewModels.Account +{ + public class ShortUserInfo + { + public string Avatar { get; set; } + + public string UserName { get; set; } + + public string UserId { get; set; } + } +} \ No newline at end of file diff --git a/Yavsc/Views/Blogspot/Details.cshtml b/Yavsc/Views/Blogspot/Details.cshtml index 239e3ba4..beda9663 100644 --- a/Yavsc/Views/Blogspot/Details.cshtml +++ b/Yavsc/Views/Blogspot/Details.cshtml @@ -71,10 +71,17 @@ $('span.field-validation-valid[data-valmsg-for="Content"]').html( @Component.Invoke("Tagger",Model) - + @if (Model.Comments.Count>0) {
@foreach (Comment comment in Model.Comments) { -
+
+ +
+ @Html.DisplayFor(c=>c.Author,"ApplicationUserLink","cmtauth",comment) +
@Html.DisplayFor(c=>c.DateCreated,null,"dteCmt",comment)
+
+
+
} @@ -93,6 +100,7 @@ $('span.field-validation-valid[data-valmsg-for="Content"]').html(
+ } @if (await AuthorizationService.AuthorizeAsync(User, Model, new EditRequirement())) { @SR["Edit"] diff --git a/Yavsc/Views/Shared/Components/Avatar/Default.cshtml b/Yavsc/Views/Shared/Components/Avatar/Default.cshtml index 6460a9c0..82a93c74 100644 --- a/Yavsc/Views/Shared/Components/Avatar/Default.cshtml +++ b/Yavsc/Views/Shared/Components/Avatar/Default.cshtml @@ -1,2 +1,5 @@ -@model string - \ No newline at end of file +@model ShortUserInfo +
+@Model.UserName +
@Model.UserName
+
\ No newline at end of file diff --git a/Yavsc/Views/Shared/DisplayTemplates/ApplicationUser.cshtml b/Yavsc/Views/Shared/DisplayTemplates/ApplicationUser.cshtml index d9360dc0..c02b0fd3 100644 --- a/Yavsc/Views/Shared/DisplayTemplates/ApplicationUser.cshtml +++ b/Yavsc/Views/Shared/DisplayTemplates/ApplicationUser.cshtml @@ -2,8 +2,7 @@ @if (Model!=null) {
-

@Component.Invoke("Avatar", Model.Id, ".s") -@Model.UserName

+

@Component.Invoke("Avatar", Model.Id, ".s")

@if (Model.Posts!=null && Model.Posts.Count()>1) { @SR["index de ses articles"] } diff --git a/Yavsc/Views/Shared/DisplayTemplates/ApplicationUserLink.cshtml b/Yavsc/Views/Shared/DisplayTemplates/ApplicationUserLink.cshtml new file mode 100644 index 00000000..5a97a79c --- /dev/null +++ b/Yavsc/Views/Shared/DisplayTemplates/ApplicationUserLink.cshtml @@ -0,0 +1,5 @@ +@model ApplicationUser + +@if (Model!=null) { +@Component.Invoke("Avatar", Model.Id, ".xs") +} diff --git a/Yavsc/Views/Shared/_LoginPartial.cshtml b/Yavsc/Views/Shared/_LoginPartial.cshtml index c73c3840..87eb2d76 100755 --- a/Yavsc/Views/Shared/_LoginPartial.cshtml +++ b/Yavsc/Views/Shared/_LoginPartial.cshtml @@ -7,7 +7,7 @@
  • @Component.Invoke("Avatar", User.GetUserId(), ".xs") - @SR["Hello"] @User.GetUserName()! +
  • @if (User.IsInRole(Constants.AdminGroupName)) {