コード例 #1
0
        public IActionResult Create()
        {
            var viewModel = new CreateUpdatePetViewModel()
            {
                Owners = _context.Owners.ToList(),
                Pet    = new Pet()
            };

            return(View(viewModel));
        }
コード例 #2
0
        public IActionResult Update(int?id)
        {
            var viewModel = new CreateUpdatePetViewModel()
            {
                Pet    = _context.Pets.Find(id),
                Owners = _context.Owners.ToList()
            };


            return(View(viewModel));
        }
コード例 #3
0
        public IActionResult Create(CreateUpdatePetViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            _context.Pets.Add(viewModel.Pet);
            _context.SaveChanges();

            return(View("Created", viewModel.Pet));
        }