public void ModifierSoin(Soin soin) { using (SoinDAL dal = new SoinDAL()) { dal.ModifierSoin(soin); } }
public void AjouterSoin(Soin soin) { using (SoinDAL dal = new SoinDAL()) { dal.AjouterSoin(soin); } }
/// <summary> /// Modifier un soin /// </summary> /// <param name="soin"></param> internal void ModifierSoin(Soin soin) { bdd.Soins.Attach(soin); bdd.Entry(soin).State = System.Data.Entity.EntityState.Modified; bdd.SaveChanges(); // Update des produits : // Solution adoptée : Supprimer les liens puis les réajouter. List <SoinProduit> soinProduits = new List <SoinProduit>(); foreach (var produit in soin.Produits) { soinProduits.Add(new SoinProduit() { Produit = produit, Soin = soin }); } var soinProduitExistantant = bdd.SoinProduits.Where(p => p.Soin.Id == soin.Id); bdd.SoinProduits.RemoveRange(soinProduitExistantant); bdd.SaveChanges(); bdd.SoinProduits.AddRange(soinProduits); bdd.SaveChanges(); }
internal void AjouterSoin(Soin soin) { var soinAjoute = bdd.Soins.Add(soin); bdd.SaveChanges(); //Ajout des SoinProduit qui référencent les liens entre le soin et les produits: List <SoinProduit> soinProduit = new List <SoinProduit>(); foreach (var produit in soin.Produits) { //Récupére le produit existant en base pour ne pas //en créer un nouveau var produitEnBase = bdd.Produits.FirstOrDefault(p => p.Id == produit.Id); if (produitEnBase != null) // Utilisation du produit existant { soinProduit.Add( new SoinProduit() { Produit = produitEnBase, Soin = soinAjoute }); } else // Possibilité de créer un produit à la volée si il n'existe pas { soinProduit.Add( new SoinProduit() { Produit = produit, Soin = soinAjoute }); } } bdd.SoinProduits.AddRange(soinProduit); bdd.SaveChanges(); }
public void ModifierSoin(Soin soin) { _soinService.ModifierSoin(soin); }
public void AjouterSoin(Soin soin) { _soinService.AjouterSoin(soin); }