public async Task <IActionResult> Handle(CadastrarAssuntoCommand request, CancellationToken cancellationToken)
        {
            ApplicationResult <Guid> result = new ApplicationResult <Guid>(request);

            //Monta o objeto com os dados do assunto
            var assunto = Domain.AggregatesModel.AssuntoAggregate.Assunto.Criar(
                request.Valor,
                request.AssuntoPaiId,
                true);

            try
            {
                await validarAssunto(assunto);
            } catch (SISRHDomainException e)
            {
                result.SetHttpStatusToBadRequest(e.Message);
                return(result);
            }

            //Adiciona o assunto no banco de dados
            await AssuntoRepository.AdicionarAsync(assunto);

            UnitOfWork.Commit(false);

            result.Result = assunto.AssuntoId;
            result.SetHttpStatusToOk("Assunto cadastrado com sucesso.");
            return(result);
        }
예제 #2
0
        public ActionResult Criar()
        {
            var model = new CursoAssuntoUsuarioViewModel();

            using (var repo = new UsuarioRepository())
            {
                var lista = repo.Listar();
                foreach (var user in lista)
                {
                    var item = new SelectListItem
                    {
                        Text  = user.Nome,
                        Value = user.Id.ToString()
                    };
                    model.ListaUsuarios.Add(item);
                }
            }

            using (var repo = new AssuntoRepository())
            {
                var lista = repo.Listar();
                foreach (var assunto in lista)
                {
                    var item = new SelectListItem
                    {
                        Text  = assunto.NomeAssunto,
                        Value = assunto.IdAssunto.ToString()
                    };
                    model.ListaAssuntos.Add(item);
                }
            }


            return(View(model));
        }
        public async Task <IActionResult> Handle(AlterarAssuntoCommand request, CancellationToken cancellationToken)
        {
            ApplicationResult <Guid> result = new ApplicationResult <Guid>(request);

            //Recupera o objeto assunto
            var assunto = await AssuntoRepository.ObterAsync(request.AssuntoId);

            var alterouPai = assunto.AssuntoPaiId != request.AssuntoPaiId;

            //Monta o objeto com os dados do assunto
            assunto.Alterar(request.Valor, request.AssuntoPaiId, request.Ativo);

            try
            {
                await validarAssunto(assunto, alterouPai);
            }
            catch (SISRHDomainException e)
            {
                result.SetHttpStatusToBadRequest(e.Message);
                return(result);
            }

            //Altera o assunto no banco de dados
            AssuntoRepository.Atualizar(assunto);
            UnitOfWork.Commit(false);

            result.Result = assunto.AssuntoId;
            result.SetHttpStatusToOk("Assunto alterado com sucesso.");
            return(result);
        }
        public ActionResult Index()
        {
            var repo = new AssuntoRepository();

            var lista = repo.Listar();

            return(View(lista));
        }
        public ActionResult Excluir(int id)
        {
            using (var repo = new AssuntoRepository())
            {
                var assunto = repo.Obter(id);

                return(View(assunto));
            }
        }
        public ActionResult Editar(Assunto assunto)
        {
            using (var repo = new AssuntoRepository())
            {
                assunto = repo.Atualizar(assunto);

                return(RedirectToAction("Index"));
            }
        }
예제 #7
0
 private void Excluir(AssuntoCursoUsuario assunto)
 {
     using (AssuntoRepository repo = new AssuntoRepository())
     {
         repo.Excluir(assunto);
         var assuntoRet = repo.Obter(assunto.IdAssunto);
         Assert.IsTrue(assuntoRet == null);
     }
 }
예제 #8
0
        public PartialViewResult MenuAssuntos()
        {
            using (AssuntoRepository repo = new AssuntoRepository())
            {
                // Obter a lista de assuntos
                var model = repo.ListarTotalCursosPorAssunto();

                return(PartialView("~/Views/Shared/ItensMenuAssuntos.cshtml", model));
            }
        }
예제 #9
0
        public AssuntoCursoUsuario ObterAssunto(int id)
        {
            using (AssuntoRepository repo = new AssuntoRepository())
            {
                var assunto = repo.Obter(id);

                Assert.AreEqual("Demo teste 1", assunto.Nome);

                return(assunto);
            }
        }
        public ActionResult Criar()
        {
            AssuntoRepository Repor  = new AssuntoRepository();
            UsuarioRepository Repor1 = new UsuarioRepository();
            Curso             Repor2 = new Curso();

            Repor2.ListaAssunto = Repor.Listar();
            Repor2.ListaUsuario = Repor1.Listar();

            return(View(Repor2));
        }
        public ActionResult Criar(Assunto assunto)
        {
            using (var repo = new AssuntoRepository())
            {
                var inserido = repo.Inserir(assunto);

                if (inserido.Id == 0)
                {
                    ModelState.AddModelError("", "Erro");
                }
            }

            return(RedirectToAction("Index"));
        }
예제 #12
0
        private AssuntoCursoUsuario AtualizarAssunto(AssuntoCursoUsuario assunto)
        {
            using (AssuntoRepository repo = new AssuntoRepository())
            {
                assunto.Nome = "Nome Atualizado";
                repo.Atualizar(assunto);

                var assuntoAtualizado = repo.Obter(assunto.IdAssunto);

                Assert.AreEqual("Nome Atualizado", assuntoAtualizado.NomeAssunto);

                return(assuntoAtualizado);
            }
        }
예제 #13
0
        private int InserirAssunto()
        {
            using (AssuntoRepository repo = new AssuntoRepository())
            {
                var assunto = new AssuntoCursoUsuario
                {
                    Nome = "Demo teste 1"
                };

                int id = repo.Inserir(assunto).IdCurso;

                Assert.IsTrue(id > 0);
                return(id);
            }
        }
        public ActionResult Criar(Curso curso)
        {
            CursoRepository Repor = new CursoRepository();

            Repor.Inserir(curso);


            AssuntoRepository Repor3 = new AssuntoRepository();
            UsuarioRepository Repor1 = new UsuarioRepository();
            Curso             Repor2 = new Curso();

            Repor2.ListaAssunto = Repor3.Listar();
            Repor2.ListaUsuario = Repor1.Listar();

            return(View(Repor2));
        }
        public ActionResult Excluir(Assunto assunto)
        {
            try
            {
                using (var repo = new AssuntoRepository())
                {
                    repo.Excluir(assunto);

                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("Erro", ex.Message);
                return(View(assunto));
            }
        }
예제 #16
0
        public ActionResult Assunto(int?id)
        {
            IEnumerable <AssuntoCursoUsuario> listaCursoAssunto = new List <AssuntoCursoUsuario>();

            using (AssuntoRepository repoCursoAssunto = new AssuntoRepository())
            {
                listaCursoAssunto = repoCursoAssunto.ListarCursosPorAssuntos(id);
            }

            using (CursoRepository repoCurso = new CursoRepository())
            {
                foreach (var lista in listaCursoAssunto)
                {
                    //listaTodo.QtdUsuariosVotosCurso.Add(listaTodo.IdCurso);
                    lista.QtdUsuariosVotosCurso = repoCurso.ObterQtdVotos(lista.IdCurso);
                    lista.TotalDuracaoCurso     = repoCurso.SomarDuracaoCurso(lista.IdCurso);
                }
            }

            if (listaCursoAssunto.Count() == 0)
            {
                return(RedirectToAction("Index", "Curso"));
            }

            var x = 0;

            foreach (var item in listaCursoAssunto)
            {
                /*
                 *  Loop DoWhile que passa apenas uma vez para não
                 *  declarar TempData["NomeAssunto"] varias vez
                 *  sem necessidade
                 */
                do
                {
                    TempData["NomeAssunto"] = item.NomeAssunto;
                    x++;
                } while (x == 0);
            }
            return(View(listaCursoAssunto));
        }