Ejemplo n.º 1
0
        /// <returns>A task that represents the asynchronous operation</returns>
        public virtual async Task <IActionResult> StateDelete(int id)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageCountries))
            {
                return(AccessDeniedView());
            }

            //try to get a state with the specified id
            var state = await _stateProvinceService.GetStateProvinceByIdAsync(id)
                        ?? throw new ArgumentException("No state found with the specified id");

            if (await _addressService.GetAddressTotalByStateProvinceIdAsync(state.Id) > 0)
            {
                return(ErrorJson(await _localizationService.GetResourceAsync("Admin.Configuration.Countries.States.CantDeleteWithAddresses")));
            }

            //int countryId = state.CountryId;
            await _stateProvinceService.DeleteStateProvinceAsync(state);

            //activity log
            await _customerActivityService.InsertActivityAsync("DeleteStateProvince",
                                                               string.Format(await _localizationService.GetResourceAsync("ActivityLog.DeleteStateProvince"), state.Id), state);

            return(new NullJsonResult());
        }