Skip to content

Commit 1672906

Browse files
tdavisjrthiennn
authored andcommitted
Option to show/hide District, City, PostalCode (#399)
* Option to show/hide District, City, PostalCode when input address information
1 parent d8c92f8 commit 1672906

File tree

17 files changed

+2691
-18
lines changed

17 files changed

+2691
-18
lines changed

src/Modules/SimplCommerce.Module.Core/Controllers/CountryApiController.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ public IActionResult List([FromBody] SmartTableParam param)
6060
c.Id,
6161
c.Name,
6262
c.IsShippingEnabled,
63-
c.IsBillingEnabled
63+
c.IsBillingEnabled,
64+
c.IsCityEnabled,
65+
c.IsPostalCodeEnabled,
66+
c.IsDistrictEnabled
6467
});
6568

6669
return Json(countries);
@@ -83,6 +86,9 @@ public async Task<IActionResult> Get(long id)
8386
Code3 = country.Code3,
8487
IsBillingEnabled = country.IsBillingEnabled,
8588
IsShippingEnabled = country.IsShippingEnabled,
89+
IsCityEnabled = country.IsCityEnabled,
90+
IsPostalCodeEnabled = country.IsPostalCodeEnabled,
91+
IsDistrictEnabled = country.IsDistrictEnabled
8692
};
8793

8894
return Json(model);
@@ -108,6 +114,9 @@ public async Task<IActionResult> Put(long id, [FromBody] CountryForm model)
108114
country.Code3 = model.Code3;
109115
country.IsShippingEnabled = model.IsShippingEnabled;
110116
country.IsBillingEnabled = model.IsBillingEnabled;
117+
country.IsCityEnabled = model.IsCityEnabled;
118+
country.IsPostalCodeEnabled = model.IsPostalCodeEnabled;
119+
country.IsDistrictEnabled = model.IsDistrictEnabled;
111120

112121
await _countryRepository.SaveChangesAsync();
113122

@@ -126,8 +135,12 @@ public async Task<IActionResult> Post([FromBody] CountryForm model)
126135
Code2 = model.Code2,
127136
Code3 = model.Code3,
128137
IsBillingEnabled = model.IsBillingEnabled,
129-
IsShippingEnabled = model.IsShippingEnabled
130-
};
138+
IsShippingEnabled = model.IsShippingEnabled,
139+
IsCityEnabled = model.IsCityEnabled,
140+
IsPostalCodeEnabled = model.IsPostalCodeEnabled,
141+
IsDistrictEnabled = model.IsDistrictEnabled
142+
143+
};
131144

132145
_countryRepository.Add(country);
133146
await _countryRepository.SaveChangesAsync();

src/Modules/SimplCommerce.Module.Core/Controllers/UserAddressController.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ public async Task<IActionResult> List()
4949
AddressLine2 = x.Address.AddressLine1,
5050
DistrictName = x.Address.District.Name,
5151
StateOrProvinceName = x.Address.StateOrProvince.Name,
52-
CountryName = x.Address.Country.Name
52+
CountryName = x.Address.Country.Name,
53+
DisplayCity = x.Address.Country.IsCityEnabled,
54+
DisplayPostalCode = x.Address.Country.IsPostalCodeEnabled,
55+
DisplayDistrict = x.Address.Country.IsDistrictEnabled
5356
}).ToList();
5457

5558
foreach (var item in model)
@@ -207,7 +210,7 @@ public async Task<IActionResult> Delete(long id)
207210
return NotFound();
208211
}
209212

210-
if(currentUser.DefaultShippingAddressId == userAddress.Id)
213+
if (currentUser.DefaultShippingAddressId == userAddress.Id)
211214
{
212215
currentUser.DefaultShippingAddressId = null;
213216
}
@@ -220,16 +223,29 @@ public async Task<IActionResult> Delete(long id)
220223

221224
private void PopulateAddressFormData(UserAddressFormViewModel model)
222225
{
223-
model.Countries = _countryRepository.Query()
226+
var shippableCountries = _countryRepository.Query()
224227
.Where(x => x.IsShippingEnabled)
225-
.OrderBy(x => x.Name)
228+
.OrderBy(x => x.Name);
229+
230+
model.Countries = shippableCountries
226231
.Select(x => new SelectListItem
227232
{
228233
Text = x.Name,
229234
Value = x.Id.ToString()
230235
}).ToList();
231236

232237
var onlyShipableCountryId = model.CountryId > 0 ? model.CountryId : long.Parse(model.Countries.First().Value);
238+
239+
var selectedCountry = shippableCountries.FirstOrDefault(c => c.Id == model.CountryId);
240+
241+
if (selectedCountry != null)
242+
{
243+
model.DisplayCity = selectedCountry.IsCityEnabled;
244+
model.DisplayDistrict = selectedCountry.IsDistrictEnabled;
245+
model.DisplayPostalCode = selectedCountry.IsPostalCodeEnabled;
246+
}
247+
248+
233249
model.StateOrProvinces = _stateOrProvinceRepository
234250
.Query()
235251
.Where(x => x.CountryId == onlyShipableCountryId)
@@ -240,7 +256,7 @@ private void PopulateAddressFormData(UserAddressFormViewModel model)
240256
Value = x.Id.ToString()
241257
}).ToList();
242258

243-
if(model.StateOrProvinceId > 0)
259+
if (model.StateOrProvinceId > 0)
244260
{
245261
model.Districts = _districtRepository
246262
.Query()

src/Modules/SimplCommerce.Module.Core/Models/Country.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,12 @@ public class Country : EntityBase
1313
public bool IsBillingEnabled { get; set; }
1414

1515
public bool IsShippingEnabled { get; set; }
16+
17+
public bool IsCityEnabled { get; set; } = true;
18+
19+
public bool IsPostalCodeEnabled { get; set; } = true;
20+
21+
public bool IsDistrictEnabled { get; set; } = true;
22+
1623
}
1724
}

src/Modules/SimplCommerce.Module.Core/ViewModels/CountryForm.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,11 @@ public class CountryForm
1313
public bool IsBillingEnabled { get; set; }
1414

1515
public bool IsShippingEnabled { get; set; }
16+
17+
public bool IsCityEnabled { get; set; }
18+
19+
public bool IsPostalCodeEnabled { get; set; }
20+
21+
public bool IsDistrictEnabled { get; set; }
1622
}
1723
}

src/Modules/SimplCommerce.Module.Core/ViewModels/UserAddressFormViewModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,11 @@ public class UserAddressFormViewModel
3434
public IList<SelectListItem> Districts { get; set; }
3535

3636
public IList<SelectListItem> Countries { get; set; }
37+
38+
public bool DisplayDistrict { get; set; } = true;
39+
40+
public bool DisplayPostalCode { get; set; } = true;
41+
42+
public bool DisplayCity { get; set; } = true;
3743
}
3844
}

src/Modules/SimplCommerce.Module.Core/ViewModels/UserAddressListItem.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,11 @@ public class UserAddressListItem
2121
public string CountryName { get; set; }
2222

2323
public bool IsDefaultShippingAddress { get; set; }
24+
25+
public bool DisplayDistrict { get; set; }
26+
27+
public bool DisplayPostalCode { get; set; }
28+
29+
public bool DisplayCity { get; set; }
2430
}
2531
}

src/Modules/SimplCommerce.Module.Core/Views/UserAddress/List.cshtml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
<div>
1616
<strong>@address.ContactName </strong><br />
1717
@address.AddressLine1 <br />
18-
@address.DistrictName, @address.StateOrProvinceName <br />
18+
@if(address.DisplayDistrict){
19+
<text>@address.DistrictName,</text>
20+
}
21+
@address.StateOrProvinceName <br />
1922
Phone: @address.Phone
2023
</div>
2124
<div>

src/Modules/SimplCommerce.Module.Core/Views/UserAddress/_AddressForm.cshtml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
</select>
1515
</div>
1616
</div>
17+
@if (Model.DisplayDistrict)
18+
{
1719
<div class="form-group">
1820
<label class="col-sm-2 control-label">@Localizer["District"]</label>
1921
<div class="col-sm-10">
@@ -22,18 +24,28 @@
2224
</select>
2325
</div>
2426
</div>
27+
}
28+
29+
@if (Model.DisplayCity)
30+
{
2531
<div class="form-group">
2632
<label class="col-sm-2 control-label">@Localizer["City"]</label>
2733
<div class="col-sm-10">
2834
<input asp-for="City" type="text" class="form-control">
2935
</div>
3036
</div>
37+
}
38+
39+
@if (Model.DisplayPostalCode)
40+
{
3141
<div class="form-group">
3242
<label class="col-sm-2 control-label">@Localizer["Postal Code"]</label>
3343
<div class="col-sm-10">
3444
<input asp-for="PostalCode" type="text" class="form-control">
3545
</div>
3646
</div>
47+
}
48+
3749
<div class="form-group">
3850
<label class="col-sm-2 control-label">@Localizer["Address"]</label>
3951
<div class="col-sm-10">

src/Modules/SimplCommerce.Module.Core/wwwroot/admin/countries/country-form.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,33 @@ <h2 ng-if="vm.isEditMode">{{::vm.translate.get('Edit Country')}}</h2>
4747
</div>
4848
</div>
4949
</div>
50+
<div class="form-group">
51+
<div class="col-sm-offset-2 col-sm-10">
52+
<div class="checkbox">
53+
<label>
54+
<input type="checkbox" ng-model="vm.country.isCityEnabled"> {{::vm.translate.get('Display City')}}
55+
</label>
56+
</div>
57+
</div>
58+
</div>
59+
<div class="form-group">
60+
<div class="col-sm-offset-2 col-sm-10">
61+
<div class="checkbox">
62+
<label>
63+
<input type="checkbox" ng-model="vm.country.isPostalCodeEnabled"> {{::vm.translate.get('Display Postal Code')}}
64+
</label>
65+
</div>
66+
</div>
67+
</div>
68+
<div class="form-group">
69+
<div class="col-sm-offset-2 col-sm-10">
70+
<div class="checkbox">
71+
<label>
72+
<input type="checkbox" ng-model="vm.country.isDistrictEnabled"> {{::vm.translate.get('Display District')}}
73+
</label>
74+
</div>
75+
</div>
76+
</div>
5077
<div class="form-group">
5178
<div class="col-sm-offset-2 col-sm-10">
5279
<button class="btn btn-primary" ng-click="vm.save()"><span class="glyphicon glyphicon-ok"></span> {{::vm.translate.get('Save')}}</button>

src/Modules/SimplCommerce.Module.Core/wwwroot/admin/countries/country-list.html

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ <h2>{{::vm.translate.get('Countries')}}</h2>
1515
<th st-sort="Name" class="sortable">{{::vm.translate.get('Name')}}</th>
1616
<th st-sort="IsShippingEnabled" class="sortable" st-sort-default="reverse">{{::vm.translate.get('Is Shipping Enabled')}}</th>
1717
<th st-sort="IsBillingEnabled" class="sortable">{{::vm.translate.get('Is Billing Enabled')}}</th>
18+
<th st-sort="IsBillingEnabled" class="sortable">{{::vm.translate.get('Display City')}}</th>
19+
<th st-sort="IsBillingEnabled" class="sortable">{{::vm.translate.get('Display Postal Code')}}</th>
20+
<th st-sort="IsBillingEnabled" class="sortable">{{::vm.translate.get('Display District')}}</th>
1821
<th class="sortable">&nbsp;</th>
1922
</tr>
2023
<tr>
@@ -30,10 +33,19 @@ <h2>{{::vm.translate.get('Countries')}}</h2>
3033
<tr ng-repeat="country in vm.countries">
3134
<td>{{country.name}}</td>
3235
<td>
33-
<input type="checkbox" ng-model="country.isShippingEnabled" ng-click="vm.toggleShippingOrBilling(country)">
36+
<input type="checkbox" ng-model="country.isShippingEnabled" ng-click="vm.update(country)">
3437
</td>
3538
<td>
36-
<input type="checkbox" ng-model="country.isBillingEnabled" ng-click="vm.toggleShippingOrBilling(country)">
39+
<input type="checkbox" ng-model="country.isBillingEnabled" ng-click="vm.update(country)">
40+
</td>
41+
<td>
42+
<input type="checkbox" ng-model="country.isCityEnabled" ng-click="vm.update(country)">
43+
</td>
44+
<td>
45+
<input type="checkbox" ng-model="country.isPostalCodeEnabled" ng-click="vm.update(country)">
46+
</td>
47+
<td>
48+
<input type="checkbox" ng-model="country.isDistrictEnabled" ng-click="vm.update(country)">
3749
</td>
3850
<td>
3951
<a ui-sref="country-edit({id: country.id})" title="Edit" class="btn btn-primary btn-xs"> <span class="glyphicon glyphicon-pencil"></span></a>

0 commit comments

Comments
 (0)