feat: implémentation TitreAdminService pour la gestion des titres et ajout TitreAdminModèle de commande
This commit is contained in:
@@ -192,31 +192,16 @@ public class DbTitreRepository : ITitreRepository
|
||||
try
|
||||
{
|
||||
this.logger.LogInformation("Mise à jour du titre avec l'ID: {IdTitre}", titre.IdTitre);
|
||||
this.logger.LogDebug("Début de la mise à jour du titre en base de données");
|
||||
|
||||
var existingTitre = this.context.Titres.Find(titre.IdTitre);
|
||||
if (existingTitre != null)
|
||||
{
|
||||
this.logger.LogDebug("Titre trouvé, mise à jour des propriétés");
|
||||
this.context.Entry(existingTitre).CurrentValues.SetValues(titre);
|
||||
|
||||
// Handle many-to-many relationships
|
||||
this.logger.LogDebug("Mise à jour des relations many-to-many (Styles)");
|
||||
this.context.Entry(existingTitre).Collection(t => t.Styles).Load();
|
||||
existingTitre.Styles.Clear();
|
||||
foreach (var style in titre.Styles)
|
||||
{
|
||||
existingTitre.Styles.Add(style);
|
||||
}
|
||||
|
||||
this.context.SaveChanges();
|
||||
this.logger.LogDebug("Titre mis à jour avec succès: {IdTitre}", titre.IdTitre);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.logger.LogWarning("Titre avec l'ID {IdTitre} non trouvé pour la mise à jour", titre.IdTitre);
|
||||
throw new InvalidOperationException($"Titre avec l'ID {titre.IdTitre} non trouvé.");
|
||||
this.logger.LogWarning("Aucun titre trouvé avec l'ID: {IdTitre}", titre.IdTitre);
|
||||
}
|
||||
|
||||
this.logger.LogDebug("Titre trouvé, mise à jour des propriétés");
|
||||
|
||||
this.context.SaveChanges();
|
||||
this.logger.LogDebug("Titre mis à jour avec succès: {IdTitre}", titre.IdTitre);
|
||||
}
|
||||
catch (DbUpdateException ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user