Beispiel #1
0
		// GET /api/games
		public async Task<IEnumerable<Game>> Get()
		{
			using (var context = new GameCountContext())
			{
				var events = await context.Events
					.GroupBy(e => e.Game)
					.Select(eg => new Game
					{
						Id = eg.Key,
						Players = eg.Select(e => e.Player).Distinct().Count()
					})
					.ToListAsync();

				return events;
			}
		}
Beispiel #2
0
		// GET /api/games/gameId
		public async Task<IEnumerable<PlayerScore>> Get(string gameId)
		{
			using (var context = new GameCountContext())
			{
				var events = await context.Events
					.Where(e => e.Game == gameId)
					.GroupBy(e => e.Player)
					.Select(eg => new PlayerScore
					{
						Player = eg.Key,
						Score = eg.Sum(e => e.Count)
					})
					.OrderBy(s => s.Score)
					.ToListAsync();

				return events;
			}
		}
Beispiel #3
0
		// POST /api/games/gameId
		public async Task<IHttpActionResult> Post(string gameId, [FromBody]CountEvent countEvent)
		{
			using (var context = new GameCountContext())
			{
				var gameCountEvent = new GameCountEvent
				{
					Game = gameId,
					Player = countEvent.player,
					Count = countEvent.count
				};

				context.Events.Add(gameCountEvent);
				await context.SaveChangesAsync();
			}

			var myHub = GlobalHost.ConnectionManager.GetHubContext<MyHub>();
			myHub.Clients.Group(gameId).addMessage("server", "reload");

			return Ok();
		}