コード例 #1
0
        /// <returns>A task that represents the asynchronous operation</returns>
        public virtual async Task <IActionResult> StateCreatePopup(StateProvinceModel model)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageCountries))
            {
                return(AccessDeniedView());
            }

            //try to get a country with the specified id
            var country = await _countryService.GetCountryByIdAsync(model.CountryId);

            if (country == null)
            {
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                var sp = model.ToEntity <StateProvince>();

                await _stateProvinceService.InsertStateProvinceAsync(sp);

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

                await UpdateLocalesAsync(sp, model);

                ViewBag.RefreshPage = true;

                return(View(model));
            }

            //prepare model
            model = await _countryModelFactory.PrepareStateProvinceModelAsync(model, country, null, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }