public async Task <IEnumerable <Autor> > Post(IFormFile file)
        {
            // full path to file in temp location
            var content = new StringBuilder();

            content.AppendLine("tipo: " + Path.GetExtension(file.FileName));

            List <Autor> lista = new List <Autor>();

            using (var reader = new StreamReader(file.OpenReadStream()))
                using (var csv = new CsvReader(reader,
                                               System.Globalization.CultureInfo.CreateSpecificCulture("PT")))
                {
                    var records = csv.GetRecords <Autor>();
                    //Encoding iso = Encoding.GetEncoding("ISO-8859-6");
                    lista = records.ToList();
                    //return lista;
                }

            foreach (Autor autor in lista)
            {
                if (autor.Name == null || !Regex.IsMatch(autor.Iupi, "[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}") || !Regex.IsMatch(autor.OrcidId, "[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{4}"))
                {
                    return(null);//BadRequest();
                }

                if (autor.Name != "" || autor.OrcidId != "" || autor.Iupi != "")
                {
                    DatabaseServices.insertLoginPerson(_context, autor.Name, autor.OrcidId, autor.Iupi);
                    PublicacoesService.GetDifWorks(_context, autor.Name,
                                                   PublicacoesService.ConvertProductToWork(
                                                       PublicacoesService.GetProducts(_context, autor.Iupi, autor.Name)), autor.Iupi, MVC_2020_Business.Services.DatabaseServices.getOrcid(_context, autor.Iupi));
                }
            }

            //string text;
            //using (TextReader textReader = new StreamReader(file.OpenReadStream()))
            //    text = textReader.ReadToEnd();

            return(lista);

            //CsvReader csv;
            //using (var ms = new MemoryStream())
            //{
            //    file.CopyTo(ms);
            //    var fileBytes = ms.ToArray();
            //    string s = Convert.ToBase64String(fileBytes);
            //    // act on the Base64 data
            //    using (var textReader2 = new StreamReader(s))
            //        csv = new CsvReader(textReader2, System.Globalization.CultureInfo.CreateSpecificCulture("PT"));
            //    var records = csv.GetRecords<Autor>().ToList();
            //    return records;
            //}
        }
        //[SwaggerOperationFilter(typeof(Api.ReApplyOptionalRouteParameterOperationFilter))]
        public async Task <IActionResult> PutPublication([FromRoute] string nome, [FromRoute] string iupi, [FromRoute] string?orcidId = null)
        {
            if (nome == null || !Regex.IsMatch(iupi, "[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}") || !Regex.IsMatch(orcidId, "[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{4}"))
            {
                return(BadRequest());
            }

            //nao funciona
            if (orcidId == null || orcidId == ",")
            {
                //https://ws-id.ua.pt/api/orcid/####################
                //https://ws-id.ua.pt/api/orcid/####################
                string req    = "https://ws-id.ua.pt/api/orcid/" + iupi;
                var    client = new RestClient(req);
                client.Timeout = -1;
                var request = new RestRequest(Method.GET);
                request.AddHeader("Authorization", "Basic Y3JpczprdWhrMzI0MjMkJCEzNDUkRVJHVEVSLjM0");
                IRestResponse response = client.Execute(request);
                orcidId = response.Content;
            }


            try
            {
                DatabaseServices.insertLoginPerson(_context, nome, orcidId, iupi);
                PublicacoesService.GetDifWorks(_context, nome,
                                               PublicacoesService.ConvertProductToWork(
                                                   PublicacoesService.GetProducts(_context, iupi, nome)), iupi, MVC_2020_Business.Services.DatabaseServices.getOrcid(_context, iupi));
            }
            catch (Exception e)
            {
                throw;
            }

            return(Ok());


            //try
            //{
            //    await _context.SaveChangesAsync();
            //}
            //catch (DbUpdateConcurrencyException)
            //{
            //    if (!PublicationExists(id))
            //    {
            //        return NotFound();
            //    }
            //    else
            //    {
            //        throw;
            //    }
            //}
        }
Beispiel #3
0
        public IActionResult Publicacoes(string import, string ORCID_source, string Authenticus_source)
        {
            if (ORCID_source == "ORCID" /*&& import == "True"*/) // Fonte de dados - ORCID
            {
                ViewBag.dataSource = "ORCID";

                //ViewBag.PublicacoesRIA = PublicacoesService.GetProducts(_db, Session.IUPI.ToString());
                //ViewBag.PublicacoesOrcid = PublicacoesService.GetWorksFromXml();
                ViewBag.PublicacoesPTCris = PublicacoesService.GetDifWorks(_db, nome,
                                                                           PublicacoesService.ConvertProductToWork(
                                                                               PublicacoesService.GetProducts(_db, iupi, nome)), iupi, MVC_2020_Business.Services.DatabaseServices.getOrcid(_db, iupi));
                ViewBag.worksInBD = MVC_2020_Business.Services.DatabaseServices.selectToRIA(_db, MVC_2020_Business.Services.DatabaseServices.select(_db, "Publication", "State", "1", orcid), iupi);


                ViewBag.import = import;
            }
            else if (Authenticus_source == "Authenticus") // Fonte de dados - Authenticus
            {
                ViewBag.dataSource = "Authenticus";
            }

            return(View());
        }