public ActionResult Create(WalksFormModel res) { try { foreach (int id in res.SelectedDogs) { res.Walks.DogId = id; _walksRepo.AddWalks(res.Walks); } return(RedirectToAction("Index", "Walker")); } catch { List <Dog> Dogs = _dogRepo.GetAllDogs(); WalksFormModel wfm = new WalksFormModel() { Walks = res.Walks, Owners = _ownerRepo.GetAllOwners(), Dogs = Dogs.Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.Name }) }; return(View(wfm)); } }
// GET: WalksController/Create public ActionResult Create(int neighborhoodId) { List <Dog> allDogs = _dogRepo.GetDogsInNeighborhood(neighborhoodId); WalksFormModel wfm = new WalksFormModel() { Walks = new Walks(), Owners = _ownerRepo.GetOwnersInNeighborhood(neighborhoodId), Dogs = allDogs.Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.Name }) }; return(View(wfm)); }