// GET: Courses/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            TraineeshipAndPilotsDto viewTraineeship = new TraineeshipAndPilotsDto();

            using (var httpClient = new HttpClient())
            {
                using (var response = await httpClient.GetAsync($"http://localhost:50106/api/v1/Traineeships/{id}"))
                {
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        string apiResponse = await response.Content.ReadAsStringAsync();

                        viewTraineeship = JsonConvert.DeserializeObject <TraineeshipAndPilotsDto>(apiResponse);
                    }
                    else
                    {
                        return(RedirectToAction("Index"));
                    }
                }
            }

            return(View(viewTraineeship));
        }
        // GET: Courses/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            TraineeshipAndPilotsDto viewTraineeship = new TraineeshipAndPilotsDto();

            using (var httpClient = new HttpClient())
            {
                using (var response = await httpClient.GetAsync($"http://localhost:50106/api/v1/Traineeships/{id}"))
                {
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        string apiResponse = await response.Content.ReadAsStringAsync();

                        viewTraineeship = JsonConvert.DeserializeObject <TraineeshipAndPilotsDto>(apiResponse);
                    }
                    else
                    {
                        return(RedirectToAction("Index"));
                    }
                }
            }


            ICollection <LicenseDto> licensesDto = null;

            using (var httpClient = new HttpClient())
            {
                using (var response = await httpClient.GetAsync("http://localhost:50106/api/v1/licenses/"))
                {
                    string apiResponse = await response.Content.ReadAsStringAsync();

                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        licensesDto = JsonConvert.DeserializeObject <ICollection <LicenseDto> >(apiResponse);
                    }
                }
            }
            ViewData["LicenseID"] = new SelectList(licensesDto, "LicenseID", "Title");

            return(View(viewTraineeship.TraineeshipDto));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <TraineeshipAndPilotsDto> > GetTraineeShipAsync([FromRoute] int traineeshipid)
        {
            TraineeshipAndPilotsDto traineeshipAndPilotsDto = new TraineeshipAndPilotsDto();

            var traineeship = await _TraineeshipService.GetTraineeShipAsync(traineeshipid);

            if (traineeship == null)
            {
                return(NotFound("Couldn't find any associated Traineeship"));
            }
            var pilots = await _PilotService.GetPilotsByTraineeship(traineeshipid);

            if (pilots == null)
            {
                return(NotFound("Couldn't find any associated pilots"));
            }

            traineeshipAndPilotsDto.TraineeshipDto = traineeship;
            traineeshipAndPilotsDto.PilotsDto      = pilots;

            return(Ok(traineeshipAndPilotsDto));
        }