Beispiel #1
0
        public IComandResult Post([FromBody] SalvarFuncionarioCommands command)
        {
            var user = Guid.Parse(this.User.Identity.Name);

            //var user = Guid.Parse("bfbed547-0e0c-4c3c-86cc-4e92cd0fd1c8");
            command.SetarUsuarioId(user);
            var result = (ComandResult)_funcionarioHandler.Handle(command);

            this.Commit(result.Success);
            return(result);
        }
Beispiel #2
0
        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 SalvarFuncionarioCommands();

                    var Nome = drCurrent["Nome"].ToString();
                    salvar.FuncaoId      = drCurrent["FuncaoId"].ToString();
                    salvar.Cpf           = drCurrent["Cpf"].ToString();
                    salvar.Email         = drCurrent["Email"].ToString();
                    salvar.TipoUsuario   = drCurrent["TipoUsuario"].ToString();
                    salvar.Celular       = drCurrent["Celular"].ToString();
                    salvar.Nacionalidade = "brasileira";
                    salvar.Sexo          = drCurrent["Sexo"].ToString();
                    salvar.Uf            = drCurrent["Uf"].ToString();
                    salvar.Cidade        = drCurrent["Cidade"].ToString();
                    salvar.SobreNome     = SobreNome(Nome);
                    salvar.Nome          = PrimeiroNome(Nome);

                    //salvar.DataNascimento = Convert.ToDateTime(drCurrent["DataNascimento"].ToString());

                    var user = Guid.Parse(this.User.Identity.Name);
                    //var user = Guid.Parse("781503e9-272b-4251-8fdf-77aca5f2d57a");
                    salvar.SetarUsuarioId(user);

                    _funcionarioHandler.Handle(salvar);
                }

                this.Commit(true);

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