예제 #1
0
        public IComandResult Handle(AlterarFuncionarioCommands comand)
        {
            var _r = new List <string>();

            //verificar se tem notificação no comand
            if (!comand.IsValid())
            {
                return(new ComandResult(false, "Por favor corrija os campos abaixo", comand.Notifications));
            }

            var funcionario = _repository.Existe(comand.Id);

            if (funcionario != null)
            {
                funcionario.Alterar(comand.Nome.ToUpper(), comand.SobreNome.ToUpper(), comand.DataNascimento, comand.Sexo, comand.Nacionalidade, comand.Natural);
                funcionario.SetarCelular(comand.Celular);
                funcionario.SetarEmail(comand.Email);
                funcionario.SetarRgCpf(comand.Rg, comand.Cpf);
                funcionario.SetarTelefoneFixo(comand.TelefoneFixo);


                var r = _repository.Alterar(funcionario);

                var dadoPessoal = _dadoPessoalRepositorio.BuscarPorId(comand.DadoPessoalId);

                if (dadoPessoal != null)
                {
                    dadoPessoal.Alterar(comand.Rua, comand.Numero, comand.Bairro, comand.Uf, comand.Cidade, comand.Cep, comand.Complemento);
                    _dadoPessoalRepositorio.Alterar(dadoPessoal);
                }

                var _usuario = _usuarioRepositorio.Existe(funcionario.UsuarioId);

                if (_usuario != null)
                {
                    _usuario.SetarTipoUsuario(comand.TipoUsuario);
                    _usuarioRepositorio.Alterar(_usuario);
                }
            }
            else
            {
                return(new ComandResult(false, "Funcionário não existe,tente novamente!!", new { _r }));
            }

            return(new ComandResult(true, "Dados Alterados com Sucesso!!", new { _r }));
        }
        public IComandResult Turma(IFormFile upload)
        {
            if (upload != null && upload.Length > 0)
            {
                // ExcelDataReader works with the binary Excel file, so it needs a FileStream
                // to get started. This is how we avoid dependencies on ACE or Interop:
                Stream stream = upload.OpenReadStream();

                // We return the interface, so that
                IExcelDataReader reader = null;


                if (upload.FileName.EndsWith(".xls"))
                {
                    reader = ExcelDataReader.ExcelReaderFactory.CreateBinaryReader(stream);
                }
                else if (upload.FileName.EndsWith(".xlsx"))
                {
                    reader = ExcelReaderFactory.CreateOpenXmlReader(stream);
                }
                else
                {
                    return(new ComandResult(false, "Arquivo não suportado!!", new { }));
                }

                var result = reader.AsDataSet(new ExcelDataSetConfiguration()
                {
                    ConfigureDataTable = (_) => new ExcelDataTableConfiguration()
                    {
                        UseHeaderRow = true
                    }
                });

                // reader.IsFirstRowAsColumnNames = true;

                //DataSet result = reader.AsDataSet();
                reader.Close();

                var tblAuthors = result.Tables[0];



                foreach (DataRow drCurrent in tblAuthors.Rows)
                {
                    var salvar = new SalvarTurmaCommands();

                    salvar.Ensino            = drCurrent["ENSINO"].ToString();
                    salvar.Periodo           = drCurrent["PERIODO"].ToString();
                    salvar.NomeCoordenador   = drCurrent["COORDENADOR"].ToString();
                    salvar.NomeDiretor       = drCurrent["DIRETOR"].ToString();
                    salvar.QtdAulas1Bimestre = Convert.ToInt32(drCurrent["QTDAULAS1BIMESTRE"].ToString());
                    salvar.QtdAulas2Bimestre = Convert.ToInt32(drCurrent["QTDAULAS2BIMESTRE"].ToString());
                    salvar.QtdAulas3Bimestre = Convert.ToInt32(drCurrent["QTDAULAS3BIMESTRE"].ToString());
                    salvar.QtdAulas4Bimestre = Convert.ToInt32(drCurrent["QTDAULAS4BIMESTRE"].ToString());

                    var serieId        = _serieRepositorio.Existe(drCurrent["SERIE"].ToString());
                    var anoId          = _anoRepositorio.Existe(drCurrent["ANO"].ToString());
                    var funcionarioId  = _funcionarioRepositorio.Existe(drCurrent["PROFESSOR"].ToString());
                    var departamentoId = _departamentoRepositorio.Existe(drCurrent["DEPARTAMENTO"].ToString());
                    var escolaId       = _escolaRepositorio.Existe(drCurrent["ESCOLA"].ToString());

                    if (serieId == null)
                    {
                        return(new ComandResult(false, "SerieId não encontrado!!" + drCurrent["SERIE"].ToString(), new { }));
                    }
                    if (anoId == null)
                    {
                        return(new ComandResult(false, "anoId não encontrado!!" + drCurrent["ANO"].ToString(), new { }));
                    }
                    if (funcionarioId == null)
                    {
                        return(new ComandResult(false, "funcionarioId não encontrado!!" + drCurrent["PROFESSOR"].ToString(), new { }));
                    }
                    if (departamentoId == null)
                    {
                        return(new ComandResult(false, "departamentoId não encontrado!!" + drCurrent["DEPARTAMENTO"].ToString(), new { }));
                    }
                    if (escolaId == null)
                    {
                        return(new ComandResult(false, "escolaId não encontrado!!" + drCurrent["ESCOLA"].ToString(), new { }));
                    }

                    salvar.SerieId        = serieId.Id.ToString();
                    salvar.AnoId          = anoId.Id.ToString();
                    salvar.FuncionarioId  = funcionarioId.Id.ToString();
                    salvar.EscolaId       = escolaId.Id.ToString();
                    salvar.DepartamentoId = departamentoId.Id.ToString();
                    var user = Guid.Parse(this.User.Identity.Name);

                    if (user == null)
                    {
                        return(new ComandResult(false, "Usuario não encontrado!!", new { }));
                    }
                    salvar.SetarUsuarioId(user.ToString());
                    //var user = Guid.Parse("781503e9-272b-4251-8fdf-77aca5f2d57a");


                    _turmaHandler.Handle(salvar);
                }

                this.Commit(true);

                return(new ComandResult(true, "Adicionado com sucesso", new { }));
            }
            else
            {
                return(new ComandResult(false, "Arquivo não encontrado!!", new { }));
            }
        }