// GET: players/Create public ActionResult Create() { var vm = new PlayerCreateEditViewModel(); vm.MapSelectList = new SelectList(_uow.Maps.All, nameof(Map.MapId), nameof(Map.MapName)); vm.TeamSelectList = new SelectList(_uow.Teams.All, nameof(Team.TeamId), nameof(Team.TeamName)); // ViewBag.MapId = new SelectList(_uow.Maps.All, "MapId", "MapName"); // ViewBag.TeamId = new SelectList(_uow.Teams.All, "TeamId", "TeamName"); return View(vm); }
public ActionResult Create(PlayerCreateEditViewModel vm) { if (ModelState.IsValid) { // do not get user id from html get/post!!!! vm.Player.UserId = User.Identity.GetUserId<int>(); _uow.Players.Add(vm.Player); _uow.Commit(); return RedirectToAction(nameof(Index)); } vm.MapSelectList = new SelectList(_uow.Maps.All, nameof(Map.MapId), nameof(Map.MapName), vm.Player.MapId); vm.TeamSelectList = new SelectList(_uow.Teams.All, nameof(Team.TeamId), nameof(Team.TeamName), vm.Player.TeamId); return View(vm); }
// GET: players/Edit/5 public ActionResult Edit(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } // check user id!!!! Player player = _uow.Players.GetForUser(id.Value, User.Identity.GetUserId<int>()); if (player == null) { return HttpNotFound(); } var vm = new PlayerCreateEditViewModel() { Player = player }; vm.MapSelectList = new SelectList(_uow.Maps.All, nameof(Map.MapId), nameof(Map.MapName), vm.Player.MapId); vm.TeamSelectList = new SelectList(_uow.Teams.All, nameof(Team.TeamId), nameof(Team.TeamName), vm.Player.TeamId); return View(vm); }