コード例 #1
0
        public IComandResult SalvarAluno([FromBody] SalvarItemAlunoTurmaCommands command)
        {
            // var user = this.User.Identity.Name;
            //var user = Guid.Parse("781503e9-272b-4251-8fdf-77aca5f2d57a");
            //command.SetarUsuarioId(user);
            var result = (ComandResult)_itemTurmaHandler.Handle(command);

            this.Commit(result.Success);
            return(result);
        }
コード例 #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 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 { }));
            }
        }