public async Task <IActionResult> Edit(int id, [Bind("AfhaalpuntId,Omschrijving,Adres,Postcode,stad")] Afhaalpunt afhaalpunt)
        {
            string userid = User.FindFirstValue(ClaimTypes.NameIdentifier);
            Klant  klant  = _context.Klanten.FirstOrDefault(k => k.UserId == userid);

            if (id != afhaalpunt.AfhaalpuntId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(afhaalpunt);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AfhaalpuntExists(afhaalpunt.AfhaalpuntId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(afhaalpunt));
        }
        public async Task <IActionResult> Edit(int id, [Bind("IngredientId,Soort,Allergeen,Voorraad,Prijs")] Ingredient ingredient)
        {
            string userid = User.FindFirstValue(ClaimTypes.NameIdentifier);
            Klant  klant  = _context.Klanten.FirstOrDefault(k => k.UserId == userid);

            if (id != ingredient.IngredientId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(ingredient);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!IngredientExists(ingredient.IngredientId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(ingredient));
        }
Beispiel #3
0
        public async Task <IActionResult> Edit(int id, EditProductViewModel viewModel)
        {
            Product product = await _context.Producten.Include(p => p.Productregels).SingleOrDefaultAsync(p => p.ProductId == id);

            string userid = User.FindFirstValue(ClaimTypes.NameIdentifier);
            Klant  klant  = _context.Klanten.FirstOrDefault(k => k.UserId == userid);

            if (id != viewModel.Product.ProductId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                product.Naam  = viewModel.Product.Naam;
                product.Prijs = viewModel.Product.Prijs;
                product.Image = viewModel.Product.Image;
                product.Type  = viewModel.Product.Type;

                List <Productregel> productregels = new List <Productregel>();

                foreach (int ingredientid in viewModel.GeselecteerdeIngredienten)
                {
                    productregels.Add(
                        new Productregel
                    {
                        IngredientId = ingredientid,
                        ProductId    = viewModel.Product.ProductId
                    }
                        );
                }
                product.Productregels.RemoveAll(pr => !productregels.Contains(pr));
                product.Productregels.AddRange(productregels.Where(pr => !product.Productregels.Contains(pr)));

                _context.Update(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            viewModel.Ingredientenlijst         = new SelectList(_context.Ingredienten, "IngredientId", "Soort");
            viewModel.GeselecteerdeIngredienten = product.Productregels.Select(pr => pr.IngredientId);
            return(View(viewModel));
        }