Exemplo n.º 1
0
        public GuideCityDto GetGuideCityById(LanguageHelper language, int id)
        {
            var model1 = _unitOfWork.GuideCityRepository.FindBy(m => m.Id == id);

            if (model1.Any())
            {
                var model    = model1[0];
                var modelDto = Mapper.Map <GuideCity, GuideCityDto>(model);
                if (modelDto != null)
                {
                    foreach (var CDes in model.GuideCityDescriptions)
                    {
                        if (CDes.LanguageId == (int)language)
                        {
                            modelDto.Name = CDes.Name;
                        }
                    }
                    modelDto.TownsDto = new List <GuideTownDto>();

                    foreach (var Towns in model.GuideTowns)
                    {
                        GuideTownDto towndto = new GuideTownDto();
                        towndto.CityId = Towns.CityId;
                        towndto.Id     = Towns.Id;
                        foreach (var TownDes in Towns.GuideTownDescriptions)
                        {
                            if (TownDes.LanguageId == (int)language)
                            {
                                towndto.Name = TownDes.Name;
                                modelDto.TownsDto.Add(towndto);

                                // modelDto[index_m].TownsDto[index_m2].TownName = TownDes.TownName;
                            }
                        }
                    }
                }

                return(modelDto);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        public List <GuideCityDto> GetAllGuideCities(LanguageHelper language)
        {
            var model = _unitOfWork.GuideCityRepository.GetAll().OrderBy(m => m.Sort).ToList();

            var modelDto = Mapper.Map <List <GuideCity>, List <GuideCityDto> >(model);
            int index_m  = 0;

            foreach (var city in model)
            {
                modelDto[index_m].TownsDto = new List <GuideTownDto>();
                foreach (var CDes in city.GuideCityDescriptions)
                {
                    if (CDes.LanguageId == (int)language)
                    {
                        modelDto[index_m].Name = CDes.Name;
                    }
                }
                int index_m2 = 0;
                foreach (var Towns in city.GuideTowns)
                {
                    GuideTownDto towndto = new GuideTownDto();
                    towndto.CityId = Towns.CityId;
                    towndto.Id     = Towns.Id;
                    foreach (var TownDes in Towns.GuideTownDescriptions)
                    {
                        if (TownDes.LanguageId == (int)language)
                        {
                            towndto.Gps_Latitude  = Towns.Gps_Latitude;
                            towndto.Gps_Longitude = Towns.Gps_Longitude;
                            towndto.Name          = TownDes.Name;
                            modelDto[index_m].TownsDto.Add(towndto);

                            // modelDto[index_m].TownsDto[index_m2].TownName = TownDes.TownName;
                        }
                    }
                    index_m2++;
                }
                index_m++;
            }
            return(modelDto);
        }