コード例 #1
0
        /// <summary>
        /// Retrieve country for the specified id
        /// </summary>
        /// <param name="countryId"></param>
        /// <param name="includeCities"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <ApiResponse <CountryResponse> > GetCountryByIdAsync(int countryId, bool includeCities = false, CancellationToken cancellationToken = default)
        {
            var responseModel = new ApiResponse <CountryResponse>();

            Country country = null;

            if (includeCities)
            {
                country = await _countriesRepo.FindByIdWithCitiesAsync(countryId);
            }

            else
            {
                country = await _countriesRepo.FindByIdAsync(countryId);
            }


            if (country == null)
            {
                responseModel.AddError(ExceptionCreator.CreateNotFoundError(nameof(country), $"country of id {countryId}: not found"));
                return(responseModel);
            }

            if (includeCities)
            {
                responseModel.Data = await CreateCountryWithCitiesResponse(country);
            }

            else
            {
                responseModel.Data = CreateCountryResponse(country);
            }

            return(responseModel);
        }
コード例 #2
0
        // GET: Countries/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var country = await _countries.FindByIdAsync((int)id);

            //_context.Countries
            //.Include(c => c.Departments)
            //.ThenInclude(d => d.Cities)
            //.FirstOrDefaultAsync(m => m.Id == id);
            if (country == null)
            {
                return(NotFound());
            }
            return(View(country));
        }