public ActionResult Edit(int id) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers)) return AccessDeniedView(); var customer = _customerService.GetCustomerById(id); if (customer == null || customer.Deleted) //No customer found with the specified id return RedirectToAction("List"); var model = new CustomerModel(); model.Id = customer.Id; model.Email = customer.Email; model.Username = customer.Username; //vendors model.VendorId = customer.VendorId; PrepareVendorsModel(model); model.AdminComment = customer.AdminComment; model.IsTaxExempt = customer.IsTaxExempt; model.Active = customer.Active; model.AffiliateId = customer.AffiliateId; model.TimeZoneId = customer.GetAttribute<string>(SystemCustomerAttributeNames.TimeZoneId); model.UsernamesEnabled = _customerSettings.UsernamesEnabled; model.AllowUsersToChangeUsernames = _customerSettings.AllowUsersToChangeUsernames; model.AllowCustomersToSetTimeZone = _dateTimeSettings.AllowCustomersToSetTimeZone; foreach (var tzi in _dateTimeHelper.GetSystemTimeZones()) model.AvailableTimeZones.Add(new SelectListItem() { Text = tzi.DisplayName, Value = tzi.Id, Selected = (tzi.Id == model.TimeZoneId) }); model.DisplayVatNumber = _taxSettings.EuVatEnabled; model.VatNumber = customer.GetAttribute<string>(SystemCustomerAttributeNames.VatNumber); model.VatNumberStatusNote = ((VatNumberStatus)customer.GetAttribute<int>(SystemCustomerAttributeNames.VatNumberStatusId)) .GetLocalizedEnum(_localizationService, _workContext); model.CreatedOn = _dateTimeHelper.ConvertToUserTime(customer.CreatedOnUtc, DateTimeKind.Utc); model.LastActivityDate = _dateTimeHelper.ConvertToUserTime(customer.LastActivityDateUtc, DateTimeKind.Utc); model.LastIpAddress = customer.LastIpAddress; model.LastVisitedPage = customer.GetAttribute<string>(SystemCustomerAttributeNames.LastVisitedPage); //form fields model.FirstName = customer.GetAttribute<string>(SystemCustomerAttributeNames.FirstName); model.LastName = customer.GetAttribute<string>(SystemCustomerAttributeNames.LastName); model.Gender = customer.GetAttribute<string>(SystemCustomerAttributeNames.Gender); model.DateOfBirth = customer.GetAttribute<DateTime?>(SystemCustomerAttributeNames.DateOfBirth); model.Company = customer.GetAttribute<string>(SystemCustomerAttributeNames.Company); model.StreetAddress = customer.GetAttribute<string>(SystemCustomerAttributeNames.StreetAddress); model.StreetAddress2 = customer.GetAttribute<string>(SystemCustomerAttributeNames.StreetAddress2); model.ZipPostalCode = customer.GetAttribute<string>(SystemCustomerAttributeNames.ZipPostalCode); model.City = customer.GetAttribute<string>(SystemCustomerAttributeNames.City); model.CountryId = customer.GetAttribute<int>(SystemCustomerAttributeNames.CountryId); model.StateProvinceId = customer.GetAttribute<int>(SystemCustomerAttributeNames.StateProvinceId); model.Phone = customer.GetAttribute<string>(SystemCustomerAttributeNames.Phone); model.Fax = customer.GetAttribute<string>(SystemCustomerAttributeNames.Fax); model.GenderEnabled = _customerSettings.GenderEnabled; model.DateOfBirthEnabled = _customerSettings.DateOfBirthEnabled; model.CompanyEnabled = _customerSettings.CompanyEnabled; model.StreetAddressEnabled = _customerSettings.StreetAddressEnabled; model.StreetAddress2Enabled = _customerSettings.StreetAddress2Enabled; model.ZipPostalCodeEnabled = _customerSettings.ZipPostalCodeEnabled; model.CityEnabled = _customerSettings.CityEnabled; model.CountryEnabled = _customerSettings.CountryEnabled; model.StateProvinceEnabled = _customerSettings.StateProvinceEnabled; model.PhoneEnabled = _customerSettings.PhoneEnabled; model.FaxEnabled = _customerSettings.FaxEnabled; //countries and states if (_customerSettings.CountryEnabled) { model.AvailableCountries.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Address.SelectCountry"), Value = "0" }); foreach (var c in _countryService.GetAllCountries()) { model.AvailableCountries.Add(new SelectListItem() { Text = c.Name, Value = c.Id.ToString(), Selected = c.Id == model.CountryId }); } if (_customerSettings.StateProvinceEnabled) { //states var states = _stateProvinceService.GetStateProvincesByCountryId(model.CountryId).ToList(); if (states.Count > 0) { foreach (var s in states) model.AvailableStates.Add(new SelectListItem() { Text = s.Name, Value = s.Id.ToString(), Selected = (s.Id == model.StateProvinceId) }); } else model.AvailableStates.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Address.OtherNonUS"), Value = "0" }); } } //customer roles model.AvailableCustomerRoles = _customerService .GetAllCustomerRoles(true) .Select(cr => cr.ToModel()) .ToList(); model.SelectedCustomerRoleIds = customer.CustomerRoles.Select(cr => cr.Id).ToArray(); model.AllowManagingCustomerRoles = _permissionService.Authorize(StandardPermissionProvider.ManageCustomerRoles); //reward points gistory model.DisplayRewardPointsHistory = _rewardPointsSettings.Enabled; model.AddRewardPointsValue = 0; model.AddRewardPointsMessage = "Some comment here..."; //external authentication records model.AssociatedExternalAuthRecords = GetAssociatedExternalAuthRecords(customer); return View(model); }
public ActionResult Edit(CustomerModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers)) return AccessDeniedView(); var customer = _customerService.GetCustomerById(model.Id); if (customer == null || customer.Deleted) //No customer found with the specified id return RedirectToAction("List"); //validate customer roles var allCustomerRoles = _customerService.GetAllCustomerRoles(true); var newCustomerRoles = new List<CustomerRole>(); foreach (var customerRole in allCustomerRoles) if (model.SelectedCustomerRoleIds != null && model.SelectedCustomerRoleIds.Contains(customerRole.Id)) newCustomerRoles.Add(customerRole); var customerRolesError = ValidateCustomerRoles(newCustomerRoles); if (!String.IsNullOrEmpty(customerRolesError)) { ModelState.AddModelError("", customerRolesError); ErrorNotification(customerRolesError, false); } bool allowManagingCustomerRoles = _permissionService.Authorize(StandardPermissionProvider.ManageCustomerRoles); if (ModelState.IsValid) { try { customer.AdminComment = model.AdminComment; customer.IsTaxExempt = model.IsTaxExempt; customer.Active = model.Active; //email if (!String.IsNullOrWhiteSpace(model.Email)) { _customerRegistrationService.SetEmail(customer, model.Email); } else { customer.Email = model.Email; } //username if (_customerSettings.UsernamesEnabled && _customerSettings.AllowUsersToChangeUsernames) { if (!String.IsNullOrWhiteSpace(model.Username)) { _customerRegistrationService.SetUsername(customer, model.Username); } else { customer.Username = model.Username; } } //VAT number if (_taxSettings.EuVatEnabled) { string prevVatNumber = customer.GetAttribute<string>(SystemCustomerAttributeNames.VatNumber); _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.VatNumber, model.VatNumber); //set VAT number status if (!String.IsNullOrEmpty(model.VatNumber)) { if (!model.VatNumber.Equals(prevVatNumber, StringComparison.InvariantCultureIgnoreCase)) { _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.VatNumberStatusId, (int)_taxService.GetVatNumberStatus(model.VatNumber)); } } else { _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.VatNumberStatusId, (int)VatNumberStatus.Empty); } } //vendor customer.VendorId = model.VendorId; //form fields if (_dateTimeSettings.AllowCustomersToSetTimeZone) _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.TimeZoneId, model.TimeZoneId); if (_customerSettings.GenderEnabled) _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.Gender, model.Gender); _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.FirstName, model.FirstName); _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.LastName, model.LastName); if (_customerSettings.DateOfBirthEnabled) _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.DateOfBirth, model.DateOfBirth); if (_customerSettings.CompanyEnabled) _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.Company, model.Company); if (_customerSettings.StreetAddressEnabled) _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.StreetAddress, model.StreetAddress); if (_customerSettings.StreetAddress2Enabled) _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.StreetAddress2, model.StreetAddress2); if (_customerSettings.ZipPostalCodeEnabled) _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.ZipPostalCode, model.ZipPostalCode); if (_customerSettings.CityEnabled) _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.City, model.City); if (_customerSettings.CountryEnabled) _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.CountryId, model.CountryId); if (_customerSettings.CountryEnabled && _customerSettings.StateProvinceEnabled) _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.StateProvinceId, model.StateProvinceId); if (_customerSettings.PhoneEnabled) _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.Phone, model.Phone); if (_customerSettings.FaxEnabled) _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.Fax, model.Fax); //customer roles if (allowManagingCustomerRoles) { foreach (var customerRole in allCustomerRoles) { if (model.SelectedCustomerRoleIds != null && model.SelectedCustomerRoleIds.Contains(customerRole.Id)) { //new role if (customer.CustomerRoles.Count(cr => cr.Id == customerRole.Id) == 0) customer.CustomerRoles.Add(customerRole); } else { //removed role if (customer.CustomerRoles.Count(cr => cr.Id == customerRole.Id) > 0) customer.CustomerRoles.Remove(customerRole); } } _customerService.UpdateCustomer(customer); } //ensure that a customer with a vendor associated is not in "Administrators" role //otherwise, he won't be have access to the other functionality in admin area if (customer.IsAdmin() && customer.VendorId > 0) { customer.VendorId = 0; _customerService.UpdateCustomer(customer); ErrorNotification(_localizationService.GetResource("Admin.Customers.Customers.AdminCouldNotbeVendor")); } //ensure that a customer in the Vendors role has a vendor account associated. //otherwise, he will have access to ALL products if (customer.IsVendor() && customer.VendorId == 0) { var vendorRole = customer .CustomerRoles .FirstOrDefault(x => x.SystemName == SystemCustomerRoleNames.Vendors); customer.CustomerRoles.Remove(vendorRole); _customerService.UpdateCustomer(customer); ErrorNotification(_localizationService.GetResource("Admin.Customers.Customers.CannotBeInVendoRoleWithoutVendorAssociated")); } //activity log _customerActivityService.InsertActivity("EditCustomer", _localizationService.GetResource("ActivityLog.EditCustomer"), customer.Id); SuccessNotification(_localizationService.GetResource("Admin.Customers.Customers.Updated")); return continueEditing ? RedirectToAction("Edit", customer.Id) : RedirectToAction("List"); } catch (Exception exc) { ErrorNotification(exc.Message, false); } } //If we got this far, something failed, redisplay form model.UsernamesEnabled = _customerSettings.UsernamesEnabled; model.AllowUsersToChangeUsernames = _customerSettings.AllowUsersToChangeUsernames; model.AllowCustomersToSetTimeZone = _dateTimeSettings.AllowCustomersToSetTimeZone; foreach (var tzi in _dateTimeHelper.GetSystemTimeZones()) model.AvailableTimeZones.Add(new SelectListItem() { Text = tzi.DisplayName, Value = tzi.Id, Selected = (tzi.Id == model.TimeZoneId) }); model.DisplayVatNumber = _taxSettings.EuVatEnabled; model.VatNumberStatusNote = ((VatNumberStatus)customer.GetAttribute<int>(SystemCustomerAttributeNames.VatNumberStatusId)) .GetLocalizedEnum(_localizationService, _workContext); model.CreatedOn = _dateTimeHelper.ConvertToUserTime(customer.CreatedOnUtc, DateTimeKind.Utc); model.LastActivityDate = _dateTimeHelper.ConvertToUserTime(customer.LastActivityDateUtc, DateTimeKind.Utc); model.LastIpAddress = model.LastIpAddress; model.LastVisitedPage = customer.GetAttribute<string>(SystemCustomerAttributeNames.LastVisitedPage); //vendors PrepareVendorsModel(model); //form fields model.GenderEnabled = _customerSettings.GenderEnabled; model.DateOfBirthEnabled = _customerSettings.DateOfBirthEnabled; model.CompanyEnabled = _customerSettings.CompanyEnabled; model.StreetAddressEnabled = _customerSettings.StreetAddressEnabled; model.StreetAddress2Enabled = _customerSettings.StreetAddress2Enabled; model.ZipPostalCodeEnabled = _customerSettings.ZipPostalCodeEnabled; model.CityEnabled = _customerSettings.CityEnabled; model.CountryEnabled = _customerSettings.CountryEnabled; model.StateProvinceEnabled = _customerSettings.StateProvinceEnabled; model.PhoneEnabled = _customerSettings.PhoneEnabled; model.FaxEnabled = _customerSettings.FaxEnabled; //countries and states if (_customerSettings.CountryEnabled) { model.AvailableCountries.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Address.SelectCountry"), Value = "0" }); foreach (var c in _countryService.GetAllCountries()) { model.AvailableCountries.Add(new SelectListItem() { Text = c.Name, Value = c.Id.ToString(), Selected = c.Id == model.CountryId }); } if (_customerSettings.StateProvinceEnabled) { //states var states = _stateProvinceService.GetStateProvincesByCountryId(model.CountryId).ToList(); if (states.Count > 0) { foreach (var s in states) model.AvailableStates.Add(new SelectListItem() { Text = s.Name, Value = s.Id.ToString(), Selected = (s.Id == model.StateProvinceId) }); } else model.AvailableStates.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Address.OtherNonUS"), Value = "0" }); } } //customer roles model.AvailableCustomerRoles = _customerService .GetAllCustomerRoles(true) .Select(cr => cr.ToModel()) .ToList(); model.AllowManagingCustomerRoles = allowManagingCustomerRoles; //reward points gistory model.DisplayRewardPointsHistory = _rewardPointsSettings.Enabled; model.AddRewardPointsValue = 0; model.AddRewardPointsMessage = "Some comment here..."; //external authentication records model.AssociatedExternalAuthRecords = GetAssociatedExternalAuthRecords(customer); return View(model); }
public ActionResult Create() { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers)) return AccessDeniedView(); var model = new CustomerModel(); model.UsernamesEnabled = _customerSettings.UsernamesEnabled; model.AllowUsersToChangeUsernames = _customerSettings.AllowUsersToChangeUsernames; model.AllowCustomersToSetTimeZone = _dateTimeSettings.AllowCustomersToSetTimeZone; foreach (var tzi in _dateTimeHelper.GetSystemTimeZones()) model.AvailableTimeZones.Add(new SelectListItem() { Text = tzi.DisplayName, Value = tzi.Id, Selected = (tzi.Id == _dateTimeHelper.DefaultStoreTimeZone.Id) }); model.DisplayVatNumber = false; //customer roles model.AvailableCustomerRoles = _customerService .GetAllCustomerRoles(true) .Select(cr => cr.ToModel()) .ToList(); model.SelectedCustomerRoleIds = new int[0]; model.AllowManagingCustomerRoles = _permissionService.Authorize(StandardPermissionProvider.ManageCustomerRoles); //vendors PrepareVendorsModel(model); //form fields model.GenderEnabled = _customerSettings.GenderEnabled; model.DateOfBirthEnabled = _customerSettings.DateOfBirthEnabled; model.CompanyEnabled = _customerSettings.CompanyEnabled; model.StreetAddressEnabled = _customerSettings.StreetAddressEnabled; model.StreetAddress2Enabled = _customerSettings.StreetAddress2Enabled; model.ZipPostalCodeEnabled = _customerSettings.ZipPostalCodeEnabled; model.CityEnabled = _customerSettings.CityEnabled; model.CountryEnabled = _customerSettings.CountryEnabled; model.StateProvinceEnabled = _customerSettings.StateProvinceEnabled; model.PhoneEnabled = _customerSettings.PhoneEnabled; model.FaxEnabled = _customerSettings.FaxEnabled; if (_customerSettings.CountryEnabled) { model.AvailableCountries.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Address.SelectCountry"), Value = "0" }); foreach (var c in _countryService.GetAllCountries()) { model.AvailableCountries.Add(new SelectListItem() { Text = c.Name, Value = c.Id.ToString() }); } if (_customerSettings.StateProvinceEnabled) { //states var states = _stateProvinceService.GetStateProvincesByCountryId(model.CountryId).ToList(); if (states.Count > 0) { foreach (var s in states) model.AvailableStates.Add(new SelectListItem() { Text = s.Name, Value = s.Id.ToString(), Selected = (s.Id == model.StateProvinceId) }); } else model.AvailableStates.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Address.OtherNonUS"), Value = "0" }); } } //default value model.Active = true; return View(model); }
public ActionResult Create(CustomerModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers)) return AccessDeniedView(); if (!String.IsNullOrWhiteSpace(model.Email)) { var cust2 = _customerService.GetCustomerByEmail(model.Email); if (cust2 != null) ModelState.AddModelError("", "Email is already registered"); } if (!String.IsNullOrWhiteSpace(model.Username) & _customerSettings.UsernamesEnabled) { var cust2 = _customerService.GetCustomerByUsername(model.Username); if (cust2 != null) ModelState.AddModelError("", "Username is already registered"); } //validate customer roles var allCustomerRoles = _customerService.GetAllCustomerRoles(true); var newCustomerRoles = new List<CustomerRole>(); foreach (var customerRole in allCustomerRoles) if (model.SelectedCustomerRoleIds != null && model.SelectedCustomerRoleIds.Contains(customerRole.Id)) newCustomerRoles.Add(customerRole); var customerRolesError = ValidateCustomerRoles(newCustomerRoles); if (!String.IsNullOrEmpty(customerRolesError)) { ModelState.AddModelError("", customerRolesError); ErrorNotification(customerRolesError, false); } bool allowManagingCustomerRoles = _permissionService.Authorize(StandardPermissionProvider.ManageCustomerRoles); if (ModelState.IsValid) { var customer = new Customer() { CustomerGuid = Guid.NewGuid(), Email = model.Email, Username = model.Username, VendorId = model.VendorId, AdminComment = model.AdminComment, IsTaxExempt = model.IsTaxExempt, Active = model.Active, CreatedOnUtc = DateTime.UtcNow, LastActivityDateUtc = DateTime.UtcNow, }; _customerService.InsertCustomer(customer); //form fields if (_dateTimeSettings.AllowCustomersToSetTimeZone) _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.TimeZoneId, model.TimeZoneId); if (_customerSettings.GenderEnabled) _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.Gender, model.Gender); _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.FirstName, model.FirstName); _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.LastName, model.LastName); if (_customerSettings.DateOfBirthEnabled) _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.DateOfBirth, model.DateOfBirth); if (_customerSettings.CompanyEnabled) _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.Company, model.Company); if (_customerSettings.StreetAddressEnabled) _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.StreetAddress, model.StreetAddress); if (_customerSettings.StreetAddress2Enabled) _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.StreetAddress2, model.StreetAddress2); if (_customerSettings.ZipPostalCodeEnabled) _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.ZipPostalCode, model.ZipPostalCode); if (_customerSettings.CityEnabled) _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.City, model.City); if (_customerSettings.CountryEnabled) _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.CountryId, model.CountryId); if (_customerSettings.CountryEnabled && _customerSettings.StateProvinceEnabled) _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.StateProvinceId, model.StateProvinceId); if (_customerSettings.PhoneEnabled) _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.Phone, model.Phone); if (_customerSettings.FaxEnabled) _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.Fax, model.Fax); //password if (!String.IsNullOrWhiteSpace(model.Password)) { var changePassRequest = new ChangePasswordRequest(model.Email, false, _customerSettings.DefaultPasswordFormat, model.Password); var changePassResult = _customerRegistrationService.ChangePassword(changePassRequest); if (!changePassResult.Success) { foreach (var changePassError in changePassResult.Errors) ErrorNotification(changePassError); } } //customer roles if (allowManagingCustomerRoles) { foreach (var customerRole in newCustomerRoles) customer.CustomerRoles.Add(customerRole); _customerService.UpdateCustomer(customer); } //ensure that a customer with a vendor associated is not in "Administrators" role //otherwise, he won't be have access to the other functionality in admin area if (customer.IsAdmin() && customer.VendorId > 0) { customer.VendorId = 0; _customerService.UpdateCustomer(customer); ErrorNotification(_localizationService.GetResource("Admin.Customers.Customers.AdminCouldNotbeVendor")); } //ensure that a customer in the Vendors role has a vendor account associated. //otherwise, he will have access to ALL products if (customer.IsVendor() && customer.VendorId == 0) { var vendorRole = customer .CustomerRoles .FirstOrDefault(x => x.SystemName == SystemCustomerRoleNames.Vendors); customer.CustomerRoles.Remove(vendorRole); _customerService.UpdateCustomer(customer); ErrorNotification(_localizationService.GetResource("Admin.Customers.Customers.CannotBeInVendoRoleWithoutVendorAssociated")); } //activity log _customerActivityService.InsertActivity("AddNewCustomer", _localizationService.GetResource("ActivityLog.AddNewCustomer"), customer.Id); SuccessNotification(_localizationService.GetResource("Admin.Customers.Customers.Added")); return continueEditing ? RedirectToAction("Edit", new { id = customer.Id }) : RedirectToAction("List"); } //If we got this far, something failed, redisplay form model.UsernamesEnabled = _customerSettings.UsernamesEnabled; model.AllowUsersToChangeUsernames = _customerSettings.AllowUsersToChangeUsernames; model.AllowCustomersToSetTimeZone = _dateTimeSettings.AllowCustomersToSetTimeZone; foreach (var tzi in _dateTimeHelper.GetSystemTimeZones()) model.AvailableTimeZones.Add(new SelectListItem() { Text = tzi.DisplayName, Value = tzi.Id, Selected = (tzi.Id == model.TimeZoneId) }); model.DisplayVatNumber = false; //customer roles model.AvailableCustomerRoles = _customerService .GetAllCustomerRoles(true) .Select(cr => cr.ToModel()) .ToList(); model.AllowManagingCustomerRoles = allowManagingCustomerRoles; //vendors PrepareVendorsModel(model); //form fields model.GenderEnabled = _customerSettings.GenderEnabled; model.DateOfBirthEnabled = _customerSettings.DateOfBirthEnabled; model.CompanyEnabled = _customerSettings.CompanyEnabled; model.StreetAddressEnabled = _customerSettings.StreetAddressEnabled; model.StreetAddress2Enabled = _customerSettings.StreetAddress2Enabled; model.ZipPostalCodeEnabled = _customerSettings.ZipPostalCodeEnabled; model.CityEnabled = _customerSettings.CityEnabled; model.CountryEnabled = _customerSettings.CountryEnabled; model.StateProvinceEnabled = _customerSettings.StateProvinceEnabled; model.PhoneEnabled = _customerSettings.PhoneEnabled; model.FaxEnabled = _customerSettings.FaxEnabled; if (_customerSettings.CountryEnabled) { model.AvailableCountries.Add(new SelectListItem() { Text = _localizationService.GetResource("Address.SelectCountry"), Value = "0" }); foreach (var c in _countryService.GetAllCountries()) { model.AvailableCountries.Add(new SelectListItem() { Text = c.Name, Value = c.Id.ToString(), Selected = (c.Id == model.CountryId) }); } if (_customerSettings.StateProvinceEnabled) { //states var states = _stateProvinceService.GetStateProvincesByCountryId(model.CountryId).ToList(); if (states.Count > 0) { foreach (var s in states) model.AvailableStates.Add(new SelectListItem() { Text = s.Name, Value = s.Id.ToString(), Selected = (s.Id == model.StateProvinceId) }); } else model.AvailableStates.Add(new SelectListItem() { Text = _localizationService.GetResource("Address.OtherNonUS"), Value = "0" }); } } return View(model); }
public ActionResult ChangePassword(CustomerModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers)) return AccessDeniedView(); var customer = _customerService.GetCustomerById(model.Id); if (customer == null) //No customer found with the specified id return RedirectToAction("List"); if (ModelState.IsValid) { var changePassRequest = new ChangePasswordRequest(model.Email, false, _customerSettings.DefaultPasswordFormat, model.Password); var changePassResult = _customerRegistrationService.ChangePassword(changePassRequest); if (changePassResult.Success) SuccessNotification(_localizationService.GetResource("Admin.Customers.Customers.PasswordChanged")); else foreach (var error in changePassResult.Errors) ErrorNotification(error); } return RedirectToAction("Edit", customer.Id); }
private void PrepareVendorsModel(CustomerModel model) { if (model == null) throw new ArgumentNullException("model"); model.AvailableVendors.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Customers.Customers.Fields.Vendor.None"), Value = "0" }); var vendors = _vendorService.GetAllVendors(0, int.MaxValue, true); foreach (var vendor in vendors) { model.AvailableVendors.Add(new SelectListItem() { Text = vendor.Name, Value = vendor.Id.ToString() }); } }
public ActionResult SendPm(CustomerModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers)) return AccessDeniedView(); var customer = _customerService.GetCustomerById(model.Id); if (customer == null) //No customer found with the specified id return RedirectToAction("List"); try { if (!_forumSettings.AllowPrivateMessages) throw new NasException("Private messages are disabled"); if (customer.IsGuest()) throw new NasException("Customer should be registered"); if (String.IsNullOrWhiteSpace(model.SendPm.Subject)) throw new NasException("PM subject is empty"); if (String.IsNullOrWhiteSpace(model.SendPm.Message)) throw new NasException("PM message is empty"); var privateMessage = new PrivateMessage { StoreId = _storeContext.CurrentStore.Id, ToCustomerId = customer.Id, FromCustomerId = _workContext.CurrentCustomer.Id, Subject = model.SendPm.Subject, Text = model.SendPm.Message, IsDeletedByAuthor = false, IsDeletedByRecipient = false, IsRead = false, CreatedOnUtc = DateTime.UtcNow }; _forumService.InsertPrivateMessage(privateMessage); SuccessNotification(_localizationService.GetResource("Admin.Customers.Customers.SendPM.Sent")); } catch (Exception exc) { ErrorNotification(exc.Message); } return RedirectToAction("Edit", new { id = customer.Id }); }
public ActionResult SendEmail(CustomerModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers)) return AccessDeniedView(); var customer = _customerService.GetCustomerById(model.Id); if (customer == null) //No customer found with the specified id return RedirectToAction("List"); try { if (String.IsNullOrWhiteSpace(customer.Email)) throw new NasException("Customer email is empty"); if (!CommonHelper.IsValidEmail(customer.Email)) throw new NasException("Customer email is not valid"); if (String.IsNullOrWhiteSpace(model.SendEmail.Subject)) throw new NasException("Email subject is empty"); if (String.IsNullOrWhiteSpace(model.SendEmail.Body)) throw new NasException("Email body is empty"); var emailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId); if (emailAccount == null) emailAccount = _emailAccountService.GetAllEmailAccounts().FirstOrDefault(); if (emailAccount == null) throw new NasException("Email account can't be loaded"); var email = new QueuedEmail() { EmailAccountId = emailAccount.Id, FromName = emailAccount.DisplayName, From = emailAccount.Email, ToName = customer.GetFullName(), To = customer.Email, Subject = model.SendEmail.Subject, Body = model.SendEmail.Body, CreatedOnUtc = DateTime.UtcNow, }; _queuedEmailService.InsertQueuedEmail(email); SuccessNotification(_localizationService.GetResource("Admin.Customers.Customers.SendEmail.Queued")); } catch (Exception exc) { ErrorNotification(exc.Message); } return RedirectToAction("Edit", new { id = customer.Id }); }
public ActionResult MarkVatNumberAsValid(CustomerModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers)) return AccessDeniedView(); var customer = _customerService.GetCustomerById(model.Id); if (customer == null) //No customer found with the specified id return RedirectToAction("List"); _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.VatNumberStatusId, (int)VatNumberStatus.Valid); return RedirectToAction("Edit", customer.Id); }