public IActionResult Details(int locationId) { locationId++; string userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; Player player = db.Players.Include(p => p.Location) .FirstOrDefault(p => p.UserId == userId); player.LocationId = locationId; db.Entry(player).State = EntityState.Modified; var locationCount = db.Locations.ToList().Count; if (player.LocationId <= locationCount) { db.SaveChanges(); ViewBag.player = player; List <PlayerInventory> inventory = db.PlayerInventory.Include(pi => pi.Item) .Where(pi => pi.PlayerId == player.Id).ToList(); foreach (PlayerInventory invetoryEntry in inventory) { ViewBag.items.Add(invetoryEntry.Item); } return(View(player.Location)); } else { player.LocationId = 1; db.Entry(player).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", "Account")); } }
public IActionResult Create(IdentityRole role) { Debug.WriteLine(role.Name); role.NormalizedName = role.Name.ToUpper(); try { db.Roles.Add(role); db.SaveChanges(); ViewBag.ResultMessage = "Role Created Successfully!"; return(RedirectToAction("Index")); } catch { return(View()); } }
public IActionResult Create(Player player, string userId) { Player newPlayer = new Player(player.Name); newPlayer.UserId = userId; db.Add(newPlayer); db.SaveChanges(); return(RedirectToAction("Details", "Locations")); }