Beispiel #1
0
        public IActionResult Creer([Bind("Nom,Contenu")] RessourceModel ressource, int mid)
        {
            logger.LogDebug($"POST /Ressources/Creer?mid={mid}");

            if (!ModelState.IsValid)
            {
                return(View(ressource));                     // Invalid inputs
            }
            var matiere = context.Matieres.FirstOrDefault(m => m.Id == mid);

            if (matiere == null)
            {
                return(NotFound());
            }

            ressource.Contenu ??= "";
            ressource.Matiere = matiere;
            ressource.Rendu   = markdownParser.Render(ressource.Contenu);
            ressource.Matiere.Ressources.Add(ressource);
            context.Sauvegarder();

            logger.LogInformation("User {user} created ressource \"{ressource}\".", signInManager.Context.User.Identity.Name, ressource.NomComplet);

            return(RedirectToAction("Index", "Matieres", new { id = ressource.MatiereId }));
        }
        public IActionResult Creer([Bind("Nom")] MatiereModel matiere, int cid)
        {
            logger.LogDebug($"POST /Matieres/Creer?cid={cid}");

            if (!ModelState.IsValid)
            {
                return(View(matiere));                     // Invalid inputs
            }
            var classe = context.Classes.FirstOrDefault(c => c.Id == cid);

            if (classe is null)
            {
                return(NotFound());
            }

            matiere.Classe = classe;
            matiere.Classe.Matieres.Add(matiere);
            context.Sauvegarder();

            logger.LogInformation("User {user} created matière \"{matiere}\".", signInManager.Context.User.Identity.Name, matiere.NomComplet);

            return(RedirectToAction("Index", "Classes", new { id = matiere.ClasseId }));
        }