示例#1
0
        public async Task <IActionResult> Edit(int id, int[] VakId, [Bind("Id,Naam,Groepscode")] Groep groep)
        {
            if (id != groep.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    Groep existingGroep = _context.Groep.Include(gv => gv.Vakken).FirstOrDefault(gv => gv.Id == id);
                    existingGroep.Vakken.Clear();

                    foreach (var item in VakId)
                    {
                        GroepVak gv = new GroepVak
                        {
                            VakId = item,
                        };
                        existingGroep.Vakken.Add(gv);
                    }
                    existingGroep.Naam       = groep.Naam;
                    existingGroep.Groepscode = groep.Groepscode;
                    existingGroep.Studenten  = groep.Studenten;
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GroepExists(groep.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(groep));
        }
示例#2
0
        public async Task <IActionResult> Create(int[] VakId, [Bind("Id,Naam,Groepscode")] Groep groep)
        {
            List <GroepVak> UpdateList = new List <GroepVak>();

            foreach (var item in VakId)
            {
                GroepVak gv = new GroepVak
                {
                    VakId = item
                };
                UpdateList.Add(gv);
            }
            groep.Vakken = UpdateList;
            if (ModelState.IsValid)
            {
                _context.Add(groep);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(groep));
        }