public ActionResult AddPerformer(long id) { if (!db.Teams.Any(x => x.Id == id)) { return(HttpNotFound()); } var model = new AddPerformerTeamViewModel(); return(View(model)); }
public ActionResult AddPerformer(long id, AddPerformerTeamViewModel model) { var team = db.Teams.Find(id); if (model == null || team == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (!ModelState.IsValid) { return(RedirectToAction("Edit", new { id })); } var performer = db.Users.Find(model.PerformerId); var constained = team.Performers.Any(x => x.Id == model.PerformerId); if (performer != null && !constained) { team.Performers.Add(performer); db.SaveChanges(); } return(RedirectToAction("Edit", new { id })); }