async Task ExecuteLoadItemsCommand() { if (IsBusy) { return; } IsBusy = true; try { SWApiService swApiService = new SWApiService(new HttpClient()); var starships = await swApiService.GetShips("starships"); foreach (var ship in starships) { ShipModels.Add(ship); } } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } }
/// <summary> /// Generate list of ships with randomize location positions /// </summary> /// <param name="squareSizes">Ship squares size that will be generate for each of ship</param> /// <param name="boardSize">The maximum board size to provide valid locations data for each ship</param> public void GenerateCollectionOfShips(int[] squareSizes, int boardSize) { var locationModel = new LocationModel { BoardSize = boardSize }; foreach (var squareSize in squareSizes) { locationModel.LocationType = RandomLocationType; locationModel.SquareSize = squareSize; ShipModel shipModel = GenerateShipModel(locationModel); ShipModels.Add(shipModel); } }