public async Task <IActionResult> Edit(int id, List <CreateViewModel> model)
        {
            if (model == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                foreach (var item in model)
                {
                    if (item.ID == 0 && item.Selezionato)
                    {
                        var assegnazione = new Assegnazione();
                        assegnazione.UtenteId = id;
                        assegnazione.Gruppo   = await _context.Gruppi.SingleAsync(g => g.Nome == item.Nome);

                        await _context.Assegnazioni.AddAsync(assegnazione);
                    }
                    else if (item.ID != 0 && !item.Selezionato)
                    {
                        _context.Remove(await _context.Assegnazioni.SingleAsync(a => a.Id == item.ID));
                    }
                }
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewData["UtenteId"] = id;
            return(View(model));
        }
        /// <summary>
        /// Metodo costruttore del ViewModel del requisito.
        /// </summary>
        public MotivazioneViewModel()
        {
            SaveVoto = new DelegateCommand(OnSaveClick, CanSaveClick);

            AppDbContext ctx = new AppDbContext();

            repoQdc = new QdcDbDataRepository(ctx);
            repoAss = new AssegnazioneDbDataRepository(ctx);
            try
            {
                int ind = repoQdc.Get().Where(q1 => q1.Id == q1.Id).Max(q1 => q1.Id);
                Motivazioni = new ObservableCollection <Assegnazione>(repoAss.Get().Where(a1 => a1.QdcId == ind));
                Ass         = Motivazioni[0];
            }
            catch (Exception e)
            {
                if (e is ArgumentOutOfRangeException || e is InvalidOperationException)
                {
                    MessageBox.Show("Non esistono requisiti assegnati a questo Qdc");
                }
            }
        }