コード例 #1
0
        // 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));
        }
コード例 #2
0
        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));
        }