Merge branch 'dev' into j2/fix/refactor-routes
# Conflicts: # Webzine.WebApplication/Controllers/RechercheController.cs # Webzine.WebApplication/Views/Recherche/Index.cshtml
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
namespace Webzine.WebApplication.Areas.Administration.Controllers;
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
using Webzine.Entity;
|
||||
using Webzine.Repository.Contracts;
|
||||
using Webzine.WebApplication.Areas.Administration.ViewModels.Artiste;
|
||||
|
||||
namespace Webzine.WebApplication.Areas.Administration.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// Contrôleur pour la gestion des artistes dans l'administration du webzine.
|
||||
/// </summary>
|
||||
@@ -49,14 +50,37 @@ public class ArtisteController : Controller
|
||||
/// <returns>Redirection.</returns>
|
||||
public IActionResult Create()
|
||||
{
|
||||
var model = new AdminArtisteForm
|
||||
return this.View();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Formulaire de création d'un artiste.
|
||||
/// </summary>
|
||||
/// <param name="model">Paramètre nécessaire pour la création d'un artiste.</param>
|
||||
/// <returns>Redirection sur la page Index.</returns>
|
||||
[HttpPost]
|
||||
public IActionResult Create(ArtisteCreateViewModel model)
|
||||
{
|
||||
// vérifier si les données sont corrects.
|
||||
if (!this.ModelState.IsValid)
|
||||
{
|
||||
Id = 0,
|
||||
Nom = string.Empty,
|
||||
Biographie = string.Empty,
|
||||
// Passer model en paramètre afin que
|
||||
// l'utilisateur conserve sa saissie.
|
||||
return this.View(model);
|
||||
}
|
||||
|
||||
// Créer un objet Artiste avecc les paramètres.
|
||||
var artiste = new Artiste
|
||||
{
|
||||
Nom = model.Nom,
|
||||
Biographie = model.Biographie,
|
||||
};
|
||||
|
||||
return this.View(model);
|
||||
// Persister les données.
|
||||
this.artisteRepository.Add(artiste);
|
||||
|
||||
// Renvoyer sur la page Index.
|
||||
return this.RedirectToAction("Index");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -68,14 +92,37 @@ public class ArtisteController : Controller
|
||||
{
|
||||
var artiste = this.artisteRepository.Find(id);
|
||||
|
||||
var model = new AdminArtisteForm
|
||||
if (artiste == null)
|
||||
{
|
||||
Id = artiste.IdArtiste,
|
||||
Nom = artiste.Nom,
|
||||
Biographie = artiste.Biographie,
|
||||
return this.RedirectToAction("Index");
|
||||
}
|
||||
|
||||
return this.View(artiste);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Traitement du formulaire de modification d'un artiste.
|
||||
/// </summary>
|
||||
/// <param name="model">Paramètre d'un artiste.</param>
|
||||
/// <returns>Redirection sur Index.</returns>
|
||||
[HttpPost]
|
||||
public IActionResult Edit(ArtisteEditViewModel model)
|
||||
{
|
||||
var artiste = new Artiste
|
||||
{
|
||||
IdArtiste = model.Id,
|
||||
Nom = model.Nom,
|
||||
Biographie = model.Biographie,
|
||||
};
|
||||
|
||||
return this.View(model);
|
||||
if (!this.ModelState.IsValid)
|
||||
{
|
||||
return this.View(artiste);
|
||||
}
|
||||
|
||||
this.artisteRepository.Update(artiste);
|
||||
|
||||
return this.RedirectToAction("Index");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -86,6 +133,12 @@ public class ArtisteController : Controller
|
||||
public IActionResult Delete(int id)
|
||||
{
|
||||
var artiste = this.artisteRepository.Find(id);
|
||||
|
||||
if (artiste == null)
|
||||
{
|
||||
return this.RedirectToAction("Index");
|
||||
}
|
||||
|
||||
var model = new AdminArtisteForm
|
||||
{
|
||||
Id = id,
|
||||
|
||||
@@ -53,6 +53,11 @@ namespace Webzine.WebApplication.Areas.Administration.Controllers
|
||||
{
|
||||
var commentaire = this.commentaireRepository.Find(id);
|
||||
|
||||
if (commentaire == null)
|
||||
{
|
||||
return this.RedirectToAction("Index");
|
||||
}
|
||||
|
||||
var model = new CommentaireDeleteViewModel
|
||||
{
|
||||
IdCommentaire = commentaire.IdCommentaire,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using System.Diagnostics;
|
||||
namespace Webzine.WebApplication.Areas.Administration.Controllers;
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
using Webzine.Repository.Contracts;
|
||||
using Webzine.WebApplication.Areas.Administration.ViewModels;
|
||||
|
||||
namespace Webzine.WebApplication.Areas.Administration.Controllers;
|
||||
|
||||
[Area("Administration")]
|
||||
public class DashboardController : Controller
|
||||
{
|
||||
|
||||
@@ -1,109 +1,170 @@
|
||||
namespace Webzine.WebApplication.Areas.Administration.Controllers
|
||||
{
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
namespace Webzine.WebApplication.Areas.Administration.Controllers;
|
||||
|
||||
using Webzine.Repository.Contracts;
|
||||
using Webzine.WebApplication.Areas.Administration.ViewModels.Style;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
using Webzine.Entity;
|
||||
using Webzine.Repository.Contracts;
|
||||
using Webzine.WebApplication.Areas.Administration.ViewModels.Style;
|
||||
|
||||
/// <summary>
|
||||
/// Controleur pour la gestion des styles dans l'administration du webzine.
|
||||
/// </summary>
|
||||
[Area("Administration")]
|
||||
public class StyleController : Controller
|
||||
{
|
||||
private readonly ILogger<StyleController> logger;
|
||||
private readonly IStyleRepository styleRepository;
|
||||
|
||||
/// <summary>
|
||||
/// Contrôleur pour la gestion des styles dans l'administration du webzine.
|
||||
/// Initializes a new instance of the <see cref="StyleController"/> class.
|
||||
/// </summary>
|
||||
[Area("Administration")]
|
||||
public class StyleController : Controller
|
||||
/// <param name="logger">Service de journalisation injecte.</param>
|
||||
/// <param name="styleRepository">Repository des styles injecte.</param>
|
||||
public StyleController(
|
||||
ILogger<StyleController> logger,
|
||||
IStyleRepository styleRepository)
|
||||
{
|
||||
private readonly ILogger<StyleController> logger;
|
||||
private readonly IStyleRepository styleRepository;
|
||||
this.logger = logger;
|
||||
this.styleRepository = styleRepository;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="StyleController"/> class.
|
||||
/// Initialise une nouvelle instance de la classe <see cref="StyleController"/>.
|
||||
/// </summary>
|
||||
/// <param name="logger">Service de journalisation injecté.</param>
|
||||
/// <param name="styles">Repository des styles injecté.</param>
|
||||
public StyleController(
|
||||
ILogger<StyleController> logger,
|
||||
IStyleRepository styleRepository)
|
||||
this.logger.LogInformation("Initialisation du controleur StyleController.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Affiche la liste des styles dans la vue Index.
|
||||
/// </summary>
|
||||
/// <returns>La vue Index avec la liste des styles.</returns>
|
||||
public IActionResult Index()
|
||||
{
|
||||
IEnumerable<Style> listeStyles = this.styleRepository.FindAll().Take(10);
|
||||
|
||||
return this.View(listeStyles);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Affiche la vue de creation d'un nouveau style.
|
||||
/// </summary>
|
||||
/// <returns>La vue Create pour ajouter un nouveau style.</returns>
|
||||
public IActionResult Create()
|
||||
{
|
||||
var model = new StyleCreateViewModel
|
||||
{
|
||||
this.logger = logger;
|
||||
Libelle = string.Empty,
|
||||
};
|
||||
|
||||
this.logger.LogInformation("Initialisation du contrôleur StyleController.");
|
||||
return this.View(model);
|
||||
}
|
||||
|
||||
this.styleRepository = styleRepository;
|
||||
/// <summary>
|
||||
/// Cree un nouveau style.
|
||||
/// </summary>
|
||||
/// <param name="model">Nouveau style.</param>
|
||||
/// <returns>IActionResult.</returns>
|
||||
[HttpPost]
|
||||
public IActionResult Create(StyleCreateViewModel model)
|
||||
{
|
||||
if (!this.ModelState.IsValid)
|
||||
{
|
||||
return this.View(model);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Affiche la liste des styles dans la vue Index.
|
||||
/// </summary>
|
||||
/// <returns>La vue Index avec le ViewModel contenant la liste des styles.</returns>
|
||||
public IActionResult Index()
|
||||
var style = new Style
|
||||
{
|
||||
var listeStyles = this.styleRepository.FindAll().Take(10);
|
||||
Libelle = model.Libelle,
|
||||
};
|
||||
|
||||
return this.View(listeStyles);
|
||||
}
|
||||
this.styleRepository.Add(style);
|
||||
|
||||
/// <summary>
|
||||
/// Affiche la vue de création d'un nouveau style.
|
||||
/// </summary>
|
||||
/// <returns>La vue Create pour ajouter un nouveau style.</returns>
|
||||
public IActionResult Create()
|
||||
return this.RedirectToAction("Index");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Affiche la vue de confirmation de suppression d'un style.
|
||||
/// </summary>
|
||||
/// <param name="id">L'identifiant du style a supprimer.</param>
|
||||
/// <returns>La vue de confirmation ou une redirection vers l'index si le style n'existe pas.</returns>
|
||||
public IActionResult Delete(int id)
|
||||
{
|
||||
var style = this.styleRepository.Find(id);
|
||||
|
||||
if (style == null || style.IdStyle == 0)
|
||||
{
|
||||
return this.View();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Affiche la vue de confirmation de suppression d'un style, en récupérant les détails du style à supprimer à partir de l'identifiant fourni.
|
||||
/// </summary>
|
||||
/// <param name="id">L'identifiant du style à supprimer.</param>
|
||||
/// <returns>La vue de confirmation de suppression avec le ViewModel contenant les détails du style à supprimer, ou une redirection vers l'index si le style n'existe pas.</returns>
|
||||
public IActionResult Delete(int id)
|
||||
{
|
||||
var style = this.styleRepository.Find(id);
|
||||
|
||||
var vm = new StyleDeleteViewModel
|
||||
{
|
||||
IdStyle = style.IdStyle,
|
||||
Libelle = style.Libelle,
|
||||
};
|
||||
|
||||
return this.View(vm);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Méthode POST pour supprimer un style.
|
||||
/// </summary>
|
||||
/// <param name="model">Le style à supprimer.</param>
|
||||
/// <returns>Redirige vers la page d'index d'admin style.</returns>
|
||||
[HttpPost]
|
||||
public IActionResult Delete(StyleEditViewModel model)
|
||||
{
|
||||
var style = this.styleRepository.Find(model.IdStyle);
|
||||
|
||||
if (style != null)
|
||||
{
|
||||
this.styleRepository.Delete(style);
|
||||
}
|
||||
|
||||
return this.RedirectToAction("Index");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Affiche la vue d'édition d'un style existant, en récupérant les détails du style à éditer à partir de l'identifiant fourni.
|
||||
/// </summary>
|
||||
/// <param name="id">L'identifiant du style à éditer.</param>
|
||||
/// <returns>La vue d'édition avec le ViewModel contenant les détails du style à éditer, ou une redirection vers l'index si le style n'existe pas.</returns>
|
||||
[HttpGet]
|
||||
public IActionResult Edit(int id)
|
||||
var model = new StyleDeleteViewModel
|
||||
{
|
||||
var style = this.styleRepository.Find(id);
|
||||
IdStyle = style.IdStyle,
|
||||
Libelle = style.Libelle,
|
||||
};
|
||||
|
||||
var model = new StyleEditViewModel
|
||||
{
|
||||
IdStyle = style.IdStyle,
|
||||
Libelle = style.Libelle,
|
||||
};
|
||||
return this.View(model);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Methode POST pour supprimer un style.
|
||||
/// </summary>
|
||||
/// <param name="model">Le style a supprimer.</param>
|
||||
/// <returns>Redirige vers la page d'index d'admin style.</returns>
|
||||
[HttpPost]
|
||||
public IActionResult Delete(StyleDeleteViewModel model)
|
||||
{
|
||||
var style = this.styleRepository.Find(model.IdStyle);
|
||||
|
||||
if (style != null)
|
||||
{
|
||||
this.styleRepository.Delete(style);
|
||||
}
|
||||
|
||||
return this.RedirectToAction("Index");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Affiche la vue d'edition d'un style existant.
|
||||
/// </summary>
|
||||
/// <param name="id">L'identifiant du style a editer.</param>
|
||||
/// <returns>La vue d'edition ou une redirection vers l'index si le style n'existe pas.</returns>
|
||||
[HttpGet]
|
||||
public IActionResult Edit(int id)
|
||||
{
|
||||
var style = this.styleRepository.Find(id);
|
||||
|
||||
if (style == null || style.IdStyle == 0)
|
||||
{
|
||||
return this.RedirectToAction("Index");
|
||||
}
|
||||
|
||||
var model = new StyleEditViewModel
|
||||
{
|
||||
IdStyle = style.IdStyle,
|
||||
Libelle = style.Libelle,
|
||||
};
|
||||
|
||||
return this.View(model);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Met a jour un style existant.
|
||||
/// </summary>
|
||||
/// <param name="model">Donnees du style a modifier.</param>
|
||||
/// <returns>Redirige vers la page d'index d'admin style.</returns>
|
||||
[HttpPost]
|
||||
public IActionResult Edit(StyleEditViewModel model)
|
||||
{
|
||||
if (!this.ModelState.IsValid)
|
||||
{
|
||||
return this.View(model);
|
||||
}
|
||||
|
||||
var style = this.styleRepository.Find(model.IdStyle);
|
||||
if (style == null)
|
||||
{
|
||||
return this.RedirectToAction("Index");
|
||||
}
|
||||
|
||||
style.Libelle = model.Libelle;
|
||||
this.styleRepository.Update(style);
|
||||
|
||||
return this.RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
namespace Webzine.WebApplication.Areas.Administration.Controllers;
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
|
||||
using Webzine.Entity;
|
||||
using Webzine.Repository.Contracts;
|
||||
using Webzine.WebApplication.Areas.Administration.ViewModels.Titre;
|
||||
|
||||
namespace Webzine.WebApplication.Areas.Administration.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// Contrôleur pour la gestion des titres en administration. Ce contrôleur gère les opérations de création, modification, suppression et affichage des titres dans l'interface d'administration du webzine. Chaque action du contrôleur prépare un ViewModel spécifique pour la vue correspondante, permettant ainsi une séparation claire entre la logique métier et la présentation des données.
|
||||
/// </summary>
|
||||
@@ -129,6 +130,11 @@ public class TitreController : Controller
|
||||
{
|
||||
var titre = this.titreRepository.Find(id);
|
||||
|
||||
if (titre == null)
|
||||
{
|
||||
return this.RedirectToAction("Index");
|
||||
}
|
||||
|
||||
var model = new AdminTitreDelete
|
||||
{
|
||||
Id = titre.IdTitre,
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace Webzine.WebApplication.Areas.Administration.ViewModels.Artiste
|
||||
{
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
/// <summary>
|
||||
/// ViewModel qui sert à la création d'un artiste.
|
||||
/// </summary>
|
||||
public class ArtisteCreateViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Nom de l'artiste.
|
||||
/// </summary>
|
||||
[Required]
|
||||
public string Nom { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Biographie de l'artiste.
|
||||
/// </summary>
|
||||
public string Biographie { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace Webzine.WebApplication.Areas.Administration.ViewModels.Artiste
|
||||
{
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
/// <summary>
|
||||
/// Permet d'éditer un Artiste.
|
||||
/// </summary>
|
||||
public class ArtisteEditViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Id de l'artiste.
|
||||
/// </summary>
|
||||
[Required]
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Nom de l'artiste.
|
||||
/// </summary>
|
||||
[Required]
|
||||
public string Nom { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Biographie de l'artiste.
|
||||
/// </summary>
|
||||
public string Biographie { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
// <copyright file="CommentaireViewModel.cs" company="PlaceholderCompany">
|
||||
// Copyright (c) PlaceholderCompany. All rights reserved.
|
||||
// <copyright file="CommentaireViewModel.cs" company="Equipe 1 - BOBIN, MASI, NODON, VETU">
|
||||
// Copyright (c) Equipe 1 - BOBIN, MASI, NODON, VETU. All rights reserved.
|
||||
// </copyright>
|
||||
|
||||
namespace Webzine.WebApplication.Areas.Administration.ViewModels.Commentaire
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
// <copyright file="StyleCreateViewModel.cs" company="PlaceholderCompany">
|
||||
// Copyright (c) PlaceholderCompany. All rights reserved.
|
||||
// <copyright file="StyleCreateViewModel.cs" company="Equipe 1 - BOBIN, MASI, NODON, VETU">
|
||||
// Copyright (c) Equipe 1 - BOBIN, MASI, NODON, VETU. All rights reserved.
|
||||
// </copyright>
|
||||
|
||||
namespace Webzine.WebApplication.Areas.Administration.ViewModels.Style
|
||||
{
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
/// <summary>
|
||||
/// ViewModel pour la création d'un style en administration.
|
||||
/// </summary>
|
||||
@@ -12,6 +14,7 @@ namespace Webzine.WebApplication.Areas.Administration.ViewModels.Style
|
||||
/// <summary>
|
||||
/// Obtient ou définit le libellé du style.
|
||||
/// </summary>
|
||||
[Required]
|
||||
public string Libelle { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
// <copyright file="StyleDeleteViewModel.cs" company="PlaceholderCompany">
|
||||
// Copyright (c) PlaceholderCompany. All rights reserved.
|
||||
// <copyright file="StyleDeleteViewModel.cs" company="Equipe 1 - BOBIN, MASI, NODON, VETU">
|
||||
// Copyright (c) Equipe 1 - BOBIN, MASI, NODON, VETU. All rights reserved.
|
||||
// </copyright>
|
||||
|
||||
namespace Webzine.WebApplication.Areas.Administration.ViewModels.Style
|
||||
|
||||
@@ -1,22 +1,25 @@
|
||||
// <copyright file="StyleEditViewModel.cs" company="PlaceholderCompany">
|
||||
// Copyright (c) PlaceholderCompany. All rights reserved.
|
||||
// <copyright file="StyleEditViewModel.cs" company="Equipe 1 - BOBIN, MASI, NODON, VETU">
|
||||
// Copyright (c) Equipe 1 - BOBIN, MASI, NODON, VETU. All rights reserved.
|
||||
// </copyright>
|
||||
|
||||
namespace Webzine.WebApplication.Areas.Administration.ViewModels.Style
|
||||
{
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
/// <summary>
|
||||
/// ViewModel pour la modification d'un style en administration.
|
||||
/// </summary>
|
||||
public class StyleEditViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Obtient ou définit le libellé du style.
|
||||
/// Obtient ou definit l'identifiant du style.
|
||||
/// </summary>
|
||||
public int IdStyle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Obtient ou définit le libellé du style.
|
||||
/// Obtient ou definit le libelle du style.
|
||||
/// </summary>
|
||||
[Required]
|
||||
public string Libelle { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
|
||||
namespace Webzine.WebApplication.Areas.Administration.ViewModels.Titre;
|
||||
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
|
||||
/// <summary>
|
||||
/// ViewModel pour la création et la modification d'un titre dans l'administration.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,11 +1,41 @@
|
||||
@model Webzine.WebApplication.Areas.Administration.ViewModels.Artiste.AdminArtisteForm
|
||||
@model Webzine.WebApplication.Areas.Administration.ViewModels.Artiste.ArtisteCreateViewModel
|
||||
|
||||
<h1>Créer un artiste</h1>
|
||||
|
||||
<hr />
|
||||
|
||||
<form asp-action="Create" method="post">
|
||||
<div class="container">
|
||||
<!-- ARTISTE -->
|
||||
<div class="row mb-3">
|
||||
<label class="col-md-3 col-form-label">Nom de l'artiste<span class="text-danger">*</span></label>
|
||||
<div class="col-md-9">
|
||||
<input asp-for="Nom" class="form-control" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<partial name="_Form" />
|
||||
<!-- BIOGRAPHIE -->
|
||||
<div class="row mb-3">
|
||||
<label class="col-md-3 col-form-label">Biographie</label>
|
||||
<div class="col-md-9">
|
||||
<textarea asp-for="Biographie" class="form-control" rows="5"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- BOUTONS -->
|
||||
<div class="row mt-4">
|
||||
<div class="col-md-9 offset-md-3">
|
||||
<button type="submit" class="btn btn-primary me-2">
|
||||
Sauvegarder
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
<a asp-action="Index"
|
||||
class="btn text-primary">
|
||||
Retour à l'administration des artistes
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
@@ -1,4 +1,4 @@
|
||||
@model Webzine.WebApplication.Areas.Administration.ViewModels.Artiste.AdminArtisteForm
|
||||
@model Webzine.Entity.Artiste
|
||||
|
||||
<h1>Editer un artiste</h1>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<form asp-action="Edit" method="post">
|
||||
|
||||
<input type="hidden" asp-for="Id"/>
|
||||
<input type="hidden" asp-for="IdArtiste"/>
|
||||
|
||||
<partial name="_Form" />
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@model Webzine.WebApplication.Areas.Administration.ViewModels.Artiste.AdminArtisteForm
|
||||
@model Webzine.Entity.Artiste
|
||||
|
||||
<div class="container">
|
||||
<!-- ARTISTE -->
|
||||
@@ -17,8 +17,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- BOUTONS -->
|
||||
<div class="row mt-4">
|
||||
<div class="col-md-9 offset-md-3">
|
||||
|
||||
13
Webzine.WebApplication/Configuration/AppEnums.cs
Normal file
13
Webzine.WebApplication/Configuration/AppEnums.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace Webzine.WebApplication.Configuration;
|
||||
|
||||
public enum SeederType
|
||||
{
|
||||
Local,
|
||||
Spotify,
|
||||
}
|
||||
|
||||
public enum RepositoryType
|
||||
{
|
||||
Local,
|
||||
Db,
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Webzine.WebApplication.Controllers;
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
public class ApiController : ControllerBase
|
||||
{
|
||||
private readonly ILogger<ApiController> logger;
|
||||
@@ -29,7 +29,7 @@ public class ApiController : ControllerBase
|
||||
return this.Ok(new
|
||||
{
|
||||
nom = "webzine",
|
||||
version = "2.0",
|
||||
version = "3.0",
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
// <copyright file="RechercheController.cs" company="PlaceholderCompany">
|
||||
// Copyright (c) PlaceholderCompany. All rights reserved.
|
||||
// <copyright file="RechercheController.cs" company="Equipe 1 - BOBIN, MASI, NODON, VETU">
|
||||
// Copyright (c) Equipe 1 - BOBIN, MASI, NODON, VETU. All rights reserved.
|
||||
// </copyright>
|
||||
|
||||
namespace Webzine.WebApplication.Controllers
|
||||
@@ -8,53 +8,40 @@ namespace Webzine.WebApplication.Controllers
|
||||
|
||||
using Webzine.Repository.Contracts;
|
||||
using Webzine.WebApplication.ViewModels.Recherche;
|
||||
using Webzine.WebApplication.ViewModels.Titre;
|
||||
|
||||
public class RechercheController : Controller
|
||||
{
|
||||
private readonly ILogger<RechercheController> logger;
|
||||
private readonly ITitreRepository titreRepository;
|
||||
private readonly IArtisteRepository artisteRepository;
|
||||
|
||||
public RechercheController(ILogger<RechercheController> logger, ITitreRepository titreRepository)
|
||||
public RechercheController(
|
||||
ILogger<RechercheController> logger,
|
||||
ITitreRepository titreRepository,
|
||||
IArtisteRepository artisteRepository)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.titreRepository = titreRepository;
|
||||
this.artisteRepository = artisteRepository;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
/// <summary>
|
||||
/// Affichage de la page Recherche depuis le header de l'app.
|
||||
/// </summary>
|
||||
/// <param name="mot">Nom d'artiste ou de titre.</param>
|
||||
/// <returns>Page de recherche avec les r<>sultats.</returns>
|
||||
public IActionResult Index(string mot)
|
||||
{
|
||||
// Logger la recherche.
|
||||
this.logger.LogInformation("Recherche artistes/titres pour le mot : {Mot}.", mot);
|
||||
|
||||
var titres = this.titreRepository.Search(mot)
|
||||
.Concat(this.titreRepository.SearchByStyle(mot))
|
||||
.DistinctBy(t => t.IdTitre)
|
||||
.OrderBy(t => t.Libelle)
|
||||
.Select(t => new TitreStyleItem
|
||||
{
|
||||
IdTitre = t.IdTitre,
|
||||
Libelle = t.Libelle,
|
||||
ArtisteNom = t.Artiste?.Nom,
|
||||
UrlJaquette = t.UrlJaquette,
|
||||
Duree = t.Duree,
|
||||
})
|
||||
.ToList();
|
||||
// Recherche des titres.
|
||||
var titres = this.titreRepository.Search(mot);
|
||||
|
||||
var artistes = this.titreRepository.FindAll()
|
||||
.Select(t => t.Artiste)
|
||||
.Where(a => a != null
|
||||
&& !string.IsNullOrWhiteSpace(a.Nom)
|
||||
&& !string.IsNullOrWhiteSpace(mot)
|
||||
&& a.Nom.Contains(mot, StringComparison.OrdinalIgnoreCase))
|
||||
.DistinctBy(a => a!.IdArtiste)
|
||||
.OrderBy(a => a!.Nom)
|
||||
.Select(a => new RechercheArtisteItem
|
||||
{
|
||||
Nom = a!.Nom,
|
||||
NombreDeTitres = a.Titres?.Count ?? 0,
|
||||
})
|
||||
.ToList();
|
||||
// Recherche des artistes.
|
||||
var artistes = this.artisteRepository.Search(mot);
|
||||
|
||||
// Param<61>tres a retourner <20> la vue.
|
||||
var vm = new RechercheIndexViewModel
|
||||
{
|
||||
Mot = mot,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// <copyright file="TitreController.cs" company="PlaceholderCompany">
|
||||
// Copyright (c) PlaceholderCompany. All rights reserved.
|
||||
// <copyright file="TitreController.cs" company="Equipe 1 - BOBIN, MASI, NODON, VETU">
|
||||
// Copyright (c) Equipe 1 - BOBIN, MASI, NODON, VETU. All rights reserved.
|
||||
// </copyright>
|
||||
|
||||
namespace Webzine.WebApplication.Controllers
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS base
|
||||
USER $APP_UID
|
||||
WORKDIR /app
|
||||
EXPOSE 8080
|
||||
EXPOSE 8081
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
WORKDIR /src
|
||||
COPY ["Webzine.WebApplication/Webzine.WebApplication.csproj", "Webzine.WebApplication/"]
|
||||
RUN dotnet restore "Webzine.WebApplication/Webzine.WebApplication.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/Webzine.WebApplication"
|
||||
RUN dotnet build "./Webzine.WebApplication.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||
|
||||
FROM build AS publish
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
RUN dotnet publish "./Webzine.WebApplication.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "Webzine.WebApplication.dll"]
|
||||
@@ -1,3 +1,6 @@
|
||||
// L'erreur SA1200 (ordre des using directives) est desactivée pour Program.cs
|
||||
#pragma warning disable SA1200
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
using NLog;
|
||||
@@ -8,6 +11,7 @@ using Webzine.Entity;
|
||||
using Webzine.Entity.Fixtures;
|
||||
using Webzine.Repository;
|
||||
using Webzine.Repository.Contracts;
|
||||
using Webzine.WebApplication.Configuration;
|
||||
using Webzine.WebApplication.Extensions;
|
||||
|
||||
// Initiation du logger NLog pour la classe courante afin de pouvoir l'utiliser pour logger des messages d'information, d'erreur, etc avant la construction de l'application.
|
||||
@@ -32,19 +36,20 @@ try
|
||||
builder.Host.UseNLog();
|
||||
|
||||
// En fonction de la configuration, utilise soit les repositories basés sur une base de données, soit les repositories basés sur des listes locales.
|
||||
bool useDatabase = builder.Configuration.GetValue<bool>("UseDatabase");
|
||||
bool isSQLite = builder.Configuration.GetValue<bool>("IsSQLite");
|
||||
if (useDatabase)
|
||||
var repositoryType = builder.Configuration.GetValue<RepositoryType>("Repository");
|
||||
var seederType = builder.Configuration.GetValue<SeederType>("Seeder");
|
||||
var shouldSeed = args.Contains("--seed");
|
||||
if (repositoryType == RepositoryType.Db)
|
||||
{
|
||||
if (isSQLite)
|
||||
if (builder.Environment.IsProduction())
|
||||
{
|
||||
builder.Services.AddDbContext<WebzineDbContext>(options =>
|
||||
options.UseSqlite(builder.Configuration.GetConnectionString("SqliteConnection")));
|
||||
options.UseNpgsql(builder.Configuration.GetConnectionString("PostGreSQLConnection")));
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.Services.AddDbContext<WebzineDbContext>(options =>
|
||||
options.UseNpgsql(builder.Configuration.GetConnectionString("PostGreSQLConnection")));
|
||||
options.UseSqlite(builder.Configuration.GetConnectionString("SqliteConnection")));
|
||||
}
|
||||
|
||||
builder.Services.AddScoped<DbEntityRepository>();
|
||||
@@ -68,29 +73,25 @@ try
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
if (useDatabase)
|
||||
if (repositoryType == RepositoryType.Db)
|
||||
{
|
||||
if (isSQLite)
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
using (var scope = app.Services.CreateScope())
|
||||
var db = scope.ServiceProvider.GetRequiredService<WebzineDbContext>();
|
||||
if (shouldSeed)
|
||||
{
|
||||
var db = scope.ServiceProvider.GetRequiredService<WebzineDbContext>();
|
||||
db.Database.EnsureDeleted();
|
||||
db.Database.EnsureCreated();
|
||||
var repo = scope.ServiceProvider.GetRequiredService<DbEntityRepository>();
|
||||
repo.SeedBaseDeDonnees();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
// TODO : A modifier pour ne pas supprimer la base de donnée en prod
|
||||
var db = scope.ServiceProvider.GetRequiredService<WebzineDbContext>();
|
||||
db.Database.EnsureDeleted();
|
||||
db.Database.EnsureCreated();
|
||||
var repo = scope.ServiceProvider.GetRequiredService<DbEntityRepository>();
|
||||
repo.SeedBaseDeDonnees();
|
||||
|
||||
if (seederType == SeederType.Local)
|
||||
{
|
||||
repo.SeedBaseDeDonnees();
|
||||
}
|
||||
else if (seederType == SeederType.Spotify)
|
||||
{
|
||||
// Seed à l'aide de l'API Spotify.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,26 @@
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"http-seed": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:5038",
|
||||
"commandLineArgs": "--seed",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https-seed": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "https://localhost:7095;http://localhost:5038",
|
||||
"commandLineArgs": "--seed",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
namespace Webzine.WebApplication.ViewModels.Recherche;
|
||||
|
||||
/// <summary>
|
||||
/// ViewModel pour afficher un artiste dans les resultats de recherche.
|
||||
/// </summary>
|
||||
public class RechercheArtisteItem
|
||||
{
|
||||
/// <summary>
|
||||
/// Nom de l'artiste.
|
||||
/// </summary>
|
||||
public string? Nom { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Nombre de titres associes a l'artiste.
|
||||
/// </summary>
|
||||
public int NombreDeTitres { get; set; }
|
||||
}
|
||||
@@ -1,24 +1,25 @@
|
||||
using Webzine.WebApplication.ViewModels.Titre;
|
||||
|
||||
namespace Webzine.WebApplication.ViewModels.Recherche;
|
||||
|
||||
/// <summary>
|
||||
/// ViewModel pour afficher les resultats de recherche d'artistes et de titres.
|
||||
/// </summary>
|
||||
public class RechercheIndexViewModel
|
||||
namespace Webzine.WebApplication.ViewModels.Recherche
|
||||
{
|
||||
/// <summary>
|
||||
/// Mot saisi dans le formulaire.
|
||||
/// </summary>
|
||||
public string? Mot { get; set; }
|
||||
using Webzine.Entity;
|
||||
|
||||
/// <summary>
|
||||
/// Artistes trouves.
|
||||
/// ViewModel pour afficher les resultats de recherche d'artistes et de titres.
|
||||
/// </summary>
|
||||
public List<RechercheArtisteItem> Artistes { get; set; } = new ();
|
||||
public class RechercheIndexViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Mot saisi dans le formulaire.
|
||||
/// </summary>
|
||||
public string? Mot { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Titres trouves.
|
||||
/// </summary>
|
||||
public List<TitreStyleItem> Titres { get; set; } = new ();
|
||||
/// <summary>
|
||||
/// Artistes trouves.
|
||||
/// </summary>
|
||||
public IEnumerable<Artiste> Artistes { get; set; } = new List<Artiste>();
|
||||
|
||||
/// <summary>
|
||||
/// Titres trouves.
|
||||
/// </summary>
|
||||
public IEnumerable<Titre> Titres { get; set; } = new List<Titre>();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Webzine.WebApplication.ViewModels.Titre;
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
/// <summary>
|
||||
/// Classe représentant un commentaire sur un titre, utilisée pour la validation des données lors de la soumission d'un commentaire.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Webzine.Entity;
|
||||
|
||||
namespace Webzine.WebApplication.ViewModels.Titre;
|
||||
|
||||
using Webzine.Entity;
|
||||
|
||||
/// <summary>
|
||||
/// Contient les détails d'un titre, ainsi que les commentaires associés.
|
||||
/// </summary>
|
||||
|
||||
@@ -10,74 +10,65 @@
|
||||
<h1 class="mb-4">Resultats pour "@Model.Mot"</h1>
|
||||
|
||||
<hr />
|
||||
<h2 class="h4 mt-4">Artistes</h2>
|
||||
|
||||
@if (string.IsNullOrWhiteSpace(Model.Mot))
|
||||
@if (!Model.Artistes.Any())
|
||||
{
|
||||
<div class="alert alert-info">
|
||||
Saisissez un mot-cle pour lancer une recherche.
|
||||
<p>Aucun artiste n'a été trouvé.</p>
|
||||
</div>
|
||||
}
|
||||
else if (!Model.Artistes.Any() && !Model.Titres.Any())
|
||||
|
||||
@foreach (var artiste in Model.Artistes)
|
||||
{
|
||||
<div class="my-3">
|
||||
<a asp-controller="Artiste"
|
||||
asp-action="Index"
|
||||
asp-route-nom="@artiste.Nom">
|
||||
@artiste.Nom
|
||||
</a>
|
||||
<span class="text-muted">(@artiste.Titres.Count titre(s))</span>
|
||||
</div>
|
||||
}
|
||||
<h2 class="h4 mt-4">Titres</h2>
|
||||
|
||||
@if (!Model.Titres.Any())
|
||||
{
|
||||
<div class="alert alert-info">
|
||||
Aucun artiste ni titre ne correspond a votre recherche.
|
||||
<p>Aucun titre n'a été trouvé.</p>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
@if (Model.Artistes.Any())
|
||||
{
|
||||
<h2 class="h4 mt-4">Artistes</h2>
|
||||
|
||||
@foreach (var artiste in Model.Artistes)
|
||||
{
|
||||
<div class="my-3">
|
||||
@foreach (var titre in Model.Titres)
|
||||
{
|
||||
<div class="d-flex align-items-start my-3">
|
||||
<a asp-controller="Titre"
|
||||
asp-action="Index"
|
||||
asp-route-id="@titre.IdTitre"
|
||||
class="me-3 text-black">
|
||||
<img src="@titre.UrlJaquette" alt="@titre.Libelle" width="70" height="70" class="object-fit-cover" loading="lazy" />
|
||||
</a>
|
||||
|
||||
<div class="justify-content-center d-flex flex-column">
|
||||
<div>
|
||||
<a asp-controller="Artiste"
|
||||
asp-action="Index"
|
||||
asp-route-nom="@artiste.Nom">
|
||||
@artiste.Nom
|
||||
asp-route-nom="@titre.Artiste.Nom">
|
||||
@titre.Artiste.Nom
|
||||
</a>
|
||||
<span class="text-muted">(@artiste.NombreDeTitres titre(s))</span>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
@if (Model.Titres.Any())
|
||||
{
|
||||
<h2 class="h4 mt-4">Titres</h2>
|
||||
|
||||
@foreach (var titre in Model.Titres)
|
||||
{
|
||||
<div class="d-flex align-items-start my-3">
|
||||
-
|
||||
<a asp-controller="Titre"
|
||||
asp-action="Index"
|
||||
asp-route-id="@titre.IdTitre"
|
||||
class="me-3 text-black">
|
||||
<img src="@titre.UrlJaquette" alt="@titre.Libelle" width="70" height="70" class="object-fit-cover" loading="lazy"/>
|
||||
asp-route-id="@titre.IdTitre">
|
||||
@titre.Libelle
|
||||
</a>
|
||||
|
||||
<div class="justify-content-center d-flex flex-column">
|
||||
<div>
|
||||
<a asp-controller="Artiste"
|
||||
asp-action="Index"
|
||||
asp-route-nom="@titre.ArtisteNom">
|
||||
@titre.ArtisteNom
|
||||
</a>
|
||||
-
|
||||
<a asp-controller="Titre"
|
||||
asp-action="Index"
|
||||
asp-route-id="@titre.IdTitre">
|
||||
@titre.Libelle
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
Duree : @TimeSpan.FromSeconds(titre.Duree).ToString(@"mm\:ss")
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
<div>
|
||||
Duree : @TimeSpan.FromSeconds(titre.Duree).ToString(@"mm\:ss")
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -61,7 +61,7 @@
|
||||
</ul>
|
||||
|
||||
<!-- Barre de recherche -->
|
||||
<form class="d-flex" asp-controller="Recherche" asp-action="Index" method="post">
|
||||
<form class="d-flex" asp-area="" asp-controller="Recherche" asp-action="Index" method="get">
|
||||
<div class="input-group">
|
||||
<div class="form-outline">
|
||||
<input class="form-control me-2"
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
"Seeder": "Local",
|
||||
"Repository": "Db"
|
||||
}
|
||||
|
||||
4
Webzine.WebApplication/appsettings.Production.json
Normal file
4
Webzine.WebApplication/appsettings.Production.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"Seeder": "Local",
|
||||
"Repository": "Db"
|
||||
}
|
||||
@@ -9,11 +9,9 @@
|
||||
"NombreDerniereChronique": 3,
|
||||
"NombreDeTopTitres": 3
|
||||
},
|
||||
"UseDatabase": true,
|
||||
"IsSQLite": true,
|
||||
"ConnectionStrings": {
|
||||
"SqliteConnection": "Data Source=Data/webzine.sqlite",
|
||||
"PostGreSQLConnection" : "Host=localhost;Port=5432;Username=admin;Password=admin123;Database=webzine_db"
|
||||
"PostGreSQLConnection": "Host=localhost;Port=5432;Username=admin;Password=admin123;Database=webzine_db"
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user