Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("Id,firstName,lastName,birthDate,gender,category")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("Id,Marque,Lot,Date,DateRappel")] Injection injection, int Personne, int Vaccin)
        {
            var personne = await _context.Personnes.FindAsync(Personne);

            injection.Personne = personne;

            var vaccin = await _context.Vaccins.FindAsync(Vaccin);

            injection.Vaccin = vaccin;

            ModelState.Clear();
            TryValidateModel(injection);

            if (ModelState.IsValid)
            {
                _context.Add(injection);
                await _context.SaveChangesAsync();

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

            ViewData["listeDesPersonnes"] = new SelectList(_context.Personnes, "Id", "Nom");
            ViewData["listeDesVaccins"]   = new SelectList(_context.Vaccins, "Id", "Nom");

            return(View(injection));
        }
        public async Task <IActionResult> Create([Bind("Id,date,recall,brand,lot")] Injection injection, int User, int Vaccine)
        {
            var user = await _context.User.FindAsync(User);

            var vaccine = await _context.Vaccine.FindAsync(Vaccine);

            injection.user    = user;
            injection.vaccine = vaccine;

            ModelState.Clear();
            TryValidateModel(injection);

            if (ModelState.IsValid)
            {
                _context.Add(injection);
                await _context.SaveChangesAsync();

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

            ViewData["users"]    = new SelectList(_context.User, "Id", "firstName", "lastName");
            ViewData["vaccines"] = new SelectList(_context.Vaccine, "Id", "name");

            return(View(injection));
        }
        public async Task <IActionResult> Create([Bind("Id,Nom,Prenom,Sexe,DateNaissance,Type")] Vaccinator.Models.Personne personne)
        {
            if (ModelState.IsValid)
            {
                _context.Add(personne);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(personne));
        }
Esempio n. 5
0
        public async Task <IActionResult> Create([Bind("Id,Libelle,Description")] Categorie categorie)
        {
            if (ModelState.IsValid)
            {
                _context.Add(categorie);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(categorie));
        }
        public async Task <IActionResult> Create([Bind("Id,Nom")] Vaccin vaccin)
        {
            if (ModelState.IsValid)
            {
                _context.Add(vaccin);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(vaccin));
        }
Esempio n. 7
0
        public async Task <IActionResult> Create([Bind("Id,TypeVaccin,Marque,NumLot,Date,DateRappel")] Vaccin vaccin, int Personne)
        {
            var personne = await _context.Personne.FindAsync(Personne);

            vaccin.Personne = personne;

            ModelState.Clear();
            TryValidateModel(vaccin);

            if (ModelState.IsValid)
            {
                _context.Add(vaccin);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["listeDesPersonnes"] = new SelectList(_context.Personne, "Id", "Nom");
            return(View(vaccin));
        }
        public async Task <IActionResult> Create([Bind("Id,Lot,Marque,DatePremier,DateRappel")] Injection injection, int Personne, int Vaccin)
        {
            var personne = await _context.Personnes.FindAsync(Personne);

            var vaccin = await _context.Vaccin.FindAsync(Vaccin);

            injection.Personne = personne;
            injection.Vaccin   = vaccin;
            ModelState.Clear();
            TryValidateModel(injection);

            if (ModelState.IsValid)
            {
                _context.Add(injection);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(injection));
        }
        public async Task <IActionResult> Create([Bind("Id,Nom,AnneeDeNaissance")] Chaton chaton, int Categorie)
        {
            //Je vais chercher la catégorie
            var categorie = await _context.Categories.FindAsync(Categorie);

            //SI elle est nulle -> erreur!

            //j'affecte cette catégorie au chaton
            chaton.Categorie = categorie;

            //je force la réévaluation du modelstate
            ModelState.Clear();
            TryValidateModel(chaton);

            if (ModelState.IsValid)
            {
                _context.Add(chaton);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["listeDesCategorie"] = new SelectList(_context.Categories, "Id", "Libelle");
            return(View(chaton));
        }