public ActionResult Attach(LocationSelector selector) { Frame frame = db.Frames.Find(selector.FrameId); if (frame == null) { return View("Missing", new MissingItem(selector.FrameId)); } if (selector.LocationId > 0) { Location location = db.Locations.Find(selector.LocationId); if (location == null) { return View("Missing", new MissingItem(selector.LocationId, "Location")); } frame.Locations.Add(location); db.SaveChanges(); return this.RestoreReferrer() ?? RedirectToAction("Index"); } IEnumerable<Location> locations = db.Locations .Where(l => !db.Frames .FirstOrDefault(f => f.FrameId == selector.FrameId) .Locations.Any(fl => fl.LocationId == l.LocationId)) ; ViewBag.Locations = new SelectList(db.Locations, "LocationId", "Name"); return View(selector); }
// // GET: /Frame/Attach/5 public ActionResult Attach(int id = 0) { Frame frame = db.Frames.Find(id); if (frame == null) { return View("Missing", new MissingItem(id)); } LocationSelector selector = new LocationSelector { FrameId = id, }; var locations = db.Locations .Where(l => !db.Frames .FirstOrDefault(f => f.FrameId == selector.FrameId) .Locations.Any(fl => fl.LocationId == l.LocationId)) .Include(l => l.Level) .Select(l => new { LocationId = l.LocationId, Name = l.Level.Name + " : " + l.Name }) .OrderBy(l => l.Name) .ToList() ; ViewBag.Locations = new SelectList(locations, "LocationId", "Name"); return View(selector); }
// // GET: /Frame/Detach/5 public ActionResult Detach(int id = 0, int locationId = 0) { Frame frame = db.Frames.Find(id); if (frame == null) { return View("Missing", new MissingItem(id)); } LocationSelector selector = new LocationSelector { FrameId = id, LocationId = locationId, LocationName = db.Locations.Find(locationId).Name, }; return View(selector); }