public IComandResult Post([FromBody] SalvarAlunoCommands command) { var user = Guid.Parse(this.User.Identity.Name); //var user = Guid.Parse("781503e9-272b-4251-8fdf-77aca5f2d57a"); command.SetarUsuarioId(user); var result = (ComandResult)_alunoHandler.Handle(command); this.Commit(result.Success); return(result); }
public IComandResult Aluno(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 SalvarAlunoCommands(); var Nome = drCurrent["Nome"].ToString(); salvar.Ra = drCurrent["Ra"].ToString(); salvar.Rm = drCurrent["Rm"].ToString(); salvar.Nacionalidade = drCurrent["Nacionalidade"].ToString(); salvar.RacaCor = drCurrent["RacaCor"].ToString(); salvar.Sexo = drCurrent["Sexo"].ToString(); salvar.Uf = drCurrent["Uf"].ToString(); salvar.Cidade = drCurrent["Cidade"].ToString(); salvar.SobreNome = SobreNome(Nome); salvar.Nome = PrimeiroNome(Nome); salvar.Gemeos = "Não"; 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); _alunoHandler.Handle(salvar); } this.Commit(true); return(new ComandResult(true, "Adicionado com sucesso", new { })); } else { return(new ComandResult(false, "Arquivo não encontrado!!", new { })); } }