public Boolean RemoveProduct(Listino listino, Prodotto prodotto, int quantita) { Listino existingListino = GetListino(listino.Id); if (existingListino != null) { ProdottoService prodSrv = new ProdottoService(); Prodotto existingProdotto = prodSrv.GetProdotto(prodotto.Id); if (existingProdotto != null) { DettaglioListinoService dlSrv = new DettaglioListinoService(); ///Get from different context (NOT WORKING) //DettaglioListino dettaglio = dlSrv.GetDettaglioByListinoProdotto(listino.Id, prodotto.Id); ///Get from same context (OK) DettaglioListino dettaglio = context.DettaglioListinoSet.SingleOrDefault(x => x.Id_listino == listino.Id && x.Id_prodotto == prodotto.Id); if (dettaglio != null) { context.DettaglioListinoSet.Remove(dettaglio); context.SaveChanges(); return(true); } else { return(false); } } else { return(false); //throw new DbUpdateException(); } } else { return(false); //throw new DbUpdateException(); } }
public Boolean DeleteProdotto(Prodotto prodotto) { Prodotto newProdotto = GetProdotto(prodotto.Id); if(newProdotto != null) { /// FIRST remove related entries in dettaglioListino DettaglioListinoService dlSrv = new DettaglioListinoService(); List<DettaglioListino> dettagli = dlSrv.GetDettagliByProdotto(prodotto.Id); foreach (var dettaglio in dettagli) { context.DettaglioListinoSet.Remove(dettaglio); } context.ProdottoSet.Remove(prodotto); context.SaveChanges(); return true; } else { return false; } }
public Boolean DeleteListino(Listino listino) { Listino newListino = GetListino(listino.Id); if (newListino != null) { /// FIRST remove related entries in dettaglioListino DettaglioListinoService dlSrv = new DettaglioListinoService(); List <DettaglioListino> dettagli = dlSrv.GetDettagliByListino(listino.Id); foreach (var dettaglio in dettagli) { context.DettaglioListinoSet.Remove(dettaglio); context.SaveChanges(); } context.ListinoSet.Remove(listino); context.SaveChanges(); return(true); } else { return(false); } }