예제 #1
0
        public JsonResult GetProvinces(ConfigurationRequestViewModel viewModel)
        {
            var country = _addressConfigurationService.GetCountry(viewModel.CountryId);
            var city    = string.IsNullOrWhiteSpace(viewModel.CityName)
                ? _addressConfigurationService.GetCity(viewModel.CityId)
                : _addressConfigurationService.GetCity(viewModel.CityName);

            if (country == null)
            {
                // this is an error
            }
            else
            {
                // city may be null: that is handled in the service
                var provinces = _addressConfigurationService.GetAllProvinces(
                    viewModel.IsBillingAddress
                        ? AddressRecordType.BillingAddress
                        : AddressRecordType.ShippingAddress,
                    country, city);
                return(Json(new {
                    Success = true,
                    Provinces = provinces
                                .Select(tp =>
                                        new {
                        Value = tp.Record.TerritoryInternalRecord.Id,
                        Text = _contentManager.GetItemMetadata(tp).DisplayText
                    })
                                .OrderBy(obj => obj.Text)
                }));
            }
            // TODO
            return(Json(new List <string>()));
        }
예제 #2
0
        private bool ValidateVM(AddressEditViewModel vm)
        {
            int id = -1;

            if (vm.CityId > 0)
            {
                if (int.TryParse(vm.City, out id))
                {
                    // the form sent the city's id instead of its name
                    vm.City = _addressConfigurationService
                              .GetCity(vm.CityId)
                              ?.As <TitlePart>()
                              ?.Title
                              ?? string.Empty;
                }
            }
            if (vm.ProvinceId > 0)
            {
                if (int.TryParse(vm.Province, out id))
                {
                    // the form sent the city's id instead of its name
                    vm.Province = _addressConfigurationService
                                  .GetProvince(vm.ProvinceId)
                                  ?.As <TitlePart>()
                                  ?.Title
                                  ?? string.Empty;
                }
            }
            if (vm.CountryId > 0)
            {
                if (int.TryParse(vm.Country, out id))
                {
                    // the form sent the city's id instead of its name
                    vm.Country = _addressConfigurationService
                                 .GetCountry(vm.CountryId)
                                 ?.As <TitlePart>()
                                 ?.Title
                                 ?? string.Empty;
                }
            }
            bool response = true;

            foreach (var valP in _validationProviders)
            {
                if (!valP.Validate(vm))
                {
                    response = false;
                }
            }
            return(response);
        }
예제 #3
0
        public JsonResult GetCities(ConfigurationRequestViewModel viewModel)
        {
            var country = _addressConfigurationService.GetCountry(viewModel.CountryId);

            if (country == null)
            {
                // this is an error
            }
            else
            {
                var cities = _addressConfigurationService.GetAllCities(
                    viewModel.IsBillingAddress
                        ? AddressRecordType.BillingAddress
                        : AddressRecordType.ShippingAddress,
                    country);
                if (viewModel.CityId != 0)
                {
                    var selectedCity = _addressConfigurationService.GetCity(viewModel.CityId);
                    if (selectedCity != null && !cities.Any(c => c.Record.TerritoryInternalRecord.Id == viewModel.CityId))
                    {
                        cities = cities.Concat(new[] { selectedCity });
                    }
                }
                return(Json(new {
                    Success = true,
                    Cities = cities
                             .Select(tp =>
                                     new {
                        Value = tp.Record.TerritoryInternalRecord.Id,
                        Text = _contentManager.GetItemMetadata(tp).DisplayText
                    })
                             .OrderBy(obj => obj.Text)
                }));
            }
            // TODO
            return(Json(new List <string>()));
        }
예제 #4
0
        private void ValidateVM(AddressEditViewModel vm)
        {
            int id = -1;

            if (vm.CityId > 0)
            {
                if (int.TryParse(vm.City, out id))
                {
                    // the form sent the city's id instead of its name
                    vm.City = _addressConfigurationService
                              .GetCity(vm.CityId)
                              ?.As <TitlePart>()
                              ?.Title
                              ?? string.Empty;
                }
            }
            if (vm.ProvinceId > 0)
            {
                if (int.TryParse(vm.Province, out id))
                {
                    // the form sent the city's id instead of its name
                    vm.Province = _addressConfigurationService
                                  .GetProvince(vm.ProvinceId)
                                  ?.As <TitlePart>()
                                  ?.Title
                                  ?? string.Empty;
                }
            }
            if (vm.CountryId > 0)
            {
                if (int.TryParse(vm.Country, out id))
                {
                    // the form sent the city's id instead of its name
                    vm.Country = _addressConfigurationService
                                 .GetCountry(vm.CountryId)
                                 ?.As <TitlePart>()
                                 ?.Title
                                 ?? string.Empty;
                }
            }
        }