public Setor(SetorPutDto setorPutDto, SetorViewDto viewDto) { Id = viewDto.Id; IncSetor = viewDto.IncSetor; Nome = setorPutDto.Nome; Coordenacao = setorPutDto.Coordenacao; }
public async Task <ActionResult> ExcluirSetor(Guid setorId) { if (!ModelState.IsValid) { return(CustomResponse(ModelState)); } SetorViewDto viewDto = await _setorService.PesquisarSetorPorIdAsync(setorId); if (viewDto == null) { return(NotFound(new { success = true, status = 404, mensagem = "O setor informado não foi encontrado!", })); } await _setorService.ExcluirSetorAsync(setorId); return(CustomResponse(new { mensagem = "O setor foi excluído com sucesso!", })); }
public async Task <ActionResult> EditarSetor(Guid setorId, [FromBody] SetorPutDto setorPutDto) { if (!ModelState.IsValid) { return(CustomResponse(ModelState)); } if (setorId != setorPutDto.Id) { NotificarErro("Id da request diferente do Id da Entidade!"); return(CustomResponse(setorPutDto)); } SetorViewDto viewDto = await _setorService.PesquisarSetorPorIdAsync(setorId); if (viewDto == null) { return(NotFound(new { success = true, status = 404, mensagem = "O setor informado não foi encontrado!", })); } await _setorService.EditarSetorAsync(setorPutDto, viewDto); return(CustomResponse(new { Inc = setorPutDto.IncSetor, mensagem = "O setor foi editado com sucesso!", })); }
public async Task <bool> EditarSetorAsync(SetorPutDto setorPutDto, SetorViewDto viewDto) { // validação domínio if (!ExecutarValidacao(new SetorPutDtoValidation(), setorPutDto)) { return(false); } Setor setor = new Setor(setorPutDto, viewDto); await _setorRepository.EditarAsync(setor); return(true); }
public async Task <ActionResult> CadastrarSetor([FromBody] SetorPostDto setorPostDto) { if (!ModelState.IsValid) { return(CustomResponse(ModelState)); } await _setorService.CadastrarSetorAsync(setorPostDto); SetorViewDto viewDto = await _setorService.PesquisarSetorPorIdAsync(setorPostDto.Id); return(CustomResponse(new { Inc = viewDto.IncSetor, mensagem = "O setor foi cadastrado com sucesso!", })); }
public async Task <ActionResult> PesquisarSetorPorInc(int incSetor) { if (!ModelState.IsValid) { return(CustomResponse(ModelState)); } SetorViewDto viewDto = await _setorService.PesquisarSetorPorIncAsync(incSetor); if (viewDto == null) { return(NotFound(new { success = true, status = 404, mensagem = "O setor informado não foi encontrado!", })); } return(CustomResponse(viewDto)); }
public async Task <SetorViewDto> PesquisarSetorPorIncAsync(int incSetor) { try { SetorViewDto result = await _context.Setores .Where(set => set.IncSetor == incSetor) .DefaultIfEmpty() .Select(set => new SetorViewDto { Id = set.Id, IncSetor = set.IncSetor, Nome = set.Nome, Coordenacao = set.Coordenacao, DescricaoSetor = set.IncSetor + " - " + set.Nome, }).SingleAsync(); return(result); } catch (Exception ex) { throw ex; } }
public async Task <SetorPaginacaoViewtDto> PesquisarSetoresPorFiltrosPaginacaoAsync(SetorFiltroDto filtroDto) { try { SetorPaginacaoViewtDto paginacaoViewDto = new SetorPaginacaoViewtDto(); filtroDto.RegistroInicial = filtroDto.RegistroInicial <= 1 ? 0 : filtroDto.RegistroInicial - 1; string query = @"SELECT SQL_CALC_FOUND_ROWS DISTINCT * FROM Setor AS seto WHERE 1 = 1"; if (!string.IsNullOrEmpty(filtroDto.IncSetor)) { query = query + $" AND seto.Inc_Setor = {int.Parse(filtroDto.IncSetor)}"; } if (!string.IsNullOrEmpty(filtroDto.Nome)) { query = query + $" AND seto.Nome LIKE '%{filtroDto.Nome}%'"; } if (!string.IsNullOrEmpty(filtroDto.Coordenacao)) { query = query + $" AND seto.Coordenacao LIKE '%{filtroDto.Coordenacao}%'"; } query = query + " ORDER BY seto.Nome"; // LIMIT RegistroInicial,QtdRegistroPorPagina; query = query + $" LIMIT {filtroDto.RegistroInicial},{filtroDto.QtdRegistroPorPagina}"; string queryTotalRegitrosEncontrados = "SELECT FOUND_ROWS() AS totalRegistros"; var connection = _context.Database.GetDbConnection(); using (var command = connection.CreateCommand()) { await connection.OpenAsync(); command.CommandText = query; using (var dataReader = await command.ExecuteReaderAsync()) { if (dataReader.HasRows) { while (dataReader.Read()) { // Registros.: SetoresViewDto[] SetorViewDto viewDto = new SetorViewDto(); viewDto.Id = Guid.Parse(dataReader["Id"].ToString()); viewDto.IncSetor = int.Parse(dataReader["Inc_Setor"].ToString()); viewDto.Nome = dataReader["Nome"].ToString(); viewDto.Coordenacao = dataReader["Coordenacao"].ToString(); viewDto.DescricaoSetor = dataReader["Inc_Setor"].ToString() + " - " + dataReader["Nome"].ToString(); paginacaoViewDto.listaSetorViewDto.Add(viewDto); } } } command.CommandText = queryTotalRegitrosEncontrados; using (var dataReader = command.ExecuteReader()) { if (dataReader.HasRows) { while (dataReader.Read()) { // Total Registros.: TotalRegistros paginacaoViewDto.TotalRegistros = int.Parse(dataReader["totalRegistros"].ToString());; } } } connection.Close(); } paginacaoViewDto.preencherDadosPaginacao(filtroDto.QtdRegistroPorPagina, filtroDto.RegistroInicial); return(paginacaoViewDto); } catch (Exception ex) { throw ex; } }