Exemplo n.º 1
0
 public IServiceResultWrap GetMunicipalities([FromBody] string searchedCode)
 {
     return(serviceManager.CallService(
                () => new ServiceResultWrap()
     {
         Data = municipalityService.GetMunicipalities(searchedCode)
     },
                new Dictionary <Type, string>()));
 }
        public JsonResult SeedCities([FromBody] List <CityViewModel> cities)
        {
            BaseResponse response = new BaseResponse();

            try
            {
                int companyId = cities.FirstOrDefault()?.Company?.Id ?? 0;
                List <CountryViewModel>      countries      = countryService.GetCountries(companyId).Countries;
                List <RegionViewModel>       regions        = regionService.GetRegions(companyId).Regions;
                List <MunicipalityViewModel> municipalities = municipalityService.GetMunicipalities(companyId).Municipalities;
                foreach (var item in cities)
                {
                    string mark = item?.Country.Mark;
                    if (mark == "NEM" || mark == "GER" || mark == "DEU")
                    {
                        mark = "DEU";
                    }
                    if (mark == "SRB")
                    {
                        mark = "SRB";
                    }
                    item.Country      = countries.FirstOrDefault(x => x.Mark == mark);
                    item.Region       = regions.FirstOrDefault(x => x.RegionCode == item.Region.RegionCode);
                    item.Municipality = municipalities.FirstOrDefault(x => x.MunicipalityCode == item.Municipality.MunicipalityCode);
                    cityService.Create(item);
                }
            }
            catch (Exception ex)
            {
                response = null;
                Console.WriteLine(ex.Message);
            }
            return(Json(response, new Newtonsoft.Json.JsonSerializerSettings()
            {
                Formatting = Newtonsoft.Json.Formatting.Indented
            }));
        }