本文整理汇总了C#中Nop.Core.Domain.Customers.Customer.IsAdmin方法的典型用法代码示例。如果您正苦于以下问题:C# Customer.IsAdmin方法的具体用法?C# Customer.IsAdmin怎么用?C# Customer.IsAdmin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nop.Core.Domain.Customers.Customer
的用法示例。
在下文中一共展示了Customer.IsAdmin方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Can_check_whether_customer_is_admin
public void Can_check_whether_customer_is_admin()
{
var customer = new Customer();
customer.CustomerRoles.Add(new CustomerRole()
{
Active = true,
Name = "Registered",
SystemName = SystemCustomerRoleNames.Registered
});
customer.CustomerRoles.Add(new CustomerRole()
{
Active = true,
Name = "Guests",
SystemName = SystemCustomerRoleNames.Guests
});
customer.IsAdmin().ShouldBeFalse();
customer.CustomerRoles.Add(
new CustomerRole()
{
Active = true,
Name = "Administrators",
SystemName = SystemCustomerRoleNames.Administrators
});
customer.IsAdmin().ShouldBeTrue();
}
示例2: CanCancelRecurringPayment
/// <summary>
/// Gets a value indicating whether a customer can cancel recurring payment
/// </summary>
/// <param name="customerToValidate">Customer</param>
/// <param name="recurringPayment">Recurring Payment</param>
/// <returns>value indicating whether a customer can cancel recurring payment</returns>
public virtual bool CanCancelRecurringPayment(Customer customerToValidate, RecurringPayment recurringPayment)
{
if (recurringPayment == null)
return false;
if (customerToValidate == null)
return false;
var initialOrder = recurringPayment.InitialOrder;
if (initialOrder == null)
return false;
var customer = recurringPayment.InitialOrder.Customer;
if (customer == null)
return false;
if (initialOrder.OrderStatus == OrderStatus.Cancelled)
return false;
if (!customerToValidate.IsAdmin())
{
if (customer.Id != customerToValidate.Id)
return false;
}
if (!recurringPayment.NextPaymentDate.HasValue)
return false;
return true;
}
示例3: Create
public ActionResult Create(CustomerModel model, bool continueEditing, FormCollection form)
{
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);
}
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);
//custom customer attributes
var customerAttributes = ParseCustomCustomerAttributes(customer, form);
_genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.CustomCustomerAttributes, customerAttributes);
//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
foreach (var customerRole in newCustomerRoles)
{
//ensure that the current customer cannot add to "Administrators" system role if he's not an admin himself
if (customerRole.SystemName == SystemCustomerRoleNames.Administrators &&
!_workContext.CurrentCustomer.IsAdmin())
continue;
customer.CustomerRoles.Add(customerRole);
//.........这里部分代码省略.........
示例4: Create
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)
{
//.........这里部分代码省略.........