コード例 #1
0
        public IActionResult GetCities(bool includeRelations = true,
                                       bool UseLazyLoading   = true,
                                       bool UseAutoMapper    = true)
        {
            IQueryable <City> CityList = null;

            //var cityList1 = _repositoryWrapper.CityInfoRepositoryWrapper.FindAll(); ;

            if ((false == includeRelations) || (false == UseLazyLoading))
            {
                _repositoryWrapper.CityInfoRepositoryWrapper.DisableLazyLoading();
            }
            else  // true == includeRelations && true == UseLazyLoading
            {
                _repositoryWrapper.CityInfoRepositoryWrapper.EnableLazyLoading();
            }

            if (true == UseLazyLoading)
            {
                CityList = _repositoryWrapper.CityInfoRepositoryWrapper.FindAll();
            }
            else
            {
                CityList = _repositoryWrapper.CityInfoRepositoryWrapper.GetAllCities(includeRelations) as IQueryable <City>;
            }

            // Koden der er udkommenteret herunder er med for at vise, at man kan nå alle
            // wrappere fra alle controllers.
            //var LanguageEntities = _repositoryWrapper.LanguageRepositoryWrapper.FindAll();

            List <CityDto> CityDtos;

            if (true == UseAutoMapper)
            {
                CityDtos = _mapper.Map <IEnumerable <CityDto> >(CityList).ToList();
            }
            else
            {
                // Use Mapster
                CityDtos = CityList.Adapt <CityDto[]>().ToList();
            }

            //List<CityDto> CityDtos = _mapper.Map<IEnumerable<CityDto>>(CityList).ToList();
            //List<CityDto> CityDtos1 = cityList1.Adapt<CityDto[]>().ToList();

            var CityDtos2 = CityList.Adapt <CityDto[]>();

            CityDto CityDto_Object_Final = new CityDto();

            CityDto_Object_Final.Id = 0;
            //CityDto_Object_Final.Name = "Load Metode";
            CityDto_Object_Final.Name        = (true == UseAutoMapper ? "AutoMapper" : "Mapster");
            CityDto_Object_Final.Description = (true == UseLazyLoading ? "Lazy Loading" : "Eager Loading");

            CityDtos.Add(CityDto_Object_Final);

            return(Ok(CityDtos));
        }
コード例 #2
0
        private void UpdateDataGrid()
        {
            CityDtos = _mapper.Map <List <City>, List <CityDTO> >(_cityService.GetAll());

            CityDtos.Sort(delegate(CityDTO x, CityDTO y)
            {
                return(x.Id.CompareTo(y.Id));
            });

            DataGrid.ItemsSource = CityDtos;
        }
コード例 #3
0
        public IActionResult GetCity(int cityId)
        {
            var city = _cityRepository.GetCity(cityId);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var cityDtos = new CityDtos()
            {
                Id        = city.Id,
                CityName  = city.CityName,
                Latitude  = city.Latitude,
                Longitude = city.Longitude,
                ZipCode   = city.ZipCode
            };

            return(Ok(cityDtos));
        }