Esempio n. 1
0
        public void OnPost(string idDoProjeto)
        {
            if (ErroAoPreencherCampos())
            {
                CarregarProjeto(idDoProjeto);
                return;
            }

            if (Arquivo is null)
            {
                var url = Request.Form["url"];
                _treinamento.AdicionarImagemPorUrl(idDoProjeto, url, Tags);
            }
            else
            {
                var pasta = Path.Combine(_environment.ContentRootPath, "imagens");
                if (!Directory.Exists(pasta))
                {
                    Directory.CreateDirectory(pasta);
                }

                var caminhoDoArquivo = Path.Combine(_environment.ContentRootPath, "imagens", Arquivo.FileName);

                using (var fileStream = new FileStream(caminhoDoArquivo, FileMode.Create))
                    Arquivo.CopyTo(fileStream);

                _treinamento.AdicionarImagemPorArquivo(idDoProjeto, caminhoDoArquivo, Tags);

                Directory.Delete(pasta, true);
            }

            CarregarProjeto(idDoProjeto);

            MensagemFotos = "Imagem adicionada com sucesso!";

            if (!_treinamento.Treinar(idDoProjeto, TagsDoProjeto))
            {
                ErroTreinamento     = true;
                MensagemTreinamento = "Porém, não é possível TREINAR o modelo sem que TODAS as tags tenham, ao menos, 5 fotos cada.";
                return;
            }

            MensagemTreinamento = "Treinamento realizado com sucesso!";
        }
Esempio n. 2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Bazar).State = EntityState.Modified;

            try
            {
                if (Arquivo?.Length > 0)
                {
                    var extensao    = Path.GetExtension(Arquivo.FileName);
                    var nomeArquivo = Path.Combine(_ambiente.WebRootPath, "bazares", Bazar.Id + extensao);
                    using (var stream = new FileStream(nomeArquivo, FileMode.Create))
                    {
                        Arquivo.CopyTo(stream);
                        stream.Close();
                        Bazar.Logotipo = Bazar.Id + extensao;
                    }
                }

                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BazarExists(Bazar.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Edit", new { Id = Bazar.Id }));
        }