/// <summary> /// Gets a specific asteroid by id and returns a detailed view. /// </summary> /// <param name="asteroidId"></param> /// <returns></returns> public async Task <IActionResult> GetAsteroidDetails(string asteroidId) { var asteroid = await nasaService.GetAsteroidDataAsync(asteroidId); if (asteroid == null) { return(View("Error", new ErrorViewModel { ErrorMessage = $"Asteroid with id '{asteroidId}' doesn't exist." })); } var serializedJson = JsonConvert.SerializeObject(asteroid.CloseApproachData, new UnwrappedObjectSerializer(true)); var spreadsheets = excelConverter.CreateSpreadsheets(new[] { asteroid }); var dataTables = spreadsheets.Select(a => mapper.Map <TableViewModel>(a)); return(View("AsteroidDetails", dataTables)); }
/// <summary> /// Downloads a specific asteroid page from the Nasa Api as an xlsx file. /// </summary> /// <param name="pageNum">Page to download.</param> /// <returns></returns> public async Task <IActionResult> DownloadFile(int pageNum) { //We subtract one since this page variable comes from the view which has the page count incremented //by one so it displays properly. var asteroids = await nasaService.GetAsteroidDataCollectionAsync(pageNum - 1, PageSize); if (asteroids == null) { return(View("Error", new ErrorViewModel { ErrorMessage = $"Page number '{pageNum}'s doesn't exist." })); } var sheets = excelConverter.CreateSpreadsheets(asteroids.Asteroids); var excelPackage = excelConverter.CreateExcelPackage(sheets); var file = await excelPackage.GetAsByteArrayAsync(); return(File(file, ContentType, string.Format(FileName, pageNum))); }