fix: improve form handling for Create and Edit actions in TitreController
This commit is contained in:
@@ -95,6 +95,33 @@ public class TitreController : Controller
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
public IActionResult Create(TitreAdminDTO model)
|
public IActionResult Create(TitreAdminDTO model)
|
||||||
{
|
{
|
||||||
|
if (!this.ModelState.IsValid)
|
||||||
|
{
|
||||||
|
var form = new AdminTitreForm
|
||||||
|
{
|
||||||
|
IdArtiste = model.IdArtiste,
|
||||||
|
Libelle = model.Libelle,
|
||||||
|
Album = model.Album,
|
||||||
|
Chronique = model.Chronique,
|
||||||
|
DateSortie = model.DateSortie,
|
||||||
|
Duree = model.Duree,
|
||||||
|
UrlJaquette = model.UrlJaquette,
|
||||||
|
UrlEcoute = model.UrlEcoute,
|
||||||
|
Styles = model.Styles,
|
||||||
|
Artistes = this.artisteRepository.FindAll().Select(a => new SelectListItem
|
||||||
|
{
|
||||||
|
Value = a.IdArtiste.ToString(),
|
||||||
|
Text = a.Nom,
|
||||||
|
}).ToList(),
|
||||||
|
AllStyles = this.styleRepository.FindAll().Select(s => new SelectListItem
|
||||||
|
{
|
||||||
|
Value = s.IdStyle.ToString(),
|
||||||
|
Text = s.Libelle,
|
||||||
|
}).ToList(),
|
||||||
|
};
|
||||||
|
return this.View(form);
|
||||||
|
}
|
||||||
|
|
||||||
this.titreAdminService.CreerTitre(model);
|
this.titreAdminService.CreerTitre(model);
|
||||||
return this.RedirectToAction("Index");
|
return this.RedirectToAction("Index");
|
||||||
}
|
}
|
||||||
@@ -147,6 +174,34 @@ public class TitreController : Controller
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
public IActionResult Edit(TitreAdminDTO model)
|
public IActionResult Edit(TitreAdminDTO model)
|
||||||
{
|
{
|
||||||
|
if (!this.ModelState.IsValid)
|
||||||
|
{
|
||||||
|
var form = new AdminTitreForm
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
IdArtiste = model.IdArtiste,
|
||||||
|
Libelle = model.Libelle,
|
||||||
|
Album = model.Album,
|
||||||
|
Chronique = model.Chronique,
|
||||||
|
DateSortie = model.DateSortie,
|
||||||
|
Duree = model.Duree,
|
||||||
|
UrlJaquette = model.UrlJaquette,
|
||||||
|
UrlEcoute = model.UrlEcoute,
|
||||||
|
Styles = model.Styles,
|
||||||
|
Artistes = this.artisteRepository.FindAll().Select(a => new SelectListItem
|
||||||
|
{
|
||||||
|
Value = a.IdArtiste.ToString(),
|
||||||
|
Text = a.Nom,
|
||||||
|
}).ToList(),
|
||||||
|
AllStyles = this.styleRepository.FindAll().Select(s => new SelectListItem
|
||||||
|
{
|
||||||
|
Value = s.IdStyle.ToString(),
|
||||||
|
Text = s.Libelle,
|
||||||
|
}).ToList(),
|
||||||
|
};
|
||||||
|
return this.View(form);
|
||||||
|
}
|
||||||
|
|
||||||
this.titreAdminService.ModifierTitre(model);
|
this.titreAdminService.ModifierTitre(model);
|
||||||
return this.RedirectToAction("Index");
|
return this.RedirectToAction("Index");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user