public ActionResult AddressEdit(OrderAddressModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders)) return AccessDeniedView(); var order = _orderService.GetOrderById(model.OrderId); if (order == null) //No order found with the specified id return RedirectToAction("List"); var address = _addressService.GetAddressById(model.Address.Id); if (address == null) throw new ArgumentException("No address found with the specified id"); if (ModelState.IsValid) { address = model.Address.ToEntity(address); _addressService.UpdateAddress(address); return RedirectToAction("AddressEdit", new { addressId = model.Address.Id, orderId = model.OrderId }); } //If we got this far, something failed, redisplay form model.OrderId = order.Id; model.Address = address.ToModel(); model.Address.FirstNameEnabled = true; model.Address.FirstNameRequired = true; model.Address.LastNameEnabled = true; model.Address.LastNameRequired = true; model.Address.EmailEnabled = true; model.Address.EmailRequired = true; model.Address.CompanyEnabled = _addressSettings.CompanyEnabled; model.Address.CompanyRequired = _addressSettings.CompanyRequired; model.Address.CountryEnabled = _addressSettings.CountryEnabled; model.Address.StateProvinceEnabled = _addressSettings.StateProvinceEnabled; model.Address.CityEnabled = _addressSettings.CityEnabled; model.Address.CityRequired = _addressSettings.CityRequired; model.Address.StreetAddressEnabled = _addressSettings.StreetAddressEnabled; model.Address.StreetAddressRequired = _addressSettings.StreetAddressRequired; model.Address.StreetAddress2Enabled = _addressSettings.StreetAddress2Enabled; model.Address.StreetAddress2Required = _addressSettings.StreetAddress2Required; model.Address.ZipPostalCodeEnabled = _addressSettings.ZipPostalCodeEnabled; model.Address.ZipPostalCodeRequired = _addressSettings.ZipPostalCodeRequired; model.Address.PhoneEnabled = _addressSettings.PhoneEnabled; model.Address.PhoneRequired = _addressSettings.PhoneRequired; model.Address.FaxEnabled = _addressSettings.FaxEnabled; model.Address.FaxRequired = _addressSettings.FaxRequired; //countries model.Address.AvailableCountries.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Address.SelectCountry"), Value = "0" }); foreach (var c in _countryService.GetAllCountries(true)) model.Address.AvailableCountries.Add(new SelectListItem() { Text = c.Name, Value = c.Id.ToString(), Selected = (c.Id == address.CountryId) }); //states var states = address.Country != null ? _stateProvinceService.GetStateProvincesByCountryId(address.Country.Id, true).ToList() : new List<StateProvince>(); if (states.Count > 0) { foreach (var s in states) model.Address.AvailableStates.Add(new SelectListItem() { Text = s.Name, Value = s.Id.ToString(), Selected = (s.Id == address.StateProvinceId) }); } else model.Address.AvailableStates.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Address.OtherNonUS"), Value = "0" }); return View(model); }
public ActionResult AddressEdit(int addressId, int orderId) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders)) return AccessDeniedView(); var order = _orderService.GetOrderById(orderId); if (order == null) //No order found with the specified id return RedirectToAction("List"); var address = _addressService.GetAddressById(addressId); if (address == null) throw new ArgumentException("No address found with the specified id", "addressId"); var model = new OrderAddressModel(); model.OrderId = orderId; model.Address = address.ToModel(); //countries model.Address.AvailableCountries.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Address.SelectCountry"), Value = "0" }); foreach (var c in _countryService.GetAllCountries(true)) model.Address.AvailableCountries.Add(new SelectListItem() { Text = c.Name, Value = c.Id.ToString(), Selected = (c.Id == address.CountryId) }); //states var states = address.Country != null ? _stateProvinceService.GetStateProvincesByCountryId(address.Country.Id, true).ToList() : new List<StateProvince>(); if (states.Count > 0) { foreach (var s in states) model.Address.AvailableStates.Add(new SelectListItem() { Text = s.Name, Value = s.Id.ToString(), Selected = (s.Id == address.StateProvinceId) }); } else model.Address.AvailableStates.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Address.OtherNonUS"), Value = "0" }); return View(model); }
public ActionResult AddressEdit(int addressId, int orderId) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders)) return AccessDeniedView(); var order = _orderService.GetOrderById(orderId); if (order == null) //No order found with the specified id return RedirectToAction("List"); //a vendor does not have to this functionality if (_workContext.CurrentVendor != null) return RedirectToAction("Edit", "Order", new { id = orderId }); var address = _addressService.GetAddressById(addressId); if (address == null) throw new ArgumentException("No address found with the specified id", "addressId"); var model = new OrderAddressModel(); model.OrderId = orderId; model.Address = address.ToModel(); model.Address.FirstNameEnabled = true; model.Address.FirstNameRequired = true; model.Address.LastNameEnabled = true; model.Address.LastNameRequired = true; model.Address.EmailEnabled = true; model.Address.EmailRequired = true; model.Address.CompanyEnabled = _addressSettings.CompanyEnabled; model.Address.CompanyRequired = _addressSettings.CompanyRequired; model.Address.CountryEnabled = _addressSettings.CountryEnabled; model.Address.StateProvinceEnabled = _addressSettings.StateProvinceEnabled; model.Address.CityEnabled = _addressSettings.CityEnabled; model.Address.CityRequired = _addressSettings.CityRequired; model.Address.StreetAddressEnabled = _addressSettings.StreetAddressEnabled; model.Address.StreetAddressRequired = _addressSettings.StreetAddressRequired; model.Address.StreetAddress2Enabled = _addressSettings.StreetAddress2Enabled; model.Address.StreetAddress2Required = _addressSettings.StreetAddress2Required; model.Address.ZipPostalCodeEnabled = _addressSettings.ZipPostalCodeEnabled; model.Address.ZipPostalCodeRequired = _addressSettings.ZipPostalCodeRequired; model.Address.PhoneEnabled = _addressSettings.PhoneEnabled; model.Address.PhoneRequired = _addressSettings.PhoneRequired; model.Address.FaxEnabled = _addressSettings.FaxEnabled; model.Address.FaxRequired = _addressSettings.FaxRequired; //countries model.Address.AvailableCountries.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Address.SelectCountry"), Value = "0" }); foreach (var c in _countryService.GetAllCountries(true)) model.Address.AvailableCountries.Add(new SelectListItem() { Text = c.Name, Value = c.Id.ToString(), Selected = (c.Id == address.CountryId) }); //states var states = address.Country != null ? _stateProvinceService.GetStateProvincesByCountryId(address.Country.Id, true).ToList() : new List<StateProvince>(); if (states.Count > 0) { foreach (var s in states) model.Address.AvailableStates.Add(new SelectListItem() { Text = s.Name, Value = s.Id.ToString(), Selected = (s.Id == address.StateProvinceId) }); } else model.Address.AvailableStates.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Address.OtherNonUS"), Value = "0" }); return View(model); }
public ActionResult AddressEdit(OrderAddressModel model, FormCollection form) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders)) return AccessDeniedView(); var order = _orderService.GetOrderById(model.OrderId); if (order == null) //No order found with the specified id return RedirectToAction("List"); //a vendor does not have access to this functionality if (_workContext.CurrentVendor != null) return RedirectToAction("Edit", "Order", new { id = order.ID }); var address = _addressService.GetAddressById(model.Address.Id); if (address == null) throw new ArgumentException("No address found with the specified id"); //custom address attributes var customAttributes = form.ParseCustomAddressAttributes(_addressAttributeParser, _addressAttributeService); var customAttributeWarnings = _addressAttributeParser.GetAttributeWarnings(customAttributes); foreach (var error in customAttributeWarnings) { ModelState.AddModelError("", error); } if (ModelState.IsValid) { address = model.Address.ToEntity(address); address.CustomAttributes = customAttributes; _addressService.UpdateAddress(address); return RedirectToAction("AddressEdit", new { addressId = model.Address.Id, orderId = model.OrderId }); } //If we got this far, something failed, redisplay form model.OrderId = order.ID; model.Address = address.ToModel(); model.Address.FirstNameEnabled = true; model.Address.FirstNameRequired = true; model.Address.LastNameEnabled = true; model.Address.LastNameRequired = true; model.Address.EmailEnabled = true; model.Address.EmailRequired = true; model.Address.CompanyEnabled = _addressSettings.CompanyEnabled; model.Address.CompanyRequired = _addressSettings.CompanyRequired; model.Address.CountryEnabled = _addressSettings.CountryEnabled; model.Address.StateProvinceEnabled = _addressSettings.StateProvinceEnabled; model.Address.CityEnabled = _addressSettings.CityEnabled; model.Address.CityRequired = _addressSettings.CityRequired; model.Address.StreetAddressEnabled = _addressSettings.StreetAddressEnabled; model.Address.StreetAddressRequired = _addressSettings.StreetAddressRequired; model.Address.StreetAddress2Enabled = _addressSettings.StreetAddress2Enabled; model.Address.StreetAddress2Required = _addressSettings.StreetAddress2Required; model.Address.ZipPostalCodeEnabled = _addressSettings.ZipPostalCodeEnabled; model.Address.ZipPostalCodeRequired = _addressSettings.ZipPostalCodeRequired; model.Address.PhoneEnabled = _addressSettings.PhoneEnabled; model.Address.PhoneRequired = _addressSettings.PhoneRequired; model.Address.FaxEnabled = _addressSettings.FaxEnabled; model.Address.FaxRequired = _addressSettings.FaxRequired; //countries model.Address.AvailableCountries.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Address.SelectCountry"), Value = "0" }); foreach (var c in _countryService.GetAllCountries(true)) model.Address.AvailableCountries.Add(new SelectListItem { Text = c.Name, Value = c.ID.ToString(), Selected = (c.ID == address.CountryId) }); //states var states = address.Country != null ? _stateProvinceService.GetStateProvincesByCountryId(address.Country.ID, true).ToList() : new List<StateProvince>(); if (states.Count > 0) { foreach (var s in states) model.Address.AvailableStates.Add(new SelectListItem { Text = s.Name, Value = s.ID.ToString(), Selected = (s.ID == address.StateProvinceId) }); } else model.Address.AvailableStates.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Address.OtherNonUS"), Value = "0" }); //customer attribute services model.Address.PrepareCustomAddressAttributes(address, _addressAttributeService, _addressAttributeParser); return View(model); }