Exemple #1
0
        public ActionResult Edit(int id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings))
            {
                return(Content("Access denied"));
            }

            var pickupPoint = _storePickupPointService.GetStorePickupPointById(id);

            if (pickupPoint == null)
            {
                return(RedirectToAction("Configure"));
            }

            var model = new StorePickupPointModel
            {
                Id           = pickupPoint.Id,
                Name         = pickupPoint.Name,
                Description  = pickupPoint.Description,
                OpeningHours = pickupPoint.OpeningHours,
                PickupFee    = pickupPoint.PickupFee,
                StoreId      = pickupPoint.StoreId
            };

            var address = _addressService.GetAddressById(pickupPoint.AddressId);

            if (address != null)
            {
                model.Address = new AddressModel
                {
                    Address1      = address.Address1,
                    City          = address.City,
                    CountryId     = address.CountryId,
                    ZipPostalCode = address.ZipPostalCode
                };
            }
            model.Address.AvailableCountries.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.Address.SelectCountry"), Value = "0"
            });
            foreach (var country in _countryService.GetAllCountries(showHidden: true))
            {
                model.Address.AvailableCountries.Add(new SelectListItem {
                    Text = country.Name, Value = country.Id.ToString(), Selected = (address != null && country.Id == address.CountryId)
                });
            }
            model.AvailableStores.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.Configuration.Settings.StoreScope.AllStores"), Value = "0"
            });
            foreach (var store in _storeService.GetAllStores())
            {
                model.AvailableStores.Add(new SelectListItem {
                    Text = store.Name, Value = store.Id.ToString(), Selected = store.Id == model.StoreId
                });
            }

            return(View("~/Plugins/Pickup.PickupInStore/Views/PickupInStore/Edit.cshtml", model));
        }
        public IActionResult Edit(int id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings))
            {
                return(AccessDeniedView());
            }

            var pickupPoint = _storePickupPointService.GetStorePickupPointById(id);

            if (pickupPoint == null)
            {
                return(RedirectToAction("Configure"));
            }

            var model = new StorePickupPointModel
            {
                Id           = pickupPoint.Id,
                Name         = pickupPoint.Name,
                Description  = pickupPoint.Description,
                OpeningHours = pickupPoint.OpeningHours,
                PickupFee    = pickupPoint.PickupFee,
                DisplayOrder = pickupPoint.DisplayOrder,
                StoreId      = pickupPoint.StoreId,
                Latitude     = pickupPoint.Latitude,
                Longitude    = pickupPoint.Longitude,
                TransitDays  = pickupPoint.TransitDays
            };

            var address = _addressService.GetAddressById(pickupPoint.AddressId);

            if (address != null)
            {
                model.Address = new AddressModel
                {
                    Address1             = address.Address1,
                    City                 = address.City,
                    County               = address.County,
                    CountryId            = address.CountryId,
                    StateProvinceId      = address.StateProvinceId,
                    ZipPostalCode        = address.ZipPostalCode,
                    CountryEnabled       = _addressSettings.CountryEnabled,
                    StateProvinceEnabled = _addressSettings.StateProvinceEnabled,
                    ZipPostalCodeEnabled = _addressSettings.ZipPostalCodeEnabled,
                    CityEnabled          = _addressSettings.CityEnabled,
                    CountyEnabled        = _addressSettings.CountyEnabled
                };
            }

            model.Address.AvailableCountries.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.Address.SelectCountry"), Value = "0"
            });
            foreach (var country in _countryService.GetAllCountries(showHidden: true))
            {
                model.Address.AvailableCountries.Add(new SelectListItem {
                    Text = country.Name, Value = country.Id.ToString(), Selected = (address != null && country.Id == address.CountryId)
                });
            }

            var states = !model.Address.CountryId.HasValue ? new List <StateProvince>()
                : _stateProvinceService.GetStateProvincesByCountryId(model.Address.CountryId.Value, showHidden: true);

            if (states.Any())
            {
                model.Address.AvailableStates.Add(new SelectListItem {
                    Text = _localizationService.GetResource("Admin.Address.SelectState"), Value = "0"
                });
                foreach (var state in states)
                {
                    model.Address.AvailableStates.Add(new SelectListItem {
                        Text = state.Name, Value = state.Id.ToString(), Selected = (address != null && state.Id == address.StateProvinceId)
                    });
                }
            }
            else
            {
                model.Address.AvailableStates.Add(new SelectListItem {
                    Text = _localizationService.GetResource("Admin.Address.Other"), Value = "0"
                });
            }

            model.AvailableStores.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.Configuration.Settings.StoreScope.AllStores"), Value = "0"
            });
            foreach (var store in _storeService.GetAllStores())
            {
                model.AvailableStores.Add(new SelectListItem {
                    Text = store.Name, Value = store.Id.ToString(), Selected = store.Id == model.StoreId
                });
            }

            return(View("~/Plugins/Pickup.PickupInStore/Views/Edit.cshtml", model));
        }