Merge branch 'patch_dev' into dev
This commit is contained in:
@@ -38,6 +38,7 @@ namespace Webzine.WebApplication.Controllers
|
|||||||
/// Affiche le detail d'un titre specifique.
|
/// Affiche le detail d'un titre specifique.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id">Identifiant du titre.</param>
|
/// <param name="id">Identifiant du titre.</param>
|
||||||
|
/// <param name="model">Model de donnée pour un commentaire.</param>
|
||||||
/// <returns>Vue des details ou 404 si introuvable.</returns>
|
/// <returns>Vue des details ou 404 si introuvable.</returns>
|
||||||
public IActionResult Index(int id)
|
public IActionResult Index(int id)
|
||||||
{
|
{
|
||||||
@@ -48,34 +49,11 @@ namespace Webzine.WebApplication.Controllers
|
|||||||
if (titre == null)
|
if (titre == null)
|
||||||
{
|
{
|
||||||
this.logger.LogWarning("Titre avec ID {Id} introuvable.", id);
|
this.logger.LogWarning("Titre avec ID {Id} introuvable.", id);
|
||||||
return this.RedirectToAction("Index");
|
return this.RedirectToAction("Index", "Accueil");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.titreRepository.IncrementNbLectures(titre);
|
this.titreRepository.IncrementNbLectures(titre);
|
||||||
|
return this.View(this.BuildTitreDetailViewModel(titre));
|
||||||
var vm = new TitreDetail
|
|
||||||
{
|
|
||||||
Details = new TitreContent
|
|
||||||
{
|
|
||||||
IdTitre = titre.IdTitre,
|
|
||||||
Libelle = titre.Libelle,
|
|
||||||
Chronique = titre.Chronique,
|
|
||||||
DateSortie = titre.DateSortie,
|
|
||||||
NbLikes = titre.NbLikes,
|
|
||||||
UrlJaquette = titre.UrlJaquette,
|
|
||||||
UrlEcoute = titre.UrlEcoute,
|
|
||||||
UrlEmbedEcoute = BuildSpotifyEmbedUrl(titre.UrlEcoute),
|
|
||||||
ArtisteNom = titre.Artiste.Nom,
|
|
||||||
Styles = titre.Styles,
|
|
||||||
Commentaires = titre.Commentaires,
|
|
||||||
},
|
|
||||||
CommentForm = new TitreComment
|
|
||||||
{
|
|
||||||
IdTitre = titre.IdTitre,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
return this.View(vm);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -121,8 +99,20 @@ namespace Webzine.WebApplication.Controllers
|
|||||||
/// <param name="model">Donnees du commentaire.</param>
|
/// <param name="model">Donnees du commentaire.</param>
|
||||||
/// <returns>Redirection vers la page detail.</returns>
|
/// <returns>Redirection vers la page detail.</returns>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public IActionResult Comment(TitreComment model)
|
public IActionResult Comment([Bind(Prefix = "CommentForm")] TitreComment model)
|
||||||
{
|
{
|
||||||
|
if (!this.ModelState.IsValid)
|
||||||
|
{
|
||||||
|
var titre = this.titreRepository.Find(model.IdTitre);
|
||||||
|
if (titre == null)
|
||||||
|
{
|
||||||
|
this.logger.LogWarning("Titre avec ID {Id} introuvable pour ajout de commentaire.", model.IdTitre);
|
||||||
|
return this.RedirectToAction("Index", "Accueil");
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.View("Index", this.BuildTitreDetailViewModel(titre, model));
|
||||||
|
}
|
||||||
|
|
||||||
var titreToUpdate = this.titreRepository.Find(model.IdTitre);
|
var titreToUpdate = this.titreRepository.Find(model.IdTitre);
|
||||||
if (titreToUpdate != null)
|
if (titreToUpdate != null)
|
||||||
{
|
{
|
||||||
@@ -141,6 +131,31 @@ namespace Webzine.WebApplication.Controllers
|
|||||||
return this.RedirectToAction("Index", new { id = model.IdTitre });
|
return this.RedirectToAction("Index", new { id = model.IdTitre });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private TitreDetail BuildTitreDetailViewModel(Titre titre, TitreComment? commentForm = null)
|
||||||
|
{
|
||||||
|
return new TitreDetail
|
||||||
|
{
|
||||||
|
Details = new TitreContent
|
||||||
|
{
|
||||||
|
IdTitre = titre.IdTitre,
|
||||||
|
Libelle = titre.Libelle,
|
||||||
|
Chronique = titre.Chronique,
|
||||||
|
DateSortie = titre.DateSortie,
|
||||||
|
NbLikes = titre.NbLikes,
|
||||||
|
UrlJaquette = titre.UrlJaquette,
|
||||||
|
UrlEcoute = titre.UrlEcoute,
|
||||||
|
UrlEmbedEcoute = BuildSpotifyEmbedUrl(titre.UrlEcoute),
|
||||||
|
ArtisteNom = titre.Artiste.Nom,
|
||||||
|
Styles = titre.Styles,
|
||||||
|
Commentaires = titre.Commentaires,
|
||||||
|
},
|
||||||
|
CommentForm = commentForm ?? new TitreComment
|
||||||
|
{
|
||||||
|
IdTitre = titre.IdTitre,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Mappe une entite Titre vers un item de la liste de titres pour l'affichage dans la vue de style.
|
/// Mappe une entite Titre vers un item de la liste de titres pour l'affichage dans la vue de style.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -23,6 +23,15 @@ public class ValidationActionFilter : IActionFilter
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public void OnActionExecuting(ActionExecutingContext context)
|
public void OnActionExecuting(ActionExecutingContext context)
|
||||||
{
|
{
|
||||||
|
string controllerName = context.RouteData.Values["controller"]?.ToString() ?? string.Empty;
|
||||||
|
string actionName = context.RouteData.Values["action"]?.ToString() ?? string.Empty;
|
||||||
|
|
||||||
|
if (controllerName.Equals("Titre", StringComparison.OrdinalIgnoreCase)
|
||||||
|
&& actionName.Equals("Comment", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!context.ModelState.IsValid)
|
if (!context.ModelState.IsValid)
|
||||||
{
|
{
|
||||||
var erreurs = context.ModelState
|
var erreurs = context.ModelState
|
||||||
@@ -35,8 +44,6 @@ public class ValidationActionFilter : IActionFilter
|
|||||||
context.ActionDescriptor.DisplayName,
|
context.ActionDescriptor.DisplayName,
|
||||||
string.Join(" | ", erreurs));
|
string.Join(" | ", erreurs));
|
||||||
|
|
||||||
string actionName = context.RouteData.Values["action"]?.ToString() ?? string.Empty;
|
|
||||||
|
|
||||||
// cas spécial: titre details
|
// cas spécial: titre details
|
||||||
if (actionName.Equals("Index", StringComparison.OrdinalIgnoreCase))
|
if (actionName.Equals("Index", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -125,30 +125,31 @@
|
|||||||
<h4 class="mb-4">Donne ton avis sur le titre</h4>
|
<h4 class="mb-4">Donne ton avis sur le titre</h4>
|
||||||
|
|
||||||
<form asp-action="Comment" asp-controller="Titre" asp-route-id="@Model.Details.IdTitre" method="post">
|
<form asp-action="Comment" asp-controller="Titre" asp-route-id="@Model.Details.IdTitre" method="post">
|
||||||
<input type="hidden" name="IdTitre" value="@Model.Details.IdTitre"/>
|
<input asp-for="CommentForm.IdTitre" type="hidden" />
|
||||||
|
<div asp-validation-summary="ModelOnly" class="text-danger mb-3"></div>
|
||||||
|
|
||||||
<div class="row mb-3 align-items-center">
|
<div class="row mb-3 align-items-center">
|
||||||
<label class="col-sm-2 col-form-label">
|
<label asp-for="CommentForm.Auteur" class="col-sm-2 col-form-label">
|
||||||
Nom<span class="text-danger">*</span>
|
Nom<span class="text-danger">*</span>
|
||||||
</label>
|
</label>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<input name="Auteur"
|
<input asp-for="CommentForm.Auteur"
|
||||||
class="form-control input-full"
|
class="form-control input-full"
|
||||||
placeholder="Votre nom"
|
placeholder="Votre nom" />
|
||||||
required/>
|
<span asp-validation-for="CommentForm.Auteur" class="text-danger"></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row mb-3 align-items-start">
|
<div class="row mb-3 align-items-start">
|
||||||
<label class="col-sm-2 col-form-label">
|
<label asp-for="CommentForm.Contenu" class="col-sm-2 col-form-label">
|
||||||
Commentaire<span class="text-danger">*</span>
|
Commentaire<span class="text-danger">*</span>
|
||||||
</label>
|
</label>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<textarea name="Contenu"
|
<textarea asp-for="CommentForm.Contenu"
|
||||||
rows="3"
|
rows="3"
|
||||||
class="form-control input-full"
|
class="form-control input-full"
|
||||||
placeholder="Votre commentaire..."
|
placeholder="Votre commentaire..."></textarea>
|
||||||
required></textarea>
|
<span asp-validation-for="CommentForm.Contenu" class="text-danger"></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user