Пример #1
0
        public async Task <IActionResult> Create([Bind("ProfessorId,Nome,Foto,Telefone,Turno")] Professor professor, IFormFile arquivo)
        {
            if (ModelState.IsValid)
            {
                var linkUpload = Path.Combine(_hostingEnvironment.WebRootPath, "Imagens");

                if (arquivo != null)
                {
                    using var fileStream = new FileStream(Path.Combine(linkUpload, arquivo.FileName), FileMode.Create);
                    await arquivo.CopyToAsync(fileStream);

                    professor.Foto = "~/Imagens/" + arquivo.FileName;
                }

                await _professorRepositorio.Inserir(professor);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(professor));
        }