This commit is contained in:
@@ -18,5 +18,6 @@ namespace Webzine.Entity
|
||||
[Display(Name = "Libellé")]
|
||||
public string Libelle { get; set; }
|
||||
|
||||
public List<Titre> Titres { get; set; } = new List<Titre>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,6 +62,6 @@ namespace Webzine.Entity
|
||||
public string Album { get; set; }
|
||||
|
||||
public List<Commentaire> Commentaires { get; set; }
|
||||
|
||||
public List<Style> Styles { get; set; } = new List<Style>();
|
||||
}
|
||||
}
|
||||
|
||||
163
Webzine.WebApplication/Controllers/Admin/Titre2Controller.cs
Normal file
163
Webzine.WebApplication/Controllers/Admin/Titre2Controller.cs
Normal file
@@ -0,0 +1,163 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Webzine.Entity;
|
||||
using Webzine.Entity.Fixtures;
|
||||
using Webzine.WebApplication.ViewModels.Admin.Titre;
|
||||
|
||||
namespace Webzine.WebApplication.Controllers.Admin;
|
||||
|
||||
public class Titre2Controller : Controller
|
||||
{
|
||||
private readonly ILogger<Titre2Controller> _logger;
|
||||
private readonly List<Titre> _titres;
|
||||
private readonly List<Style> _styles;
|
||||
private readonly List<Artiste> _artistes;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Initialise une nouvelle instance du <see cref="Titre2Controller"/>.
|
||||
/// Les données sont générées dynamiquement via <see cref="DataFactory"/>.
|
||||
/// </summary>
|
||||
/// <param name="logger">Service de journalisation injecté.</param>
|
||||
public Titre2Controller(ILogger<Titre2Controller> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
|
||||
_logger.LogInformation("Initialisation du contrôleur TitreController.");
|
||||
|
||||
var factory = new DataFactory();
|
||||
|
||||
_artistes = factory.GenerateArtists(10);
|
||||
_styles = factory.GenerateStyles(10);
|
||||
_titres = factory.GenerateTitres(30, _artistes, _styles);
|
||||
|
||||
factory.GenerateCommentaires(50, _titres);
|
||||
|
||||
_logger.LogInformation("Données fictives générées avec succès.");
|
||||
}
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
var model = _titres.Select(t => new AdminTitreList
|
||||
{
|
||||
Id = t.IdTitre,
|
||||
Artiste = t.Artiste?.Nom,
|
||||
Titre = t.Libelle,
|
||||
Duree = TimeSpan.FromSeconds(t.Duree).ToString(@"mm\:ss"),
|
||||
DateSortie = t.DateSortie,
|
||||
NbLectures = t.NbLectures,
|
||||
NbLikes = t.NbLikes,
|
||||
NbCommentaires = t.Commentaires?.Count ?? 0
|
||||
}).ToList();
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
public ActionResult Create()
|
||||
{
|
||||
var model = new AdminTitreForm
|
||||
{
|
||||
Artistes = _artistes.Select(a => new SelectListItem
|
||||
{
|
||||
Value = a.IdArtiste.ToString(),
|
||||
Text = a.Nom
|
||||
}).ToList(),
|
||||
|
||||
AllStyles = _styles.Select(s => new SelectListItem
|
||||
{
|
||||
Value = s.IdStyle.ToString(),
|
||||
Text = s.Libelle
|
||||
}).ToList()
|
||||
};
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public ActionResult Create(IFormCollection collection)
|
||||
{
|
||||
try
|
||||
{
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
catch
|
||||
{
|
||||
return View();
|
||||
}
|
||||
}
|
||||
|
||||
public ActionResult Edit(int id)
|
||||
{
|
||||
var titre = _titres.First(t => t.IdTitre == id);
|
||||
|
||||
var model = new AdminTitreForm
|
||||
{
|
||||
Id = titre.IdTitre,
|
||||
IdArtiste = titre.IdArtiste,
|
||||
Libelle = titre.Libelle,
|
||||
Album = titre.Album,
|
||||
Chronique = titre.Chronique,
|
||||
DateSortie = titre.DateSortie,
|
||||
Duree = titre.Duree,
|
||||
UrlJaquette = titre.UrlJaquette,
|
||||
UrlEcoute = titre.UrlEcoute,
|
||||
NbLectures = titre.NbLectures,
|
||||
NbLikes = titre.NbLikes,
|
||||
Styles = titre.Styles.Select(s => s.IdStyle).ToList(),
|
||||
|
||||
Artistes = _artistes.Select(a => new SelectListItem
|
||||
{
|
||||
Value = a.IdArtiste.ToString(),
|
||||
Text = a.Nom
|
||||
}).ToList(),
|
||||
|
||||
AllStyles = _styles.Select(s => new SelectListItem
|
||||
{
|
||||
Value = s.IdStyle.ToString(),
|
||||
Text = s.Libelle
|
||||
}).ToList()
|
||||
};
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public ActionResult Edit(int id, IFormCollection collection)
|
||||
{
|
||||
try
|
||||
{
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
catch
|
||||
{
|
||||
return View();
|
||||
}
|
||||
}
|
||||
|
||||
public ActionResult Delete(int id)
|
||||
{
|
||||
var titre = _titres.First(t => t.IdTitre == id);
|
||||
|
||||
var model = new AdminTitreDelete
|
||||
{
|
||||
Id = titre.IdTitre,
|
||||
Titre = titre.Libelle,
|
||||
Artiste = titre.Artiste?.Nom
|
||||
};
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public ActionResult Delete(AdminTitreDelete model)
|
||||
{
|
||||
var titre = _titres.First(t => t.IdTitre == model.Id);
|
||||
|
||||
_titres.Remove(titre);
|
||||
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
using NLog;
|
||||
using NLog.Web;
|
||||
using Webzine.Repository;
|
||||
using Webzine.Repository.Contracts;
|
||||
|
||||
// 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.
|
||||
var logger = LogManager.Setup().LoadConfigurationFromAppSettings().GetCurrentClassLogger();
|
||||
@@ -23,9 +21,6 @@ try
|
||||
builder.Logging.ClearProviders();
|
||||
builder.Host.UseNLog();
|
||||
|
||||
// Register LocalEntityRepository as a singleton
|
||||
builder.Services.AddSingleton<ILocalEntityRepository, LocalEntityRepository>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Active la possibilité de servir des fichiers statiques présents dans
|
||||
@@ -41,14 +36,6 @@ try
|
||||
name: "default",
|
||||
pattern: "{controller=Accueil}/{action=Index}/{id?}");
|
||||
|
||||
|
||||
// Permet de remplir les listes d'entités du repository avec des donn<6E>es de test.
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
var repository = scope.ServiceProvider.GetRequiredService<ILocalEntityRepository>();
|
||||
repository.Seed();
|
||||
}
|
||||
|
||||
app.Run();
|
||||
}
|
||||
catch (Exception exception)
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace Webzine.WebApplication.ViewModels.Admin.Titre;
|
||||
|
||||
public class AdminTitreDelete
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Titre { get; set; }
|
||||
|
||||
public string Artiste { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
|
||||
namespace Webzine.WebApplication.ViewModels.Admin.Titre;
|
||||
|
||||
public class AdminTitreForm
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public int IdArtiste { get; set; }
|
||||
|
||||
public string Libelle { get; set; }
|
||||
|
||||
public string Album { get; set; }
|
||||
|
||||
public string Chronique { get; set; }
|
||||
|
||||
public DateTime DateSortie { get; set; }
|
||||
|
||||
public int Duree { get; set; }
|
||||
|
||||
public string UrlJaquette { get; set; }
|
||||
|
||||
public string UrlEcoute { get; set; }
|
||||
|
||||
public int NbLectures { get; set; }
|
||||
|
||||
public int NbLikes { get; set; }
|
||||
|
||||
public List<int> Styles { get; set; } = new();
|
||||
|
||||
public List<SelectListItem> Artistes { get; set; }
|
||||
|
||||
public List<SelectListItem> AllStyles { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace Webzine.WebApplication.ViewModels.Admin.Titre
|
||||
{
|
||||
public class AdminTitreList
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Artiste { get; set; }
|
||||
|
||||
public string Titre { get; set; }
|
||||
|
||||
public string Duree { get; set; }
|
||||
|
||||
public DateTime DateSortie { get; set; }
|
||||
|
||||
public int NbLectures { get; set; }
|
||||
|
||||
public int NbLikes { get; set; }
|
||||
|
||||
public int NbCommentaires { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,9 @@
|
||||
<title>@ViewData["Title"] - Webzine</title>
|
||||
|
||||
@* Ajout de bootstrap *@
|
||||
<script src="./js/bootstrap.min.js" defer></script>
|
||||
<link rel="stylesheet" href="./css/bootstrap.min.css">
|
||||
<script src="/js/bootstrap.min.js" defer></script>
|
||||
<link rel="stylesheet" href="/css/app.css">
|
||||
<link rel="stylesheet" href="/css/bootstrap.min.css">
|
||||
|
||||
@* Ajout de font-awesome *@
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
|
||||
|
||||
11
Webzine.WebApplication/Views/Titre2/Create.cshtml
Normal file
11
Webzine.WebApplication/Views/Titre2/Create.cshtml
Normal file
@@ -0,0 +1,11 @@
|
||||
@model Webzine.WebApplication.ViewModels.Admin.Titre.AdminTitreForm
|
||||
|
||||
<h1>Créer un titre</h1>
|
||||
|
||||
<hr />
|
||||
|
||||
<form asp-action="Create" method="post">
|
||||
|
||||
<partial name="_Form"/>
|
||||
|
||||
</form>
|
||||
34
Webzine.WebApplication/Views/Titre2/Delete.cshtml
Normal file
34
Webzine.WebApplication/Views/Titre2/Delete.cshtml
Normal file
@@ -0,0 +1,34 @@
|
||||
@model Webzine.WebApplication.ViewModels.Admin.Titre.AdminTitreDelete
|
||||
|
||||
<div class="container mt-4">
|
||||
|
||||
<h1 class="mb-3">Supprimer un titre</h1>
|
||||
|
||||
<hr />
|
||||
|
||||
<p>
|
||||
Etes-vous sûr de vouloir supprimer le titre
|
||||
"@Model.Titre"
|
||||
de
|
||||
@Model.Artiste ?
|
||||
</p>
|
||||
|
||||
<form asp-action="Delete" method="post">
|
||||
|
||||
<input type="hidden" asp-for="Id"/>
|
||||
|
||||
<button type="submit" class="btn btn-danger">
|
||||
Supprimer
|
||||
</button>
|
||||
|
||||
</form>
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
|
||||
<a asp-action="Index">
|
||||
Retour à l'administration des titres
|
||||
</a>
|
||||
|
||||
</div>
|
||||
13
Webzine.WebApplication/Views/Titre2/Edit.cshtml
Normal file
13
Webzine.WebApplication/Views/Titre2/Edit.cshtml
Normal file
@@ -0,0 +1,13 @@
|
||||
@model Webzine.WebApplication.ViewModels.Admin.Titre.AdminTitreForm
|
||||
|
||||
<h1>Editer un titre</h1>
|
||||
|
||||
<hr />
|
||||
|
||||
<form asp-action="Edit" method="post">
|
||||
|
||||
<input type="hidden" asp-for="Id"/>
|
||||
|
||||
<partial name="_Form"/>
|
||||
|
||||
</form>
|
||||
74
Webzine.WebApplication/Views/Titre2/Index.cshtml
Normal file
74
Webzine.WebApplication/Views/Titre2/Index.cshtml
Normal file
@@ -0,0 +1,74 @@
|
||||
@model IEnumerable<Webzine.WebApplication.ViewModels.Admin.Titre.AdminTitreList>
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Titres";
|
||||
}
|
||||
|
||||
<div class="container mt-4">
|
||||
|
||||
<h1 class="mb-3">Titres</h1>
|
||||
<hr />
|
||||
|
||||
<a asp-action="" class="btn btn-primary mb-3">
|
||||
<i class="fa fa-plus"></i> Ajouter un nouvel titre
|
||||
</a>
|
||||
|
||||
<table class="table table-striped table-bordered align-middle">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>Artiste</th>
|
||||
<th>Titre</th>
|
||||
<th>Durée</th>
|
||||
<th>Date de sortie</th>
|
||||
<th class="text-center"><i class="fa fa-eye"></i></th>
|
||||
<th class="text-center"><i class="fa fa-thumbs-up"></i></th>
|
||||
<th class="text-center"><i class="fa fa-comments"></i></th>
|
||||
<th class="text-center action-column">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
<tr>
|
||||
<td>@item.Artiste</td>
|
||||
<td>@item.Titre</td>
|
||||
<td>@item.Duree</td>
|
||||
<td>@item.DateSortie.ToString("dd/MM/yyyy")</td>
|
||||
|
||||
<td class="text-center">@item.NbLectures</td>
|
||||
<td class="text-center">@item.NbLikes</td>
|
||||
<td class="text-center">@item.NbCommentaires</td>
|
||||
|
||||
<td class="text-center action-column">
|
||||
|
||||
<a asp-action="Edit" asp-route-id="@item.Id"
|
||||
class="btn btn-sm btn-outline-primary">
|
||||
<i class="fa fa-pen"></i>
|
||||
</a>
|
||||
|
||||
<a asp-action="Delete" asp-route-id="@item.Id"
|
||||
class="btn btn-sm btn-outline-danger">
|
||||
<i class="fa fa-trash"></i>
|
||||
</a>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
|
||||
<style>
|
||||
|
||||
.action-column{
|
||||
width:120px;
|
||||
white-space:nowrap;
|
||||
}
|
||||
|
||||
.action-column .btn{
|
||||
margin-right:4px;
|
||||
}
|
||||
|
||||
</style>
|
||||
135
Webzine.WebApplication/Views/Titre2/_Form.cshtml
Normal file
135
Webzine.WebApplication/Views/Titre2/_Form.cshtml
Normal file
@@ -0,0 +1,135 @@
|
||||
@model Webzine.WebApplication.ViewModels.Admin.Titre.AdminTitreForm
|
||||
|
||||
<div class="container">
|
||||
<!-- ARTISTE -->
|
||||
<div class="row mb-3 align-items-center">
|
||||
<label class="col-md-3 col-form-label">Nom de l'artiste<span class="text-danger">*</span></label>
|
||||
<div class="col-md-9">
|
||||
<select asp-for="IdArtiste"
|
||||
asp-items="Model.Artistes"
|
||||
class="form-select"></select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- TITRE -->
|
||||
<div class="row mb-3 align-items-center">
|
||||
<label class="col-md-3 col-form-label">Titre<span class="text-danger">*</span></label>
|
||||
<div class="col-md-9">
|
||||
<input asp-for="Libelle" class="form-control"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ALBUM -->
|
||||
<div class="row mb-3 align-items-center">
|
||||
<label class="col-md-3 col-form-label">Album<span class="text-danger">*</span></label>
|
||||
<div class="col-md-9">
|
||||
<input asp-for="Album" class="form-control"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- CHRONIQUE -->
|
||||
<div class="row mb-3">
|
||||
<label class="col-md-3 col-form-label">Chronique<span class="text-danger">*</span></label>
|
||||
<div class="col-md-9">
|
||||
<textarea asp-for="Chronique"
|
||||
class="form-control"
|
||||
rows="5"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- DATE + DUREE -->
|
||||
<div class="row mb-3 align-items-center">
|
||||
<label class="col-md-3 col-form-label">Date de sortie<span class="text-danger">*</span></label>
|
||||
<div class="col-md-3">
|
||||
<input type="text"
|
||||
class="form-control"
|
||||
name="DateSortie"
|
||||
pattern="\d{2}/\d{2}/\d{4}"
|
||||
value="@Model.DateSortie.ToString("d")"/>
|
||||
</div>
|
||||
|
||||
<label class="col-md-3 col-form-label">Durée en secondes<span class="text-danger">*</span></label>
|
||||
<div class="col-md-3">
|
||||
<div class="input-group">
|
||||
<input asp-for="Duree"
|
||||
class="form-control"
|
||||
type="number"
|
||||
min="0" />
|
||||
<span class="input-group-text text-muted">seconds</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- JAQUETTE -->
|
||||
<div class="row mb-3 align-items-center">
|
||||
<label class="col-md-3 col-form-label">Jaquette<span class="text-danger">*</span></label>
|
||||
<div class="col-md-9">
|
||||
<input asp-for="UrlJaquette"
|
||||
class="form-control"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- URL ECOUTE -->
|
||||
<div class="row mb-3 align-items-center">
|
||||
<label class="col-md-3 col-form-label">URL d'écoute</label>
|
||||
<div class="col-md-9">
|
||||
<input asp-for="UrlEcoute"
|
||||
class="form-control"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- STYLES -->
|
||||
<div class="row mb-4">
|
||||
<label class="col-md-3 col-form-label">Styles</label>
|
||||
<div class="col-md-9">
|
||||
<div class="row">
|
||||
@foreach (var style in Model.AllStyles)
|
||||
{
|
||||
<div class="col-md-4 form-check">
|
||||
<input class="form-check-input"
|
||||
type="checkbox"
|
||||
name="Styles"
|
||||
value="@style.Value"
|
||||
@(Model.Styles.Contains(int.Parse(style.Value)) ? "checked" : "") />
|
||||
|
||||
<label class="form-check-label">
|
||||
@style.Text
|
||||
</label>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- LECTURES / LIKES (AFFICHAGE UNIQUEMENT) -->
|
||||
<div class="row mb-4 align-items-center">
|
||||
<label class="col-md-3 col-form-label">Nb de lectures<span class="text-danger">*</span></label>
|
||||
<div class="col-md-3">
|
||||
@Model.NbLectures
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-4 align-items-center">
|
||||
<label class="col-md-3 col-form-label">Nb de likes<span class="text-danger">*</span></label>
|
||||
<div class="col-md-3">
|
||||
@Model.NbLikes
|
||||
</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 titres
|
||||
</a>
|
||||
</div>
|
||||
@@ -0,0 +1,3 @@
|
||||
a {
|
||||
text-decoration: none !important;
|
||||
}
|
||||
Reference in New Issue
Block a user