diff --git a/src/Yavsc/Controllers/Communicating/BlogspotController.cs b/src/Yavsc/Controllers/Communicating/BlogspotController.cs index b6f34d6e..1aadee04 100644 --- a/src/Yavsc/Controllers/Communicating/BlogspotController.cs +++ b/src/Yavsc/Controllers/Communicating/BlogspotController.cs @@ -16,6 +16,7 @@ using Microsoft.Extensions.Options; using Microsoft.EntityFrameworkCore; using System.Diagnostics; using Yavsc.ViewModels.Blog; +using System.Collections; // For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860 @@ -45,7 +46,7 @@ namespace Yavsc.Controllers public async Task Index(string id) { if (!string.IsNullOrEmpty(id)) { - return await UserPosts(id); + return View("UserPosts", await UserPosts(id)); } return View(); } @@ -63,13 +64,10 @@ namespace Yavsc.Controllers ).ToList()); } - [Route("~/Blog/{userName}/{pageLen?}/{pageNum?}")] - [AllowAnonymous] - public async Task UserPosts(string userName, int pageLen=10, int pageNum=0) + private async Task> UserPosts(string userName, int pageLen=10, int pageNum=0) { string posterId = (await _context.Users.SingleOrDefaultAsync(u=>u.UserName == userName))?.Id ?? null ; - var result = _context.UserPosts(posterId, User.Identity.Name); - return View("Index", result.ToArray().Skip(pageLen*pageNum).Take(pageLen).OrderByDescending(p => p.DateCreated).ToList().GroupBy(p=> p.Title )); + return _context.UserPosts(posterId, User.Identity.Name); } // GET: Blog/Details/5 [AllowAnonymous] diff --git a/src/Yavsc/Helpers/UserHelpers.cs b/src/Yavsc/Helpers/UserHelpers.cs index 391cbf6c..d4d5c229 100644 --- a/src/Yavsc/Helpers/UserHelpers.cs +++ b/src/Yavsc/Helpers/UserHelpers.cs @@ -14,7 +14,7 @@ namespace Yavsc.Helpers { return user.FindFirstValue("sub"); } - + public static string GetUserName(this ClaimsPrincipal user) { return user.FindFirstValue(ClaimTypes.Name); @@ -27,21 +27,28 @@ namespace Yavsc.Helpers public static IEnumerable UserPosts(this ApplicationDbContext dbContext, string posterId, string readerId) { - long[] readerCirclesMemberships = dbContext.Circle.Include(c=>c.Members).Where(c=>c.Members.Any(m=>m.MemberId == readerId)) - .Select(c=>c.Id).ToArray(); - var result = (readerId!=null) - ? - dbContext.Blogspot.Include( - b => b.Author - ).Include(p=>p.ACL).Where(x => x.Author.Id == posterId && - (x.Visible && - (x.ACL.Count==0 || x.ACL.Any(a=> readerCirclesMemberships.Contains(a.CircleId))))) - : - dbContext.Blogspot.Include( + if (readerId == null) + { + var userPosts = dbContext.Blogspot.Include( b => b.Author - ).Where(x => x.Author.Id == posterId && x.Visible); - // BlogIndexKey - return result; + ).Where(x => ((x.AuthorId == posterId) && (x.Visible))).ToArray(); + return userPosts; + } + else + { + long[] readerCirclesMemberships = + dbContext.Circle.Include(c => c.Members) + .Where(c => c.Members.Any(m => m.MemberId == readerId)) + .Select(c => c.Id).ToArray(); + return dbContext.Blogspot.Include( + b => b.Author + ).Include(p => p.ACL).Where(x => x.Author.Id == posterId && + (x.Visible && + (x.ACL.Count == 0 || x.ACL.Any(a => readerCirclesMemberships.Contains(a.CircleId))))); + + + } + } } } diff --git a/src/Yavsc/Models/ApplicationDbContext.cs b/src/Yavsc/Models/ApplicationDbContext.cs index 3d8a3009..84cff78d 100644 --- a/src/Yavsc/Models/ApplicationDbContext.cs +++ b/src/Yavsc/Models/ApplicationDbContext.cs @@ -87,7 +87,7 @@ namespace Yavsc.Models } builder.Entity().Property(a=>a.ParentCode).IsRequired(false); - builder.Entity().HasOne(p => p.Author).WithMany(a => a.Posts); + //builder.Entity().HasOne(p => p.Author).WithMany(a => a.Posts); } diff --git a/src/Yavsc/Views/Blogspot/Details.cshtml b/src/Yavsc/Views/Blogspot/Details.cshtml index 64471a1e..713f55b3 100644 --- a/src/Yavsc/Views/Blogspot/Details.cshtml +++ b/src/Yavsc/Views/Blogspot/Details.cshtml @@ -66,19 +66,20 @@ $('span.field-validation-valid[data-valmsg-for="Content"]').html( }
-

@Model.Title

- -
- @Html.DisplayForModel() -
+
+

@Model.Title

+ + @Html.DisplayFor(m=>m.Author) + @Html.DisplayFor(m=>m.Content) +
-
- @if (Model.Comments!=null) { - foreach (var comment in Model.Comments.Where(c=>c.ParentId==null)) { - @Html.DisplayFor(model=>comment,"Comment","Comment") +
+ @if (Model.Comments!=null) { + foreach (var comment in Model.Comments.Where(c=>c.ParentId==null)) { + @Html.DisplayFor(model=>comment,"Comment","Comment") + } } - } -
+
@if (User.GetUserId()!=null) {
@@ -96,9 +97,8 @@ $('span.field-validation-valid[data-valmsg-for="Content"]').html(

Vous devez être identifié pour commenter.

} -
-@if ((await AuthorizationService.AuthorizeAsync(User, Model, new EditPermission())).Succeeded) { -Edit -} -Back to List + @if ((await AuthorizationService.AuthorizeAsync(User, Model, new EditPermission())).Succeeded) { + Edit + } + Back to List
diff --git a/src/Yavsc/Views/Manage/Index.cshtml b/src/Yavsc/Views/Manage/Index.cshtml index 7f23863a..be931011 100755 --- a/src/Yavsc/Views/Manage/Index.cshtml +++ b/src/Yavsc/Views/Manage/Index.cshtml @@ -155,9 +155,9 @@ @(((double)Model.DiskUsage/Model.DiskQuota).ToString("%#0")) : } - + @(Model.DiskUsage.ToString("0,#")) / @(Model.DiskQuota.ToString("0,#")) - +
Identifiant utilisateur
diff --git a/src/Yavsc/Views/Shared/Components/BlogIndex/Default.cshtml b/src/Yavsc/Views/Shared/Components/BlogIndex/Default.cshtml index 9a2f3310..17f8d2ac 100644 --- a/src/Yavsc/Views/Shared/Components/BlogIndex/Default.cshtml +++ b/src/Yavsc/Views/Shared/Components/BlogIndex/Default.cshtml @@ -1,18 +1,19 @@ @model IEnumerable> @if (User.IsSignedIn()) { - - + } @@ -34,7 +35,7 @@
@item.Content @if (trunked) { ... } - (@Html.DisplayFor(m => item.Author), + @Html.DisplayFor(m => item.Author) posté le @item.DateCreated.ToString("dddd d MMM yyyy à H:mm") @if ((item.DateModified - item.DateCreated).Minutes > 0){  diff --git a/src/Yavsc/Views/Shared/DisplayTemplates/ApplicationUser.cshtml b/src/Yavsc/Views/Shared/DisplayTemplates/ApplicationUser.cshtml index 8fc95062..a9e0e52e 100644 --- a/src/Yavsc/Views/Shared/DisplayTemplates/ApplicationUser.cshtml +++ b/src/Yavsc/Views/Shared/DisplayTemplates/ApplicationUser.cshtml @@ -1,14 +1,14 @@ @model ApplicationUser @{ var avuri = "/Avatars/"+Model.UserName+".s.png"; - var userPosted = Model.Posts!=null && Model.Posts.Count()>1; + var userPosted = Model.Posts!=null && Model.Posts.Count()>=1; }
-@if (userPosted) { - +@Model.UserName -}else { - Html.LabelFor(m=>m.UserName); +} else { + Html.DisplayFor(m=>m.UserName); }