public async Task <ActionResult <Player> > RegisterAsync(Player player) { var exists = await db.Players.Where(p => EF.Functions.Like(p.Email, player.Email)).FirstOrDefaultAsync(); if (exists != null) { return(NotFound()); } db.Entry(player).State = EntityState.Added; player.SignInCode = Guid.NewGuid().ToString("d"); await db.SaveChangesAsync(); return(Ok(player)); }
public async Task <ActionResult <Map> > AddToMap(int mapId, int characterId) { var map = await db.Maps.Where(p => p.Id == mapId).Include(p => p.CharacterPositions).ThenInclude(p => p.Character).SingleOrDefaultAsync(); if (map != null) { if (map.CharacterPositions.Any(p2 => p2.Character.Id == characterId)) { return(Ok(map)); } var cp = new CharacterPosition { Map = map, Character = await db.Characters.FindAsync(characterId) }; db.Entry(cp).State = EntityState.Added; await db.SaveChangesAsync(); return(await Refresh(mapId)); } return(NotFound()); }