Exemplo n.º 1
0
        public IComandResult Handle(SalvarAlunoCommands comand)
        {
            //verificar se tem notificação no comand
            if (!comand.IsValid())
            {
                return(new ComandResult(false, "Por favor corrija os campos abaixo", comand.Notifications));
            }

            var alunoJaexiste = _repository.AlunoJaExiste(comand.Ra, comand.Rm);

            if (alunoJaexiste != null)
            {
                return(new ComandResult(false, "Aluno já está cadastrado!!", new { }));
            }

            var dadoPessoal = new DadoPessoal(comand.Rua, comand.Numero, comand.Bairro, comand.Uf, comand.Cidade, comand.Cep, comand.Complemento);

            var ret = _dadoPessoalRepositorio.Salvar(dadoPessoal);

            var aluno = new Aluno(comand.Nome, comand.SobreNome, comand.DataNascimento, comand.Sexo, comand.Nacionalidade, comand.Natural, ret.Id, comand.Ra, comand.Rm, comand.RacaCor, comand.Gemeos, comand.UsuarioId);

            _repository.Salvar(aluno);

            return(new ComandResult(true, "Dados Salvos com Sucesso!!", new { }));
        }
        public IComandResult Funcionario(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 SalvarItemAlunoTurmaCommands();


                    var alunoId = _alunoRepositorio.AlunoJaExiste(drCurrent["RM"].ToString());
                    var serieId = _serieRepositorio.Existe(drCurrent["SERIE"].ToString());
                    var numero  = drCurrent["NUMERO"].ToString();

                    if (alunoId == null)
                    {
                        return(new ComandResult(false, "alunoId não encontrado!!" + drCurrent["RM"].ToString(), new { }));
                    }

                    if (serieId == null)
                    {
                        return(new ComandResult(false, "serieId não encontrado!!" + drCurrent["SERIE"].ToString(), new { }));
                    }
                    else
                    {
                        var turmaId = _turmaRepositorio.ExistePorSerie(serieId.Id);

                        if (turmaId == null)
                        {
                            return(new ComandResult(false, "turmaId não encontrado!!" + drCurrent["SERIE"].ToString(), new { }));
                        }

                        salvar.TurmaId = turmaId.Id.ToString();
                    }

                    if (numero == null)
                    {
                        return(new ComandResult(false, "numero não encontrado!!" + drCurrent["NUMERO"].ToString(), new { }));
                    }

                    salvar.AlunoId = alunoId.Id.ToString();
                    salvar.Numero  = Convert.ToInt32(numero);

                    var existe = _itemAlunoTurmaRepositorio.Existe(Guid.Parse(salvar.AlunoId), Guid.Parse(salvar.TurmaId));

                    if (existe == null)
                    {
                        _itemAlunoTurmaHandler.Handle(salvar);

                        this.Commit(true);
                    }
                }

                this.Dispose();

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