Пример #1
0
        public ActionResult Edit([Bind(Include = "Id,Nome,BlocosId")] CursoViewModel cursoViewModel)
        {
            if (ModelState.IsValid)
            {
                var curso = new Curso();
                curso.Id   = cursoViewModel.Id;
                curso.Nome = cursoViewModel.Nome;

                if (cursoViewModel.BlocosId.Count > 0)
                {
                    curso.Blocos = new List <Bloco>();
                    foreach (int blocoId in cursoViewModel.BlocosId)
                    {
                        var bloco = db.Blocos.Find(blocoId);
                        if (bloco != null)
                        {
                            curso.Blocos.Add(bloco);
                        }
                    }
                }

                db.Entry(curso).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            var blocos = db.Blocos.ToList();

            ViewBag.ListaBlocos = new MultiSelectList(blocos, "Id", "Nome", null);

            return(View(cursoViewModel));
        }
Пример #2
0
 public ActionResult Edit([Bind(Include = "Id,Nome,Email")] Professor professor)
 {
     if (ModelState.IsValid)
     {
         db.Entry(professor).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(professor));
 }
Пример #3
0
 public ActionResult Edit([Bind(Include = "Id,Nome")] Modulo modulo)
 {
     if (ModelState.IsValid)
     {
         db.Entry(modulo).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(modulo));
 }
Пример #4
0
 public ActionResult Edit([Bind(Include = "Id,Codigo")] Turma turma)
 {
     if (ModelState.IsValid)
     {
         db.Entry(turma).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(turma));
 }
Пример #5
0
 public ActionResult Edit([Bind(Include = "Id,Descricao")] TopicoAvaliacao topicoavaliacao)
 {
     if (ModelState.IsValid)
     {
         db.Entry(topicoavaliacao).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(topicoavaliacao));
 }
Пример #6
0
        public ActionResult Edit(Bloco bloco)
        {
            if (ModelState.IsValid)
            {
                db.Entry(bloco).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(bloco));
        }
Пример #7
0
 public ActionResult Edit([Bind(Include = "Id,Texto,TopicoAvaliacaoId")] Questao questao)
 {
     if (ModelState.IsValid)
     {
         db.Entry(questao).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.TopicoAvaliacaoId = new SelectList(db.Topicos, "Id", "Descricao", questao.TopicoAvaliacaoId);
     return(View(questao));
 }
Пример #8
0
 public ActionResult Edit([Bind(Include = "Id,QuestaoId,OpcaoEscolhida,AlunoId,AvaliacaoId")] Resposta resposta)
 {
     if (ModelState.IsValid)
     {
         db.Entry(resposta).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AlunoId     = new SelectList(db.Users, "Id", "Name", resposta.AlunoId);
     ViewBag.AvaliacaoId = new SelectList(db.Avaliacoes, "Id", "Objetivo", resposta.AvaliacaoId);
     ViewBag.QuestaoId   = new SelectList(db.Questoes, "Id", "Texto", resposta.QuestaoId);
     return(View(resposta));
 }
Пример #9
0
        public ActionResult Edit(AvaliacaoViewModel avaliacaoViewModel)
        {
            if (ModelState.IsValid)
            {
                var avaliacao = new Avaliacao();
                avaliacao.Id         = avaliacaoViewModel.Id;
                avaliacao.Objetivo   = avaliacaoViewModel.Objetivo;
                avaliacao.DataInicio = avaliacaoViewModel.DataInicio;
                avaliacao.DataFim    = avaliacaoViewModel.DataFim;

                foreach (var moduloID in avaliacaoViewModel.ModulosID)
                {
                    var modulo = db.Modulos.Find(moduloID);
                    if (modulo != null)
                    {
                        //if (avaliacao.Modulos == null)
                        //{
                        //    avaliacao.Modulos = new List<Modulo> { modulo };
                        //}
                        //else
                        //{
                        //    avaliacao.Modulos.Add(modulo);
                        //}
                    }
                }

                foreach (var questaoID in avaliacaoViewModel.QuestoesID)
                {
                    var questao = db.Questoes.Find(questaoID);
                    if (questao != null)
                    {
                        if (avaliacao.Questoes == null)
                        {
                            avaliacao.Questoes = new List <Questao> {
                                questao
                            };
                        }
                        else
                        {
                            avaliacao.Questoes.Add(questao);
                        }
                    }
                }

                db.Entry(avaliacao).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(avaliacaoViewModel));
        }
 public void GravarRespostas(IEnumerable<Resposta> respostas)
 {
     using (var db = new AvaliacoesDbContext())
     {
         var enumerable = respostas as IList<Resposta> ?? respostas.ToList();
         for (var index = 0; index < enumerable.Count; index++)
         {
             var resposta = enumerable[index];
             var jaResposdido = db.Respostas.FirstOrDefault(
                 resp =>
                     resp.AlunoId == resposta.AlunoId && resp.QuestaoId == resposta.QuestaoId &&
                     resposta.AvaliacaoId == resp.AvaliacaoId);
             if (jaResposdido == null)
             {
                 db.Respostas.Add(resposta);
             }
             else
             {
                 jaResposdido.OpcaoEscolhida = resposta.OpcaoEscolhida;
                 db.Entry(jaResposdido).State = EntityState.Modified;
             }
         }
         db.SaveChanges();
     }
 }