Ajout du nom du créateur sur l'appli MVC
This commit is contained in:
parent
9bbde92754
commit
db34091d6b
@ -8,5 +8,6 @@ namespace Application
|
|||||||
public string Content { get; set; }
|
public string Content { get; set; }
|
||||||
public int UpvotesCount { get; set; }
|
public int UpvotesCount { get; set; }
|
||||||
public int DownvotesCount { get; set; }
|
public int DownvotesCount { get; set; }
|
||||||
|
public string CreatedByUsername { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -45,15 +45,26 @@ namespace Application
|
|||||||
_data.Comments.Where(comment => comment.LinkId == linkId)
|
_data.Comments.Where(comment => comment.LinkId == linkId)
|
||||||
: _data.Comments;
|
: _data.Comments;
|
||||||
|
|
||||||
return comments
|
return from comment in comments
|
||||||
.OrderByDescending(comment => comment.CreatedAt)
|
join user in _data.Users on comment.CreatedBy equals user.Id
|
||||||
.Select(comment => new CommentDTO
|
select new CommentDTO
|
||||||
{
|
{
|
||||||
Id = comment.Id,
|
Id = comment.Id,
|
||||||
Content = comment.Content,
|
Content = comment.Content,
|
||||||
UpvotesCount = 0,
|
UpvotesCount = 0,
|
||||||
DownvotesCount = 0,
|
DownvotesCount = 0,
|
||||||
});
|
CreatedByUsername = user.UserName
|
||||||
|
};
|
||||||
|
|
||||||
|
// return comments
|
||||||
|
// .OrderByDescending(comment => comment.CreatedAt)
|
||||||
|
// .Select(comment => new CommentDTO
|
||||||
|
// {
|
||||||
|
// Id = comment.Id,
|
||||||
|
// Content = comment.Content,
|
||||||
|
// UpvotesCount = 0,
|
||||||
|
// DownvotesCount = 0,
|
||||||
|
// });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -10,5 +10,6 @@ namespace Application
|
|||||||
{
|
{
|
||||||
IQueryable<Link> Links { get; }
|
IQueryable<Link> Links { get; }
|
||||||
IQueryable<Comment> Comments { get; }
|
IQueryable<Comment> Comments { get; }
|
||||||
|
IQueryable<IUser> Users { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
10
Application/IUser.cs
Normal file
10
Application/IUser.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Application
|
||||||
|
{
|
||||||
|
public interface IUser
|
||||||
|
{
|
||||||
|
Guid Id { get; }
|
||||||
|
string UserName { get; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -10,5 +10,6 @@ namespace Application
|
|||||||
public int UpvotesCount { get; set; }
|
public int UpvotesCount { get; set; }
|
||||||
public int DownvotesCount { get; set; }
|
public int DownvotesCount { get; set; }
|
||||||
public int CommentsCount { get; set; }
|
public int CommentsCount { get; set; }
|
||||||
|
public string CreatedByUsername { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -52,6 +52,7 @@ namespace Application
|
|||||||
{
|
{
|
||||||
return (from link in _data.Links
|
return (from link in _data.Links
|
||||||
// join comment in _data.Comments on link.Id equals comment.LinkId into comments
|
// join comment in _data.Comments on link.Id equals comment.LinkId into comments
|
||||||
|
join user in _data.Users on link.CreatedBy equals user.Id
|
||||||
orderby link.CreatedAt descending
|
orderby link.CreatedAt descending
|
||||||
select new LinkDTO
|
select new LinkDTO
|
||||||
{
|
{
|
||||||
@ -61,6 +62,7 @@ namespace Application
|
|||||||
UpvotesCount = 2,
|
UpvotesCount = 2,
|
||||||
DownvotesCount = 4,
|
DownvotesCount = 4,
|
||||||
CommentsCount = _data.Comments.Count(comment => comment.LinkId == link.Id), //comments.Count(),
|
CommentsCount = _data.Comments.Count(comment => comment.LinkId == link.Id), //comments.Count(),
|
||||||
|
CreatedByUsername = user.UserName,
|
||||||
});
|
});
|
||||||
|
|
||||||
// return _data.Links
|
// return _data.Links
|
||||||
|
|||||||
@ -19,7 +19,7 @@ else
|
|||||||
<ul>
|
<ul>
|
||||||
@foreach (var comment in Model.Comments)
|
@foreach (var comment in Model.Comments)
|
||||||
{
|
{
|
||||||
<li>@comment.Content</li>
|
<li>@comment.Content - @comment.CreatedByUsername</li>
|
||||||
}
|
}
|
||||||
</ul>
|
</ul>
|
||||||
}
|
}
|
||||||
@ -4,7 +4,7 @@
|
|||||||
<h2>@Model.Url</h2>
|
<h2>@Model.Url</h2>
|
||||||
<p>
|
<p>
|
||||||
<a asp-controller="Links" asp-action="Show" asp-route-linkId="@Model.Id">Show</a>
|
<a asp-controller="Links" asp-action="Show" asp-route-linkId="@Model.Id">Show</a>
|
||||||
- Published at @Model.CreatedAt.ToLongDateString()
|
- Published at @Model.CreatedAt.ToLongDateString() by @Model.CreatedByUsername
|
||||||
- 🗨 @Model.CommentsCount
|
- 🗨 @Model.CommentsCount
|
||||||
- 👍 @Model.UpvotesCount / 👎 @Model.DownvotesCount
|
- 👍 @Model.UpvotesCount / 👎 @Model.DownvotesCount
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
@ -17,6 +17,8 @@ namespace Infrastructure
|
|||||||
|
|
||||||
IQueryable<Comment> IData.Comments => Comments;
|
IQueryable<Comment> IData.Comments => Comments;
|
||||||
|
|
||||||
|
IQueryable<IUser> IData.Users => Users;
|
||||||
|
|
||||||
public HNDbContext() : base()
|
public HNDbContext() : base()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using Application;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
|
||||||
namespace Infrastructure.Identity
|
namespace Infrastructure.Identity
|
||||||
{
|
{
|
||||||
public class User : IdentityUser<Guid>
|
public class User : IdentityUser<Guid>, IUser
|
||||||
{
|
{
|
||||||
// On peut ajouter des propriétés ici au besoin
|
// On peut ajouter des propriétés ici au besoin
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,6 +13,8 @@ namespace Infrastructure.Repositories.Memory
|
|||||||
|
|
||||||
public IQueryable<Comment> Comments => _commentRepository.Comments.AsQueryable();
|
public IQueryable<Comment> Comments => _commentRepository.Comments.AsQueryable();
|
||||||
|
|
||||||
|
public IQueryable<IUser> Users => throw new System.NotImplementedException();
|
||||||
|
|
||||||
public Data(LinkRepository linkRepository, CommentRepository commentRepository)
|
public Data(LinkRepository linkRepository, CommentRepository commentRepository)
|
||||||
{
|
{
|
||||||
_linkRepository = linkRepository;
|
_linkRepository = linkRepository;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user