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 int UpvotesCount { 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;
|
||||
|
||||
return comments
|
||||
.OrderByDescending(comment => comment.CreatedAt)
|
||||
.Select(comment => new CommentDTO
|
||||
return from comment in comments
|
||||
join user in _data.Users on comment.CreatedBy equals user.Id
|
||||
select new CommentDTO
|
||||
{
|
||||
Id = comment.Id,
|
||||
Content = comment.Content,
|
||||
UpvotesCount = 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<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 DownvotesCount { get; set; }
|
||||
public int CommentsCount { get; set; }
|
||||
public string CreatedByUsername { get; set; }
|
||||
}
|
||||
}
|
||||
@ -52,6 +52,7 @@ namespace Application
|
||||
{
|
||||
return (from link in _data.Links
|
||||
// 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
|
||||
select new LinkDTO
|
||||
{
|
||||
@ -61,6 +62,7 @@ namespace Application
|
||||
UpvotesCount = 2,
|
||||
DownvotesCount = 4,
|
||||
CommentsCount = _data.Comments.Count(comment => comment.LinkId == link.Id), //comments.Count(),
|
||||
CreatedByUsername = user.UserName,
|
||||
});
|
||||
|
||||
// return _data.Links
|
||||
|
||||
@ -19,7 +19,7 @@ else
|
||||
<ul>
|
||||
@foreach (var comment in Model.Comments)
|
||||
{
|
||||
<li>@comment.Content</li>
|
||||
<li>@comment.Content - @comment.CreatedByUsername</li>
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
@ -4,7 +4,7 @@
|
||||
<h2>@Model.Url</h2>
|
||||
<p>
|
||||
<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.UpvotesCount / 👎 @Model.DownvotesCount
|
||||
</p>
|
||||
|
||||
@ -17,6 +17,8 @@ namespace Infrastructure
|
||||
|
||||
IQueryable<Comment> IData.Comments => Comments;
|
||||
|
||||
IQueryable<IUser> IData.Users => Users;
|
||||
|
||||
public HNDbContext() : base()
|
||||
{
|
||||
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
using System;
|
||||
using Application;
|
||||
using Microsoft.AspNetCore.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
|
||||
}
|
||||
|
||||
@ -13,6 +13,8 @@ namespace Infrastructure.Repositories.Memory
|
||||
|
||||
public IQueryable<Comment> Comments => _commentRepository.Comments.AsQueryable();
|
||||
|
||||
public IQueryable<IUser> Users => throw new System.NotImplementedException();
|
||||
|
||||
public Data(LinkRepository linkRepository, CommentRepository commentRepository)
|
||||
{
|
||||
_linkRepository = linkRepository;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user