public async Task <string> GenerateGrid(GenerateGridRequest request, CancellationToken cancellationToken) { var gridElements = await _context.GridElements.Where(x => x.GridId == request.GridId).ToListAsync <GridElement> (); for (int y = 0; y < 9; y++) { for (int x = 0; x < 9; x++) { if (gridElements.FirstOrDefault(gridelem => gridelem.XLocation == x && gridelem.YLocation == y) == null) { gridElements.Add(new GridElement(_random.Next(), x, y, request.GridId, _random.Next(1, 9), _random.Next(3) - 1 == 1)); } } } return(JsonConvert.SerializeObject(gridElements)); }
public async Task <string> Handle(GenerateGridRequest request, CancellationToken cancellationToken) { return(await GenerateGrid(request, cancellationToken)); }