public bool AddLocation(NeighborhoodAddLocation locationToAdd) { var neighborhood = _db.Neighborhoods.Single(n => n.NeighborhoodId == locationToAdd.NeighborhoodId); var location = _db.Locations.Single(n => n.LocationId == locationToAdd.LocationId); neighborhood.Locations.Add(location); return(_db.SaveChanges() == 1); }
public ActionResult AddLocations(NeighborhoodAddLocation locationToAdd) { if (ModelState.IsValid) { _userId = Guid.Parse(User.Identity.GetUserId()); _neighborhoodService = new NeighborhoodService(_userId); _neighborhoodService.AddLocation(locationToAdd); return(RedirectToAction("AddLocations")); // This line is what allows a location to be added without changing the page } ViewBag.LocationId = new SelectList(db.Locations, "LocationId", "Name"); return(View("AddLocations")); }