public async Task <int> DeleteCommandes(List <int> ids)
        {
            List <CdeCli> commandesToDelete = await _pizzaDbContext.CdeCli.Where(c => ids.Contains(c.Num_Cde_Cli)).ToListAsync();

            _pizzaDbContext.RemoveRange(commandesToDelete);

            return(await _pizzaDbContext.SaveChangesAsync());
        }
        public async Task <IActionResult> Create(int PizzaId, List <int> NewIngredients)
        {
            if (ModelState.IsValid)
            {
                var                    oldIngredients       = _context.PizzaIngredients.Where(m => m.PizzaId == PizzaId).Select(m => m.IngredientId).ToList();
                List <int>             deleteIngredientsIds = oldIngredients.Except(NewIngredients).ToList();
                List <PizzaIngredient> toDelete             = _context.PizzaIngredients.Where(m => m.PizzaId == PizzaId && deleteIngredientsIds.Contains(m.IngredientId)).ToList();
                List <int>             addIngredientsIds    = NewIngredients.Except(oldIngredients).ToList();
                List <PizzaIngredient> toAdd = new List <PizzaIngredient>();
                foreach (int i in addIngredientsIds)
                {
                    toAdd.Add(new PizzaIngredient {
                        PizzaId = PizzaId, IngredientId = i
                    });
                }

                _context.RemoveRange(toDelete);
                _context.AddRange(toAdd);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Pizzas"));
            }
            ViewData["PizzaId"] = new SelectList(_context.Pizzas.Where(x => x.Id == PizzaId), "Id", "Name");
            return(View());
        }
Esempio n. 3
0
        public async Task <int> DeletePizzas(List <int> ids)
        {
            List <Catalogue_Pizza> pizzasToDelete = await _pizzaDbContext.Catalogue_Pizza.Where(p => ids.Contains(p.Num_Pizza)).ToListAsync();

            _pizzaDbContext.RemoveRange(pizzasToDelete);

            return(await _pizzaDbContext.SaveChangesAsync());
        }
Esempio n. 4
0
        public async Task <int> DeleteLignesCommande(List <int> ids)
        {
            List <Ligne_Cde_Cli> lignesCommandeToDelete = await _pizzaDbContext.Ligne_Cde_Cli.Where(l => ids.Contains(l.Num_Ligne_Cde)).ToListAsync();

            _pizzaDbContext.RemoveRange(lignesCommandeToDelete);

            return(await _pizzaDbContext.SaveChangesAsync());
        }
        public async Task <int> DeleteLivreurs(List <int> ids)
        {
            List <Livreur> livreursToDelete = await _pizzaDbContext.Livreur.Where(l => ids.Contains(l.Num_Liv)).ToListAsync();

            _pizzaDbContext.RemoveRange(livreursToDelete);

            return(await _pizzaDbContext.SaveChangesAsync());
        }
Esempio n. 6
0
        public async Task <int> DeleteQuartiers(List <int> ids)
        {
            List <Num_Cde_Cli> quartiersToDelete = await _pizzaDbContext.Quartier.Where(q => ids.Contains(q.Num_Quartier)).ToListAsync();

            _pizzaDbContext.RemoveRange(quartiersToDelete);

            return(await _pizzaDbContext.SaveChangesAsync());
        }