public async Task <JsonResult> GetLocationsByLocality(string localityCode) { var locations = await _regionProvider.GetLocationsByLocality(localityCode); return(Json(locations.Model.OrderBy(l => l.Name))); }
public async Task <IActionResult> Manage() { var model = new ManageUserViewModel(); var userTask = _userProvider.GetUser(); var regionsTask = _regionProvider.GetRegions(); var userPhonesTask = _userProvider.GetUserPhones(); var user = (await userTask).Model; var deleveryType = AddressType.City; if (user.DeleveryLocationType.HasValue) { deleveryType = (AddressType)user.DeleveryLocationType; } string regionCode = String.IsNullOrEmpty(user.RegionCode) ? Constants.MOSCOW_KLADR : user.RegionCode; var locationTask = _regionProvider.GetLocalities(regionCode); var cityTask = _regionProvider.GetLocationsByRegion(regionCode); var cityRequest = await cityTask; string cityCode = String.IsNullOrEmpty(user.CityCode) ? cityRequest.Model.First().Code : user.CityCode; var localitiesRequest = await locationTask; string localityCode = String.IsNullOrEmpty(user.LocalityCode) ? localitiesRequest.Model.First().Code : user.LocalityCode; var locationRequest = await _regionProvider.GetLocationsByLocality(localityCode); string locationCode = String.IsNullOrEmpty(user.CityCode) ? locationRequest.Model.First().Code : user.CityCode; model.AddressModel = new AddressViewModel(nameof(model.AddressModel)) { RegionCode = regionCode, RegionList = new SelectList((await regionsTask).Model.OrderBy(l => l.Name), "Code", "Name", regionCode), DeliveryLocationType = deleveryType, City = new CityViewModel { CityCode = cityCode, CityList = new SelectList(cityRequest.Model.OrderBy(l => l.Name), "Code", "Name", cityCode) }, Locality = new LocalityViewModel { LocalityList = new SelectList(localitiesRequest.Model.OrderBy(l => l.Name), "Code", "Name", localityCode), LocalityCode = user.LocalityCode, LocationList = new SelectList(locationRequest.Model.OrderBy(l => l.Name), "Code", "Name", locationCode), LocationCode = user.CityCode }, Address = user.Address }; var userPhones = (await userPhonesTask).Model; model.PhoneMobile = _mapper.Map <PhoneViewModel>(userPhones.Mobile); model.PhoneWork = _mapper.Map <PhoneViewModel>(userPhones.Work); model.PhoneHome = _mapper.Map <PhoneViewModel>(userPhones.Home); model.PhoneAdditional = _mapper.Map <PhoneViewModel>(userPhones.Additional); return(View(model)); }