示例#1
0
        public async Task <IActionResult> Create([Bind("PetId,Nome,Idade,Raca,Especie,TutorId")] Pet pet)
        {
            if (ModelState.IsValid)
            {
                _context.Add(pet);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["TutorId"] = new SelectList(_context.Tutores, "TutorId", "TutorId", pet.TutorId);
            return(View(pet));
        }
示例#2
0
        public async Task <IActionResult> Create([Bind("TutorId,Nome")] Tutor tutor, [Bind("Cep,Rua,Numero,Complemento")] Endereco endereco)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tutor);
                await _context.SaveChangesAsync();

                endereco.TutorId = tutor.TutorId;
                _context.Add(endereco);
                await _context.SaveChangesAsync();

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