Merge pull request 'patch_dev' (#200) from patch_dev into dev
Reviewed-on: https://10.4.0.131/gitea/DI1-P4-E1/Webzine/pulls/200
This commit is contained in:
@@ -1,174 +1,175 @@
|
||||
namespace Webzine.WebApplication.Areas.Administration.Controllers;
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
using ViewModels.Styles;
|
||||
|
||||
using Webzine.Entity;
|
||||
using Webzine.Repository.Contracts;
|
||||
|
||||
/// <summary>
|
||||
/// Controleur pour la gestion des styles dans l'administration du webzine.
|
||||
/// </summary>
|
||||
[Area("Administration")]
|
||||
public class StyleController : Controller
|
||||
namespace Webzine.WebApplication.Areas.Administration.Controllers
|
||||
{
|
||||
private readonly ILogger<StyleController> logger;
|
||||
private readonly IStyleRepository styleRepository;
|
||||
private readonly IConfiguration configuration;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
using Webzine.Entity;
|
||||
using Webzine.Repository.Contracts;
|
||||
using Webzine.WebApplication.Areas.Administration.ViewModels.Style;
|
||||
using Webzine.WebApplication.Areas.Administration.ViewModels.Styles;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="StyleController"/> class.
|
||||
/// Controleur pour la gestion des styles dans l'administration du webzine.
|
||||
/// </summary>
|
||||
/// <param name="logger">Service de journalisation injecte.</param>
|
||||
/// <param name="styleRepository">Repository des styles injecte.</param>
|
||||
/// <param name="configuration">Service de configuration injecte pour acceder aux parametres de configuration.</param>
|
||||
public StyleController(
|
||||
ILogger<StyleController> logger,
|
||||
IStyleRepository styleRepository,
|
||||
IConfiguration configuration)
|
||||
[Area("Administration")]
|
||||
public class StyleController : Controller
|
||||
{
|
||||
this.logger = logger;
|
||||
this.styleRepository = styleRepository;
|
||||
this.configuration = configuration;
|
||||
private readonly ILogger<StyleController> logger;
|
||||
private readonly IStyleRepository styleRepository;
|
||||
private readonly IConfiguration configuration;
|
||||
|
||||
this.logger.LogInformation("Initialisation du controleur StyleController.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Affiche la liste des styles dans la vue Index.
|
||||
/// </summary>
|
||||
/// <param name="page">Le numero de page pour la pagination des styles (par defaut a 0).</param>
|
||||
/// <returns>La vue Index avec la liste des styles.</returns>
|
||||
public IActionResult Index(int page = 0)
|
||||
{
|
||||
int styles_par_page = this.configuration.GetValue<int>("Webzine:NombreDeLignesAdministration");
|
||||
IEnumerable<Style> listeStyles = this.styleRepository.FindStyles(page * styles_par_page, styles_par_page);
|
||||
|
||||
int totalStyles = this.styleRepository.Count();
|
||||
|
||||
var model = new StyleIndexViewModel
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="StyleController"/> class.
|
||||
/// </summary>
|
||||
/// <param name="logger">Service de journalisation injecte.</param>
|
||||
/// <param name="styleRepository">Repository des styles injecte.</param>
|
||||
/// <param name="configuration">Service de configuration injecte pour acceder aux parametres de configuration.</param>
|
||||
public StyleController(
|
||||
ILogger<StyleController> logger,
|
||||
IStyleRepository styleRepository,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
Styles = listeStyles,
|
||||
Page = page,
|
||||
TotalPages = (int)Math.Ceiling((double)totalStyles / styles_par_page),
|
||||
};
|
||||
return this.View(model);
|
||||
}
|
||||
this.logger = logger;
|
||||
this.styleRepository = styleRepository;
|
||||
this.configuration = configuration;
|
||||
|
||||
/// <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.LogInformation("Initialisation du controleur StyleController.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Affiche la liste des styles dans la vue Index.
|
||||
/// </summary>
|
||||
/// <param name="page">Le numero de page pour la pagination des styles (par defaut a 0).</param>
|
||||
/// <returns>La vue Index avec la liste des styles.</returns>
|
||||
public IActionResult Index(int page = 0)
|
||||
{
|
||||
Libelle = string.Empty,
|
||||
};
|
||||
int styles_par_page = this.configuration.GetValue<int>("Webzine:NombreDeLignesAdministration");
|
||||
IEnumerable<Style> listeStyles = this.styleRepository.FindStyles(page * styles_par_page, styles_par_page);
|
||||
|
||||
return this.View(model);
|
||||
}
|
||||
int totalStyles = this.styleRepository.Count();
|
||||
|
||||
/// <summary>
|
||||
/// Cree un nouveau style.
|
||||
/// </summary>
|
||||
/// <param name="model">Nouveau style.</param>
|
||||
/// <returns>IActionResult.</returns>
|
||||
[HttpPost]
|
||||
public IActionResult Create(StyleCreateViewModel model)
|
||||
{
|
||||
var style = new Style
|
||||
var model = new StyleIndexViewModel
|
||||
{
|
||||
Styles = listeStyles,
|
||||
Page = page,
|
||||
TotalPages = (int)Math.Ceiling((double)totalStyles / styles_par_page),
|
||||
};
|
||||
return this.View(model);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Affiche la vue de creation d'un nouveau style.
|
||||
/// </summary>
|
||||
/// <returns>La vue Create pour ajouter un nouveau style.</returns>
|
||||
public IActionResult Create()
|
||||
{
|
||||
Libelle = model.Libelle,
|
||||
};
|
||||
var model = new StyleCreateViewModel
|
||||
{
|
||||
Libelle = string.Empty,
|
||||
};
|
||||
|
||||
this.styleRepository.Add(style);
|
||||
return this.View(model);
|
||||
}
|
||||
|
||||
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)
|
||||
/// <summary>
|
||||
/// Cree un nouveau style.
|
||||
/// </summary>
|
||||
/// <param name="model">Nouveau style.</param>
|
||||
/// <returns>IActionResult.</returns>
|
||||
[HttpPost]
|
||||
public IActionResult Create(StyleCreateViewModel model)
|
||||
{
|
||||
var style = new Style
|
||||
{
|
||||
Libelle = model.Libelle,
|
||||
};
|
||||
|
||||
this.styleRepository.Add(style);
|
||||
|
||||
return this.RedirectToAction("Index");
|
||||
}
|
||||
|
||||
var model = new StyleDeleteViewModel
|
||||
/// <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)
|
||||
{
|
||||
IdStyle = style.IdStyle,
|
||||
Libelle = style.Libelle,
|
||||
};
|
||||
var style = this.styleRepository.Find(id);
|
||||
|
||||
return this.View(model);
|
||||
}
|
||||
if (style == null || style.IdStyle == 0)
|
||||
{
|
||||
return this.RedirectToAction("Index");
|
||||
}
|
||||
|
||||
/// <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);
|
||||
var model = new StyleDeleteViewModel
|
||||
{
|
||||
IdStyle = style.IdStyle,
|
||||
Libelle = style.Libelle,
|
||||
};
|
||||
|
||||
if (style != null)
|
||||
{
|
||||
this.styleRepository.Delete(style);
|
||||
return this.View(model);
|
||||
}
|
||||
|
||||
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>
|
||||
public IActionResult Edit(int id)
|
||||
{
|
||||
var style = this.styleRepository.Find(id);
|
||||
|
||||
if (style == null || style.IdStyle == 0)
|
||||
/// <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");
|
||||
}
|
||||
|
||||
var model = new StyleEditViewModel
|
||||
/// <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>
|
||||
public IActionResult Edit(int id)
|
||||
{
|
||||
IdStyle = style.IdStyle,
|
||||
Libelle = style.Libelle,
|
||||
};
|
||||
var style = this.styleRepository.Find(id);
|
||||
|
||||
return this.View(model);
|
||||
}
|
||||
if (style == null || style.IdStyle == 0)
|
||||
{
|
||||
return this.RedirectToAction("Index");
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
var style = this.styleRepository.Find(model.IdStyle);
|
||||
if (style == null)
|
||||
{
|
||||
return this.RedirectToAction("Index");
|
||||
var model = new StyleEditViewModel
|
||||
{
|
||||
IdStyle = style.IdStyle,
|
||||
Libelle = style.Libelle,
|
||||
};
|
||||
|
||||
return this.View(model);
|
||||
}
|
||||
|
||||
style.Libelle = model.Libelle;
|
||||
this.styleRepository.Update(style);
|
||||
/// <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)
|
||||
{
|
||||
var style = this.styleRepository.Find(model.IdStyle);
|
||||
if (style == null)
|
||||
{
|
||||
return this.RedirectToAction("Index");
|
||||
}
|
||||
|
||||
return this.RedirectToAction("Index");
|
||||
style.Libelle = model.Libelle;
|
||||
this.styleRepository.Update(style);
|
||||
|
||||
return this.RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user