本文整理汇总了C#中Nop.Web.Models.Customer.CustomerAddressEditModel类的典型用法代码示例。如果您正苦于以下问题:C# CustomerAddressEditModel类的具体用法?C# CustomerAddressEditModel怎么用?C# CustomerAddressEditModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CustomerAddressEditModel类属于Nop.Web.Models.Customer命名空间,在下文中一共展示了CustomerAddressEditModel类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddressEdit
public ActionResult AddressEdit(int addressId)
{
if (!_workContext.CurrentCustomer.IsRegistered())
return new HttpUnauthorizedResult();
var customer = _workContext.CurrentCustomer;
//find address (ensure that it belongs to the current customer)
var address = customer.Addresses.FirstOrDefault(a => a.Id == addressId);
if (address == null)
//address is not found
return RedirectToRoute("CustomerAddresses");
var model = new CustomerAddressEditModel();
model.Address.PrepareModel(address: address,
excludeProperties: false,
addressSettings: _addressSettings,
localizationService: _localizationService,
stateProvinceService: _stateProvinceService,
addressAttributeService: _addressAttributeService,
addressAttributeParser: _addressAttributeParser,
loadCountries: () => _countryService.GetAllCountries(_workContext.WorkingLanguage.Id));
return View(model);
}
示例2: AddressAdd
public ActionResult AddressAdd()
{
if (!_workContext.CurrentCustomer.IsRegistered())
return new HttpUnauthorizedResult();
var model = new CustomerAddressEditModel();
model.Address.PrepareModel(
address: null,
excludeProperties: false,
addressSettings:_addressSettings,
localizationService:_localizationService,
stateProvinceService: _stateProvinceService,
addressAttributeService: _addressAttributeService,
addressAttributeParser: _addressAttributeParser,
loadCountries: () => _countryService.GetAllCountries(_workContext.WorkingLanguage.Id));
return View(model);
}
示例3: AddressEdit
public ActionResult AddressEdit(int addressId)
{
if (!IsCurrentUserRegistered())
return new HttpUnauthorizedResult();
var customer = _workContext.CurrentCustomer;
//find address (ensure that it belongs to the current customer)
var address = customer.Addresses.FirstOrDefault(a => a.Id == addressId);
if (address == null)
//address is not found
return RedirectToRoute("CustomerAddresses");
var model = new CustomerAddressEditModel();
model.NavigationModel = GetCustomerNavigationModel(customer);
model.NavigationModel.SelectedTab = CustomerNavigationEnum.Addresses;
model.Address.PrepareModel(address, false, _addressSettings, _localizationService,
_stateProvinceService, () => _countryService.GetAllCountries());
return View(model);
}
示例4: AddressAdd
public ActionResult AddressAdd(CustomerAddressEditModel model)
{
if (!IsCurrentUserRegistered())
return new HttpUnauthorizedResult();
var customer = _workContext.CurrentCustomer;
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);
return RedirectToRoute("CustomerAddresses");
}
//If we got this far, something failed, redisplay form
model.NavigationModel = GetCustomerNavigationModel(customer);
model.NavigationModel.SelectedTab = CustomerNavigationEnum.Addresses;
model.Address.PrepareModel(null, true, _addressSettings, _localizationService,
_stateProvinceService, () => _countryService.GetAllCountries());
return View(model);
}
示例5: AddressEdit
public ActionResult AddressEdit(CustomerAddressEditModel model, int addressId)
{
if (!IsCurrentUserRegistered())
return new HttpUnauthorizedResult();
var customer = _workContext.CurrentCustomer;
model.NavigationModel = GetCustomerNavigationModel(customer);
model.NavigationModel.SelectedTab = CustomerNavigationEnum.Addresses;
if (ModelState.IsValid)
{
model.NavigationModel = GetCustomerNavigationModel(customer);
model.NavigationModel.SelectedTab = CustomerNavigationEnum.Addresses;
//find address (ensure that it belongs to the current customer)
var address = customer.Addresses.Where(a => a.Id == addressId).FirstOrDefault();
if (address == null)
//address is not found
return RedirectToRoute("CustomerAddresses");
address = model.Address.ToEntity(address);
_addressService.UpdateAddress(address);
return RedirectToRoute("CustomerAddresses");
}
//If we got this far, something failed, redisplay form
//countries
model.Address.AvailableCountries.Add(new SelectListItem() { Text = _localizationService.GetResource("Address.SelectCountry"), Value = "0" });
foreach (var c in _countryService.GetAllCountries())
model.Address.AvailableCountries.Add(new SelectListItem() { Text = c.GetLocalized(x => x.Name), Value = c.Id.ToString(), Selected = (c.Id == model.Address.CountryId) });
//states
var states = model.Address.CountryId.HasValue ? _stateProvinceService.GetStateProvincesByCountryId(model.Address.CountryId.Value).ToList() : new List<StateProvince>();
if (states.Count > 0)
{
foreach (var s in states)
model.Address.AvailableStates.Add(new SelectListItem() { Text = s.GetLocalized(x => x.Name), Value = s.Id.ToString(), Selected = (s.Id == model.Address.StateProvinceId) });
}
else
model.Address.AvailableStates.Add(new SelectListItem() { Text = _localizationService.GetResource("Address.OtherNonUS"), Value = "0" });
return View(model);
}
示例6: AddressAdd
public ActionResult AddressAdd(CustomerAddressEditModel model)
{
if (!IsCurrentUserRegistered())
return new HttpUnauthorizedResult();
var customer = _workContext.CurrentCustomer;
model.NavigationModel = GetCustomerNavigationModel(customer);
model.NavigationModel.SelectedTab = CustomerNavigationEnum.Addresses;
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);
return RedirectToRoute("CustomerAddresses");
}
//If we got this far, something failed, redisplay form
//countries
model.Address.AvailableCountries.Add(new SelectListItem() { Text = _localizationService.GetResource("Address.SelectCountry"), Value = "0" });
foreach (var c in _countryService.GetAllCountries())
model.Address.AvailableCountries.Add(new SelectListItem() { Text = c.GetLocalized(x => x.Name), Value = c.Id.ToString(), Selected = (c.Id == model.Address.CountryId) });
//states
var states = model.Address.CountryId.HasValue ? _stateProvinceService.GetStateProvincesByCountryId(model.Address.CountryId.Value).ToList() : new List<StateProvince>();
if (states.Count > 0)
{
foreach (var s in states)
model.Address.AvailableStates.Add(new SelectListItem() { Text = s.GetLocalized(x => x.Name), Value = s.Id.ToString(), Selected = (s.Id == model.Address.StateProvinceId) });
}
else
model.Address.AvailableStates.Add(new SelectListItem() { Text = _localizationService.GetResource("Address.OtherNonUS"), Value = "0" });
return View(model);
}