Exemple #1
0
 private static Aluno MapearParaDominio(AlunoDto alunoDto)
 {
     return(new Aluno()
     {
         Nome = alunoDto.Nome, Email = alunoDto.Email, ProfessorId = alunoDto.ProfessorId
     });
 }
Exemple #2
0
        public void InserirAlunoDb(AlunoDto aluno)
        {
            try
            {
                var comandInsert = conexao.CreateCommand();
                comandInsert.CommandText = "insert into alunos (nome, sobrenome, telefone, ra) values(@nome, @sobrenome, @telefone, @ra)";

                IDbDataParameter paramNome = new SqlParameter("nome", aluno.Nome);
                comandInsert.Parameters.Add(paramNome);

                IDbDataParameter paramSobrenome = new SqlParameter("sobrenome", aluno.Sobrenome);
                comandInsert.Parameters.Add(paramSobrenome);

                IDbDataParameter paramTelefone = new SqlParameter("telefone", aluno.Telefone);
                comandInsert.Parameters.Add(paramTelefone);

                IDbDataParameter paramRa = new SqlParameter("ra", aluno.Ra);
                comandInsert.Parameters.Add(paramRa);

                comandInsert.ExecuteNonQuery();

                conexao.Close();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                conexao.Close();
            }
        }
        private void AtualizarAluno(AlunoDto dto)
        {
            var viewModel = new AlunoViewModel(dto);

            _dialogService.ShowDialog(viewModel);

            Pesquisar();
        }
        public ActionResult SalvarAluno([FromBody] AlunoDto dto)
        {
            var aluno = new Aluno(dto.Matricula, dto.Nome, dto.Curso, dto.Periodo, dto.anoIngresso);

            _alunosCollection.InsertOne(aluno);

            return(StatusCode(201, "Aluno adicionado com sucesso"));
        }
Exemple #5
0
        public async Task <Aluno> EditAluno(AlunoDto alunoDto)
        {
            var aluno = _mapper.Map <Aluno>(alunoDto);

            _alunoRepository.AlterarAsync(aluno);
            await _unitOfWork.CommitAsync();

            return(aluno);
        }
Exemple #6
0
        public async Task <Aluno> AddAluno(AlunoDto aluno)
        {
            var adAluno = new Aluno();

            adAluno = _mapper.Map <Aluno>(aluno);
            _alunoRepository.Save(adAluno);
            await _unitOfWork.CommitAsync();

            return(adAluno);
        }
 public void Atualizar(AlunoDto aluno)
 {
     try
     {
         new AlunoDAO().AtualizarAlunoDb(aluno);
     }
     catch (Exception ex)
     {
         throw new Exception($"Erro ao atualizar o aluno. Erro => {ex.Message} ");
     }
 }
        public IActionResult Post(AlunoDto model)
        {
            var aluno = _mapper.Map <Aluno>(model);

            _repo.Create(aluno);
            if (_repo.SaveChanges())
            {
                return(Created($"api/aluno/{model.Id}", _mapper.Map <AlunoDto>(aluno)));
            }
            return(BadRequest("Aluno não encontrado"));
        }
Exemple #9
0
        public IActionResult Post([FromBody] AlunoDto model)
        {
            var aluno = _mapper.Map <Aluno>(model);

            _baseRepository.Add(aluno);
            if (_baseRepository.SaveChanges())
            {
                return(Created($"/api/aluno/{model.Id}", _mapper.Map <AlunoDto>(aluno)));
            }

            //Falhou
            return(BadRequest("Aluno não foi cadastrado"));
        }
Exemple #10
0
 // PUT: api/Alunos/5
 public IHttpActionResult Put(int id, [FromBody] AlunoDto aluno)
 {
     try
     {
         var alunos = new Alunos();
         aluno.Id = id;
         alunos.Atualizar(aluno);
         return(Ok(alunos.ListarAlunos(id).FirstOrDefault()));
     }
     catch (Exception ex)
     {
         return(InternalServerError(ex));
     }
 }
Exemple #11
0
        public IActionResult Editar(int id)
        {
            var aluno = _alunoRepositorio.ObterPorId(id);
            var dto   = new AlunoDto
            {
                Id          = aluno.Id,
                Nome        = aluno.Nome,
                Cpf         = aluno.Cpf,
                Email       = aluno.Email,
                PublicoAlvo = aluno.PublicoAlvo.ToString()
            };

            return(View("NovoOuEditar", dto));
        }
Exemple #12
0
 public void SalvarCriandoProfessor(AlunoDto alunoDto)
 {
     using (var transacao = database.BeginTransaction())
     {
         Aluno aluno     = MapearParaDominio(alunoDto);
         var   professor = new Professor()
         {
             Nome = "Novo professor"
         };
         repositorioProfessor.Salvar(professor);
         aluno.ProfessorId = professor.Id;
         repositorioAluno.Salvar(aluno);
         transacao.Commit();
     }
 }
        public ArmazenadorDeAlunoTest()
        {
            _faker    = new Faker();
            _alunoDto = new AlunoDto
            {
                Nome        = _faker.Person.FullName,
                Email       = _faker.Person.Email,
                Cpf         = _faker.Person.Cpf(),
                PublicoAlvo = PublicoAlvo.Empregado.ToString(),
            };
            _alunoRepositorio = new Mock <IAlunoRepositorio>();
            var conversorDePublicoAlvo = new Mock <IConversorDePublicoAlvo>();

            _armazenadorDeAluno = new ArmazenadorDeAluno(_alunoRepositorio.Object, conversorDePublicoAlvo.Object);
        }
Exemple #14
0
        public bool RemoveAluno(AlunoDto dto)
        {
            Contexto.Database.ExecuteSqlCommand($@"UPDATE dbo.aluno 
                SET IdUsuarioExclusao = {SessionUser.IdUsuario}, 
                DataHoraExclusao = '{DateTime.Now.ToString("dd/MM/yyyy HH:mm")}'
                WHERE Id = {dto.Id}");

            Contexto.Database.ExecuteSqlCommand($@"DELETE FROM dbo.alunogrupo 
                WHERE IdAluno = {dto.Id}");

            Contexto.Database.ExecuteSqlCommand($@"DELETE FROM dbo.alunoespecialidade 
                WHERE IdAluno = {dto.Id}");

            return(true);
        }
        public IActionResult Put(int Id, AlunoDto model)
        {
            var aluno = _repo.GetAlunoById(Id, false);

            if (aluno == null)
            {
                return(BadRequest("Aluno não encontrado"));
            }
            _mapper.Map(aluno, model);
            _repo.Update(aluno);
            if (_repo.SaveChanges())
            {
                return(Created($"api/aluno/{model.Id}", _mapper.Map <AlunoDto>(aluno)));
            }
            return(BadRequest("Aluno não encontrado"));
        }
Exemple #16
0
        public ArmazenadorDeAlunoTest()
        {
            _faker = new Faker();

            _alunoDto = new AlunoDto
            {
                Nome        = _faker.Person.FullName,
                Cpf         = _faker.Person.Cpf(),
                Email       = _faker.Person.Email,
                PublicoAlvo = "Estudante"
            };

            _alunoRepositorio       = new Mock <IAlunoRepositorio>();
            _conversorDePublicoAlvo = new Mock <IConversorDePublicoAlvo>();
            _armazenadorDeAluno     = new ArmazenadorDeAluno(_alunoRepositorio.Object, _conversorDePublicoAlvo.Object);
        }
Exemple #17
0
        public AlunoViewModel(AlunoDto aluno = null)
        {
            if (aluno == null)
            {
                Aluno  = new AlunoDto();
                _isNew = true;
            }
            else
            {
                Aluno  = aluno;
                _isNew = false;
            }

            OkCommand       = new Command(Salvar);
            CancelarCommand = new Command(() => DialogResult = false);
        }
Exemple #18
0
        public ArmazenadorDeAlunoTest()
        {
            _faker = new Faker();

            _alunoDto = new AlunoDto
            {
                Cpf         = GeradorCpf.GerarCpf(),
                Email       = _faker.Person.Email,
                Nome        = _faker.Person.FullName,
                PublicoAlvo = PublicoAlvo.Universitario.ToString()
            };
            _alunoRepositorioMock       = new Mock <IAlunoRepositorio>();
            _conversorDePublicoAlvoMock = new Mock <IConversorDePublicoAlvo>();

            _armazenadorDeAluno = new ArmazenadorDeAluno(_alunoRepositorioMock.Object, _conversorDePublicoAlvoMock.Object);
        }
Exemple #19
0
        public bool EditAluno(AlunoDto dto)
        {
            var aluno = (from a in Contexto.Aluno
                         where a.Id == dto.Id
                         select a).FirstOrDefault();

            aluno.Usuario = (from u in Contexto.Usuario
                             where u.Id == aluno.IdUsuario
                             select u).FirstOrDefault();

            aluno.Nome                 = dto.Nome;
            aluno.Sexo                 = dto.Sexo;
            aluno.DataNascimento       = Convert.ToDateTime(dto.DescricaoDataNascimento);
            aluno.Telefone             = dto.Telefone;
            aluno.Celular              = dto.Celular;
            aluno.Email                = dto.Email;
            aluno.Matricula            = dto.Matricula;
            aluno.Semestre             = dto.Semestre;
            aluno.CPF                  = dto.CPF;
            aluno.Ativo                = dto.Ativo;
            aluno.IdResponsavel        = dto.IdResponsavel;
            aluno.Usuario.UsuarioLogin = dto.Usuario;

            if (dto.Senha.Length > 3)
            {
                aluno.Usuario.Senha = GerarMD5(dto.Senha);
            }

            Contexto.Database.ExecuteSqlCommand($@"UPDATE dbo.alunoespecialidade 
                SET Temporario = false, IdAluno = {dto.Id} 
                WHERE IdUsuario = {SessionUser.IdUsuario}
                AND Temporario = true");
            Contexto.Database.ExecuteSqlCommand($@"UPDATE dbo.alunogrupo 
                SET Temporario = false, IdAluno = {dto.Id} 
                WHERE IdUsuario = {SessionUser.IdUsuario}
                AND Temporario = true");
            Contexto.Database.ExecuteSqlCommand($@"DELETE FROM dbo.alunoespecialidade 
                WHERE IdUsuario = {SessionUser.IdUsuario} AND 
                (Esconder = true OR Excluir = true);");
            Contexto.Database.ExecuteSqlCommand($@"DELETE FROM dbo.alunogrupo 
                WHERE IdUsuario = {SessionUser.IdUsuario} AND 
                (Esconder = true OR Excluir = true);");

            Contexto.SaveChanges();

            return(true);
        }
        public ArmazenadorDeAlunoTest()
        {
            var _fake = new Faker();
            var _dta  = _fake.Date.Past();

            _alunoDto = new AlunoDto
            {
                Nome        = _fake.Person.FullName,
                Email       = _fake.Person.Email,
                Cpf         = _fake.Person.Cpf(),
                PublicoAlvo = PublicoAlvo.Empreendedor.ToString(),
                DataNasc    = _dta.ToString("dd/MM/yyyy")
            };

            _alunoRepositorio       = new Mock <IAlunoRepositorio>();
            _conversorDePublicoAlvo = new Mock <IConversorDePublicoAlvo>();
            _armazenadorDeAluno     = new ArmazenadorDeAluno(_alunoRepositorio.Object, _conversorDePublicoAlvo.Object);
        }
Exemple #21
0
        public IActionResult Patch(int id, AlunoDto model)
        {
            var aluno = _repo.GetAlunoById(id);

            if (aluno == null)
            {
                return(BadRequest("Aluno não encontrado"));
            }

            _mapper.Map(model, aluno);
            _repo.Update(aluno);
            if (_repo.SaveChanges())
            {
                return(Created($"/api/aluno/{model.Id}", _mapper.Map <AlunoDto>(aluno)));
            }

            return(BadRequest("Aluno não atualizado"));
        }
        public void Inserir(AlunoDto aluno)
        {
            //var listaAluno = ListarAlunos();
            //var maxId = listaAluno.Max(x => x.Id) + 1;
            //aluno.Id = maxId;
            //listaAluno.Add(aluno);
            //ReescreverArquivo(listaAluno);
            //return aluno;

            try
            {
                new AlunoDAO().InserirAlunoDb(aluno);
            }
            catch (Exception ex)
            {
                throw new Exception($"Erro ao inserir alunos. Erro => {ex.Message} ");
            }
        }
Exemple #23
0
        public dynamic Atualizar(AlunoFiltroDto alunoFiltro)
        {
            AlunoDto aluno = alunoFiltro.aluno;
            IEnumerable <FiltroDto> filtros = alunoFiltro.filtros;

            try
            {
                var pAluno   = _mapper.Map <AlunoDominio>(aluno);
                var pFiltros = _mapper.Map <IEnumerable <FiltroDominio> >(filtros);
                _servico.Atualizar(pAluno, pFiltros);

                return(new { Resultado = "Sucesso" });
            }
            catch (Exception e)
            {
                return(new { Resultado = "Erro", Erro = e.Message });
            }
        }
Exemple #24
0
        // POST: api/Alunos
        public IHttpActionResult Post(AlunoDto aluno)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var alunos = new Alunos();
                alunos.Inserir(aluno);
                return(Ok(alunos.ListarAlunos(null)));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Exemple #25
0
        public bool SaveAluno(AlunoDto dto)
        {
            var retorno = Contexto.Aluno.Add(new Aluno()
            {
                Nome           = dto.Nome,
                Sexo           = dto.Sexo,
                DataNascimento = Convert.ToDateTime(dto.DescricaoDataNascimento),
                Telefone       = dto.Telefone,
                Celular        = dto.Celular,
                Email          = dto.Email,
                Matricula      = dto.Matricula,
                Semestre       = dto.Semestre,
                CPF            = dto.CPF,
                Ativo          = dto.Ativo,
                IdResponsavel  = dto.IdResponsavel,
                Usuario        = new Usuario()
                {
                    UsuarioLogin    = dto.Usuario,
                    Senha           = GerarMD5(dto.Senha),
                    IdPapelUsuario  = PapelUsuarioEnum.Aluno,
                    IdStatusUsuario = StatusUsuarioEnum.Offline
                }
            });

            Contexto.SaveChanges();

            Contexto.Database.ExecuteSqlCommand($@"UPDATE dbo.alunoespecialidade 
                SET Temporario = false, IdAluno = {retorno.Id} 
                WHERE IdUsuario = {SessionUser.IdUsuario} AND IdAluno IS NULL
                AND Temporario = true");
            Contexto.Database.ExecuteSqlCommand($@"UPDATE dbo.alunogrupo 
                SET Temporario = false, IdAluno = {retorno.Id} 
                WHERE IdUsuario = {SessionUser.IdUsuario} AND IdAluno IS NULL
                AND Temporario = true");
            Contexto.Database.ExecuteSqlCommand($@"DELETE FROM dbo.alunoespecialidade 
                WHERE IdUsuario = {SessionUser.IdUsuario} AND 
                (Esconder = true OR Excluir = true);");
            Contexto.Database.ExecuteSqlCommand($@"DELETE FROM dbo.alunogrupo 
                WHERE IdUsuario = {SessionUser.IdUsuario} AND 
                (Esconder = true OR Excluir = true);");

            return(true);
        }
Exemple #26
0
        public List <AlunoDto> ListarAlunosDb(int?id)
        {
            //string stringConexao = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\Desenv\Estudos\DotNet\CursoWebApi_Udemy\fabiostefani.io.WebApp\fabiostefani.io.WebApp.Api\App_Data\Database.mdf;Integrated Security=True";
            //string stringConexao = ConfigurationManager.AppSettings["ConnectionString"];
            var listaAlunos = new List <AlunoDto>();

            try
            {
                var selectCmd = conexao.CreateCommand();
                selectCmd.CommandText = "select * from alunos";
                if (id != null)
                {
                    selectCmd.CommandText = $"select * from alunos where id = {id}";
                }

                var resultado = selectCmd.ExecuteReader();


                while (resultado.Read())
                {
                    var aluno = new AlunoDto
                    {
                        Id        = Convert.ToInt32(resultado["Id"]),
                        Nome      = Convert.ToString(resultado["Nome"]),
                        Sobrenome = Convert.ToString(resultado["Sobrenome"]),
                        Telefone  = Convert.ToString(resultado["Telefone"]),
                        Ra        = Convert.ToInt32(resultado["Ra"])
                    };
                    listaAlunos.Add(aluno);
                }
                conexao.Close();
                return(listaAlunos);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                conexao.Close();
            }
        }
Exemple #27
0
        public IActionResult Put(int id, AlunoDto model)
        {
            var aluno = _baseRepository.GetAlunoById(id);

            if (aluno == null)
            {
                return(BadRequest("Aluno não foi encontrado"));
            }

            _mapper.Map(model, aluno);

            _baseRepository.Update(aluno);
            if (_baseRepository.SaveChanges())
            {
                return(Created($"/api/aluno/{model.Id}", _mapper.Map <AlunoDto>(aluno)));
            }

            //Falhou
            return(BadRequest("Aluno não foi atualizado"));
        }
        public async Task <IActionResult> EditarAluno(AlunoDto alunoDto)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var retorno = await _alunoService.EditAluno(alunoDto);

                    return(Ok(retorno));
                }
                else
                {
                    return(BadRequest(ModelState));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Exemple #29
0
        public IActionResult Criar([FromBody] AlunoDto dto)
        {
            var aluno = new Aluno(dto.Nome, dto.Email);

            if (dto.Curso1 != null && dto.Curso1Grade != null)
            {
                var curso = _cursoRepositorio.RecuperarPorNome(dto.Curso1);
                aluno.Inscrever(curso, Enum.Parse <Grade>(dto.Curso1Grade));
            }

            if (dto.Curso2 != null && dto.Curso2Grade != null)
            {
                var curso = _cursoRepositorio.RecuperarPorNome(dto.Curso2);
                aluno.Inscrever(curso, Enum.Parse <Grade>(dto.Curso2Grade));
            }

            _alunoRepositorio.Salvar(aluno);
            _unitOfWork.Commit();

            return(Ok());
        }
        public void Armazenar(AlunoDto alunoDto)
        {
            var alunoComMesmoCpf = _alunoRepositorio.ObterPeloCpf(alunoDto.Cpf);

            ValidadorDeRegra.Novo()
            .Quando(alunoComMesmoCpf != null && alunoComMesmoCpf.Id != alunoDto.Id, Resource.CPF_EXISTENTE)
            //.Quando(!Enum.TryParse<EPublicoAlvo>(alunoDto.PublicoAlvo, out var publicoAlvoConvertido), Resource.PUBLICO_ALVO_INVALIDO)
            .DispararExcecaoSeExistir();

            if (alunoDto.Id == 0)
            {
                var publicoAlvoConvertido = _conversorDePublicoAlvo.Converter(alunoDto.PublicoAlvo);
                var aluno = new Aluno(alunoDto.Nome, alunoDto.Email, alunoDto.Cpf, publicoAlvoConvertido);
                _alunoRepositorio.Adicionar(aluno);
            }
            else
            {
                var aluno = _alunoRepositorio.ObterPorId(alunoDto.Id);
                aluno.AlterarNome(alunoDto.Nome);
            }
        }