// GET: Subscriptions/Details/5 public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } SubscriptionAndPilotsDto viewSubscription = null; using (var httpClient = new HttpClient()) { using (var response = await httpClient.GetAsync($"http://localhost:50106/api/v1/subscriptions/{id}")) { if (response.StatusCode == HttpStatusCode.OK) { string apiResponse = await response.Content.ReadAsStringAsync(); viewSubscription = JsonConvert.DeserializeObject <SubscriptionAndPilotsDto>(apiResponse); } else { //Redirect or send empty viewSubscription = new SubscriptionAndPilotsDto(); } } } return(View(viewSubscription)); }
public async Task <ActionResult <SubscriptionAndPilotsDto> > GetSubscriptionAsync([FromRoute] int id) { SubscriptionAndPilotsDto subscriptionAndPilotsDto = new SubscriptionAndPilotsDto(); subscriptionAndPilotsDto.SubscriptionDto = await _SubscriptionService.GetSubscriptionAsync(id); if (subscriptionAndPilotsDto.SubscriptionDto == null) { return(NotFound("Couldn't find any associated Subscription")); } subscriptionAndPilotsDto.pilotDtos = await _pilotService.GetPilotsBySubscription(id); if (subscriptionAndPilotsDto.pilotDtos == null) { return(NotFound("Couldn't fine any associated pilot")); } return(Ok(subscriptionAndPilotsDto)); }