public ActionResult SubmitPublication(Publication publication)
 {
     if (Publication.Create(publication))
     {
         return(RedirectToAction("CanalPublication", "Canal", new { id = publication.IdCanal, message = "Publication ajoutée" }));
     }
     else
     {
         return(RedirectToAction("CanalPublication", "Canal", new { id = publication.IdCanal, messageError = "Echec de la création de la publication" }));
     }
 }
예제 #2
0
        public IActionResult Publicar(IFormCollection form)
        {
            Publication newPub = new Publication();

            newPub.IdPublication = pubModels.idGPublication();
            newPub.Subtitle      = form["Subtitle"];
            newPub.Image         = form["Image"];


            // Inicio uploud
            if (form.Files.Count > 0)
            {
                //Se sim,
                //Armazenamos o arquivo na variável file
                var file   = form.Files[0];
                var folder = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/img/Posts");

                // Verificamos se a pasta Equipes não existe
                if (!Directory.Exists(folder))
                {
                    Directory.CreateDirectory(folder);
                }

                //localhost:5001           +        + Equipes + equipe.jpg
                var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/img/", folder, file.FileName);

                using (var stream = new FileStream(path, FileMode.Create))
                {
                    // Salvamos o arquivo no caminho especificado
                    file.CopyTo(stream);
                }
                newPub.Image = file.FileName;
            }


            // Uploud termino
            newPub.Subtitle = form["Subtitle"];



            // Chamamos o método Create para salvar
            // a novaEquipe no CSV
            pubModels.Create(newPub);


            return(LocalRedirect("~/Feed"));
        }