public ActionResult AddressEdit(CustomerAddressModel model, FormCollection form) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers)) return AccessDeniedView(); var customer = _customerService.GetCustomerById(model.CustomerId); if (customer == null) //No customer found with the specified id return RedirectToAction("List"); var address = _addressService.GetAddressById(model.Address.Id); if (address == null) //No address found with the specified id return RedirectToAction("Edit", new { id = customer.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); SuccessNotification(_localizationService.GetResource("Admin.Customers.Customers.Addresses.Updated")); return RedirectToAction("AddressEdit", new { addressId = model.Address.Id, customerId = model.CustomerId }); } //If we got this far, something failed, redisplay form PrepareAddressModel(model, address, customer, true); return View(model); }
protected virtual void PrepareAddressModel(CustomerAddressModel model, Address address, Customer customer, bool excludeProperties) { if (customer == null) throw new ArgumentNullException("customer"); model.CustomerId = customer.Id; if (address != null) { if (!excludeProperties) { model.Address = address.ToModel(); } } if (model.Address == null) model.Address = new AddressModel(); 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 == model.Address.CountryId) }); //states var states = model.Address.CountryId.HasValue ? _stateProvinceService.GetStateProvincesByCountryId(model.Address.CountryId.Value, 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 == model.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); }
public ActionResult AddressCreate(int customerId) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers)) return AccessDeniedView(); var customer = _customerService.GetCustomerById(customerId); if (customer == null) //No customer found with the specified id return RedirectToAction("List"); var model = new CustomerAddressModel(); PrepareAddressModel(model, null, customer, false); return View(model); }
public ActionResult AddressEdit(int addressId, int customerId) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers)) return AccessDeniedView(); var customer = _customerService.GetCustomerById(customerId); if (customer == null) //No customer found with the specified id return RedirectToAction("List"); var address = _addressService.GetAddressById(addressId); if (address == null) //No address found with the specified id return RedirectToAction("Edit", new { id = customer.Id }); var model = new CustomerAddressModel(); PrepareAddressModel(model, address, customer, false); return View(model); }
public ActionResult AddressCreate(CustomerAddressModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers)) return AccessDeniedView(); var customer = _customerService.GetCustomerById(model.CustomerId); if (customer == null) //No customer found with the specified id return RedirectToAction("List"); if (ModelState.IsValid) { var address = model.Address.ToEntity(); address.CreatedOnUtc = DateTime.UtcNow; //some validation if (address.CountryId == 0) address.CountryId = null; if (address.StateProvinceId == 0) address.StateProvinceId = null; customer.Addresses.Add(address); _customerService.UpdateCustomer(customer); SuccessNotification(_localizationService.GetResource("Admin.Customers.Customers.Addresses.Added")); return RedirectToAction("AddressEdit", new { addressId = address.Id, customerId = model.CustomerId }); } //If we got this far, something failed, redisplay form model.CustomerId = customer.Id; //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 == model.Address.CountryId) }); //states var states = model.Address.CountryId.HasValue ? _stateProvinceService.GetStateProvincesByCountryId(model.Address.CountryId.Value, 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 == model.Address.StateProvinceId) }); } else model.Address.AvailableStates.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Address.OtherNonUS"), Value = "0" }); return View(model); }
public ActionResult AddressEdit(CustomerAddressModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers)) return AccessDeniedView(); var customer = _customerService.GetCustomerById(model.CustomerId); if (customer == null) //No customer found with the specified id return RedirectToAction("List"); var address = _addressService.GetAddressById(model.Address.Id); if (address == null) //No address found with the specified id return RedirectToAction("Edit", new { id = customer.Id }); if (ModelState.IsValid) { address = model.Address.ToEntity(address); _addressService.UpdateAddress(address); SuccessNotification(_localizationService.GetResource("Admin.Customers.Customers.Addresses.Updated")); return RedirectToAction("AddressEdit", new { addressId = model.Address.Id, customerId = model.CustomerId }); } //If we got this far, something failed, redisplay form model.CustomerId = customer.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 AddressCreate(int customerId) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers)) return AccessDeniedView(); var customer = _customerService.GetCustomerById(customerId); if (customer == null) //No customer found with the specified id return RedirectToAction("List"); var model = new CustomerAddressModel(); model.Address = new AddressModel(); model.CustomerId = customerId; 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() }); model.Address.AvailableStates.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Address.OtherNonUS"), Value = "0" }); return View(model); }
public override ActionResult AddressCreate(CustomerAddressModel model, FormCollection form) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers)) return AccessDeniedView(); var customer = _customerService.GetCustomerById(model.CustomerId); if (customer == null) //No customer found with the specified id return RedirectToAction("List"); //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) { var address = model.Address.ToEntity(); address.CustomAttributes = customAttributes; address.CreatedOnUtc = DateTime.UtcNow; //some validation if (address.CountryId == 0) address.CountryId = null; if (address.StateProvinceId == 0) address.StateProvinceId = null; customer.Addresses.Add(address); _customerService.UpdateCustomer(customer); SuccessNotification(_localizationService.GetResource("Admin.Customers.Customers.Addresses.Added")); //*********************** override begin ******************************************* //return RedirectToAction("AddressEdit", new { addressId = address.Id, customerId = model.CustomerId }); //%%%% ORIGINAL %%%%%%%%% //NJM: logic changed in AUConsignor to not redirect if child action (from AUConsignor) if (ControllerContext.IsChildAction) { ControllerContext.HttpContext.Response.Redirect(ControllerContext.HttpContext.Request.Url.ToString()); //PrepareCustomerModel(model, customer, true); return View(model); } else { //return RedirectToAction("Edit", customer.Id); //original 11111111 return RedirectToAction( "Edit", // Action name "AUConsignorAdmin", // Controller name new { id = customer.Id }); // Route values } //*********************** override end ******************************************* } //If we got this far, something failed, redisplay form PrepareAddressModel(model, null, customer, true); return View(model); }
public ActionResult AddressCreate(CustomerAddressModel model, FormCollection form) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers)) return AccessDeniedView(); var customer = _customerService.GetCustomerById(model.CustomerId); if (customer == null) //No customer found with the specified id return RedirectToAction("List"); //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) { var address = model.Address.ToEntity(); address.CustomAttributes = customAttributes; address.CreatedOnUtc = DateTime.UtcNow; address.Id = customer.Addresses.Count > 0 ? customer.Addresses.Max(x => x.Id) + 1 : 1; address._id = ObjectId.GenerateNewId().ToString(); customer.Addresses.Add(address); _customerService.UpdateCustomerinAdminPanel(customer); SuccessNotification(_localizationService.GetResource("Admin.Customers.Customers.Addresses.Added")); return RedirectToAction("AddressEdit", new { addressId = address.Id, customerId = model.CustomerId }); } //If we got this far, something failed, redisplay form PrepareAddressModel(model, null, customer, true); return View(model); }
public ActionResult AddressEdit(int addressId, int customerId) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers)) return AccessDeniedView(); var customer = _customerService.GetCustomerById(customerId); if (customer == null) throw new ArgumentException("No customer found with the specified id"); var address = _addressService.GetAddressById(addressId); if (address == null) throw new ArgumentException("No address found with the specified id", "addressId"); var model = new CustomerAddressModel(); model.CustomerId = customerId; 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 AddressCreate(int customerId) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers)) return AccessDeniedView(); var customer = _customerService.GetCustomerById(customerId); if (customer == null) throw new ArgumentException("No customer found with the specified id", "customerId"); var model = new CustomerAddressModel(); model.Address = new AddressModel(); model.CustomerId = customerId; //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() }); model.Address.AvailableStates.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Address.OtherNonUS"), Value = "0" }); return View(model); }