本文整理汇总了C#中Nop.Core.Domain.Customers.CustomerRole类的典型用法代码示例。如果您正苦于以下问题:C# CustomerRole类的具体用法?C# CustomerRole怎么用?C# CustomerRole使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CustomerRole类属于Nop.Core.Domain.Customers命名空间,在下文中一共展示了CustomerRole类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PrepareCustomerRoleModel
protected CustomerRoleModel PrepareCustomerRoleModel(CustomerRole customerRole)
{
var model = customerRole.ToModel();
var product = _productService.GetProductById(customerRole.PurchasedWithProductId);
if (product != null)
{
model.PurchasedWithProductName = product.Name;
}
return model;
}
示例2: Authorize
/// <summary>
/// Authorize permission
/// </summary>
/// <param name="permissionRecordSystemName">Permission record system name</param>
/// <param name="customerRole">Customer role</param>
/// <returns>true - authorized; otherwise, false</returns>
protected virtual bool Authorize(string permissionRecordSystemName, CustomerRole customerRole)
{
if (String.IsNullOrEmpty(permissionRecordSystemName))
return false;
string key = string.Format(PERMISSIONS_ALLOWED_KEY, customerRole.Id, permissionRecordSystemName);
return _cacheManager.Get(key, () =>
{
var permissionRecord = _permissionRecordRepository.Table.Where(x => x.CustomerRoles.Contains(customerRole.Id) && x.SystemName== permissionRecordSystemName).ToList();
if (permissionRecord.Count() > 0)
return true;
return false;
});
}
示例3: Authorize
/// <summary>
/// Authorize permission
/// </summary>
/// <param name="permissionRecordSystemName">Permission record system name</param>
/// <param name="customerRole">Customer role</param>
/// <returns>true - authorized; otherwise, false</returns>
protected virtual bool Authorize(string permissionRecordSystemName, CustomerRole customerRole)
{
if (String.IsNullOrEmpty(permissionRecordSystemName))
return false;
string key = string.Format(PERMISSIONS_ALLOWED_KEY, customerRole.Id, permissionRecordSystemName);
return _cacheManager.Get(key, () =>
{
foreach (var permission1 in customerRole.PermissionRecords)
if (permission1.SystemName.Equals(permissionRecordSystemName, StringComparison.InvariantCultureIgnoreCase))
return true;
return false;
});
}
示例4: Can_check_taxExempt_customer_in_taxExemptCustomerRole
public void Can_check_taxExempt_customer_in_taxExemptCustomerRole()
{
var customer = new Customer();
customer.IsTaxExempt = false;
_taxService.IsTaxExempt(null, customer).ShouldEqual(false);
var customerRole = new CustomerRole()
{
TaxExempt = true,
Active = true
};
customer.CustomerRoles.Add(customerRole);
_taxService.IsTaxExempt(null, customer).ShouldEqual(true);
customerRole.TaxExempt = false;
_taxService.IsTaxExempt(null, customer).ShouldEqual(false);
//if role is not active, weshould ignore 'TaxExempt' property
customerRole.Active = false;
_taxService.IsTaxExempt(null, customer).ShouldEqual(false);
}
示例5: ToEntity
public static CustomerRole ToEntity(this CustomerRoleModel model, CustomerRole destination)
{
return Mapper.Map(model, destination);
}
示例6: UpdateCustomerRole
/// <summary>
/// Updates the customer role
/// </summary>
/// <param name="customerRole">Customer role</param>
public virtual void UpdateCustomerRole(CustomerRole customerRole)
{
if (customerRole == null)
throw new ArgumentNullException("customerRole");
_customerRoleRepository.Update(customerRole);
_cacheManager.RemoveByPattern(CUSTOMERROLES_PATTERN_KEY);
//event notification
_eventPublisher.EntityUpdated(customerRole);
}
示例7: DeleteCustomerRole
/// <summary>
/// Delete a customer role
/// </summary>
/// <param name="customerRole">Customer role</param>
public virtual void DeleteCustomerRole(CustomerRole customerRole)
{
if (customerRole == null)
throw new ArgumentNullException("customerRole");
if (customerRole.IsSystemRole)
throw new NopException("System role could not be deleted");
_customerRoleRepository.Delete(customerRole);
_cacheManager.RemoveByPattern(CUSTOMERROLES_PATTERN_KEY);
//event notification
_eventPublisher.EntityDeleted(customerRole);
}
示例8: InstallCustomersAndUsers
protected virtual void InstallCustomersAndUsers(string defaultUserEmail, string defaultUserPassword)
{
var crAdministrators = new CustomerRole
{
Id = 1,
_id = ObjectId.GenerateNewId().ToString(),
Name = "Administrators",
Active = true,
IsSystemRole = true,
SystemName = SystemCustomerRoleNames.Administrators,
};
_customerRoleRepository.Insert(crAdministrators);
var crForumModerators = new CustomerRole
{
Id = 2,
_id = ObjectId.GenerateNewId().ToString(),
Name = "Forum Moderators",
Active = true,
IsSystemRole = true,
SystemName = SystemCustomerRoleNames.ForumModerators,
};
_customerRoleRepository.Insert(crForumModerators);
var crRegistered = new CustomerRole
{
Id = 3,
_id = ObjectId.GenerateNewId().ToString(),
Name = "Registered",
Active = true,
IsSystemRole = true,
SystemName = SystemCustomerRoleNames.Registered,
};
_customerRoleRepository.Insert(crRegistered);
var crGuests = new CustomerRole
{
Id = 4,
_id = ObjectId.GenerateNewId().ToString(),
Name = "Guests",
Active = true,
IsSystemRole = true,
SystemName = SystemCustomerRoleNames.Guests,
};
_customerRoleRepository.Insert(crGuests);
var crVendors = new CustomerRole
{
Id = 5,
_id = ObjectId.GenerateNewId().ToString(),
Name = "Vendors",
Active = true,
IsSystemRole = true,
SystemName = SystemCustomerRoleNames.Vendors,
};
_customerRoleRepository.Insert(crVendors);
//admin user
var adminUser = new Customer
{
CustomerGuid = Guid.NewGuid(),
Email = defaultUserEmail,
Username = defaultUserEmail,
Password = defaultUserPassword,
PasswordFormat = PasswordFormat.Clear,
PasswordSalt = "",
Active = true,
CreatedOnUtc = DateTime.UtcNow,
LastActivityDateUtc = DateTime.UtcNow,
};
var defaultAdminUserAddress = new Address
{
Id = 1,
_id = ObjectId.GenerateNewId().ToString(),
FirstName = "John",
LastName = "Smith",
PhoneNumber = "12345678",
Email = "[email protected]",
FaxNumber = "",
Company = "GrandNode LTD",
Address1 = "21 West 52nd Street",
Address2 = "",
City = "New York",
StateProvinceId = _stateProvinceRepository.Table.FirstOrDefault(sp => sp.Name == "New York").Id,
CountryId = _countryRepository.Table.FirstOrDefault(c => c.ThreeLetterIsoCode == "USA").Id,
ZipPostalCode = "10021",
CreatedOnUtc = DateTime.UtcNow,
};
adminUser.Addresses.Add(defaultAdminUserAddress);
adminUser.BillingAddress = defaultAdminUserAddress;
adminUser.ShippingAddress = defaultAdminUserAddress;
adminUser.CustomerRoles.Add(crAdministrators);
adminUser.CustomerRoles.Add(crForumModerators);
adminUser.CustomerRoles.Add(crRegistered);
_customerRepository.Insert(adminUser);
//set default customer name
_genericAttributeService.SaveAttribute(adminUser, SystemCustomerAttributeNames.FirstName, "John");
_genericAttributeService.SaveAttribute(adminUser, SystemCustomerAttributeNames.LastName, "Smith");
//.........这里部分代码省略.........
示例9: InsertCustomerRoleInCustomer
public virtual void InsertCustomerRoleInCustomer(CustomerRole customerRole)
{
if (customerRole == null)
throw new ArgumentNullException("productWarehouse");
var updatebuilder = Builders<Customer>.Update;
var update = updatebuilder.AddToSet(p => p.CustomerRoles, customerRole);
_customerRepository.Collection.UpdateOneAsync(new BsonDocument("Id", customerRole.CustomerId), update);
}
示例10: DeleteCustomerRoleInCustomer
public virtual void DeleteCustomerRoleInCustomer(CustomerRole customerRole)
{
if (customerRole == null)
throw new ArgumentNullException("pwi");
var updatebuilder = Builders<Customer>.Update;
var update = updatebuilder.Pull(p => p.CustomerRoles, customerRole);
_customerRepository.Collection.UpdateOneAsync(new BsonDocument("Id", customerRole.CustomerId), update);
}
示例11: UpdateCustomerRole
/// <summary>
/// Updates the customer role
/// </summary>
/// <param name="customerRole">Customer role</param>
public virtual void UpdateCustomerRole(CustomerRole customerRole)
{
if (customerRole == null)
throw new ArgumentNullException("customerRole");
_customerRoleRepository.Update(customerRole);
var builder = Builders<Customer>.Filter;
var filter = builder.ElemMatch(x => x.CustomerRoles, y => y.Id == customerRole.Id);
var update = Builders<Customer>.Update
.Set(x => x.CustomerRoles.ElementAt(-1), customerRole);
var result = _customerRepository.Collection.UpdateManyAsync(filter, update).Result;
_cacheManager.RemoveByPattern(CUSTOMERROLES_PATTERN_KEY);
//event notification
_eventPublisher.EntityUpdated(customerRole);
}
示例12: Can_get_final_product_price_with_tier_prices_by_customerRole
public void Can_get_final_product_price_with_tier_prices_by_customerRole()
{
var product = new Product
{
Id = 1,
Name = "Product name 1",
Price = 12.34M,
CustomerEntersPrice = false,
Published = true,
};
//customer roles
var customerRole1 = new CustomerRole()
{
Id = 1,
Name = "Some role 1",
Active = true,
};
var customerRole2 = new CustomerRole()
{
Id = 2,
Name = "Some role 2",
Active = true,
};
//add tier prices
product.TierPrices.Add(new TierPrice()
{
Price = 10,
Quantity = 2,
Product= product,
CustomerRole = customerRole1
});
product.TierPrices.Add(new TierPrice()
{
Price = 9,
Quantity = 2,
Product = product,
CustomerRole = customerRole2
});
product.TierPrices.Add(new TierPrice()
{
Price = 8,
Quantity = 5,
Product= product,
CustomerRole = customerRole1
});
product.TierPrices.Add(new TierPrice()
{
Price = 5,
Quantity = 10,
Product = product,
CustomerRole = customerRole2
});
//set HasTierPrices property
product.HasTierPrices = true;
//customer
Customer customer = new Customer();
customer.CustomerRoles.Add(customerRole1);
_priceCalcService.GetFinalPrice(product, customer, 0, false, 1).ShouldEqual(12.34M);
_priceCalcService.GetFinalPrice(product, customer, 0, false, 2).ShouldEqual(10);
_priceCalcService.GetFinalPrice(product, customer, 0, false, 3).ShouldEqual(10);
_priceCalcService.GetFinalPrice(product, customer, 0, false, 5).ShouldEqual(8);
_priceCalcService.GetFinalPrice(product, customer, 0, false, 10).ShouldEqual(8);
}
示例13: InstallCustomersAndUsers
protected virtual void InstallCustomersAndUsers(string defaultUserEmail, string defaultUserPassword)
{
var crAdministrators = new CustomerRole
{
Name = "Administrators",
Active = true,
IsSystemRole = true,
SystemName = SystemCustomerRoleNames.Administrators,
};
var crForumModerators = new CustomerRole
{
Name = "Forum Moderators",
Active = true,
IsSystemRole = true,
SystemName = SystemCustomerRoleNames.ForumModerators,
};
var crRegistered = new CustomerRole
{
Name = "Registered",
Active = true,
IsSystemRole = true,
SystemName = SystemCustomerRoleNames.Registered,
};
var crGuests = new CustomerRole
{
Name = "Guests",
Active = true,
IsSystemRole = true,
SystemName = SystemCustomerRoleNames.Guests,
};
var crVendors = new CustomerRole
{
Name = "Vendors",
Active = true,
IsSystemRole = true,
SystemName = SystemCustomerRoleNames.Vendors,
};
var customerRoles = new List<CustomerRole>
{
crAdministrators,
crForumModerators,
crRegistered,
crGuests,
crVendors
};
_customerRoleRepository.Insert(customerRoles);
//admin user
var adminUser = new Customer
{
CustomerGuid = Guid.NewGuid(),
Email = defaultUserEmail,
Username = defaultUserEmail,
Password = defaultUserPassword,
PasswordFormat = PasswordFormat.Clear,
PasswordSalt = "",
Active = true,
CreatedOnUtc = DateTime.UtcNow,
LastActivityDateUtc = DateTime.UtcNow,
};
var defaultAdminUserAddress = new Address
{
FirstName = "John",
LastName = "Smith",
PhoneNumber = "12345678",
Email = defaultUserEmail,
FaxNumber = "",
Company = "Nop Solutions Ltd",
Address1 = "21 West 52nd Street",
Address2 = "",
City = "New York",
StateProvince = _stateProvinceRepository.Table.FirstOrDefault(sp => sp.Name == "New York"),
Country = _countryRepository.Table.FirstOrDefault(c => c.ThreeLetterIsoCode == "USA"),
ZipPostalCode = "10021",
CreatedOnUtc = DateTime.UtcNow,
};
adminUser.Addresses.Add(defaultAdminUserAddress);
adminUser.BillingAddress = defaultAdminUserAddress;
adminUser.ShippingAddress = defaultAdminUserAddress;
adminUser.CustomerRoles.Add(crAdministrators);
adminUser.CustomerRoles.Add(crForumModerators);
adminUser.CustomerRoles.Add(crRegistered);
_customerRepository.Insert(adminUser);
//set default customer name
_genericAttributeService.SaveAttribute(adminUser, SystemCustomerAttributeNames.FirstName, "John");
_genericAttributeService.SaveAttribute(adminUser, SystemCustomerAttributeNames.LastName, "Smith");
//second user
var secondUserEmail = "[email protected]";
var secondUser = new Customer
{
CustomerGuid = Guid.NewGuid(),
Email = secondUserEmail,
Username = secondUserEmail,
Password = "123456",
PasswordFormat = PasswordFormat.Clear,
PasswordSalt = "",
Active = true,
CreatedOnUtc = DateTime.UtcNow,
//.........这里部分代码省略.........
示例14: UpdateAttributeLocales
protected virtual void UpdateAttributeLocales(CustomerRole specificationAttribute, CustomerRoleModel model)
{
foreach (var localized in model.Locales)
{
_localizedEntityService.SaveLocalizedValue(specificationAttribute,
x => x.Description,
localized.Description,
localized.LanguageId);
}
}
示例15: InstallPermissions
/// <summary>
/// Install permissions
/// </summary>
/// <param name="permissionProvider">Permission provider</param>
public virtual void InstallPermissions(IPermissionProvider permissionProvider)
{
//install new permissions
var permissions = permissionProvider.GetPermissions();
foreach (var permission in permissions)
{
var permission1 = GetPermissionRecordBySystemName(permission.SystemName);
if (permission1 == null)
{
//new permission (install it)
permission1 = new PermissionRecord
{
Name = permission.Name,
SystemName = permission.SystemName,
Category = permission.Category,
};
//default customer role mappings
var defaultPermissions = permissionProvider.GetDefaultPermissions();
foreach (var defaultPermission in defaultPermissions)
{
var customerRole = _customerService.GetCustomerRoleBySystemName(defaultPermission.CustomerRoleSystemName);
if (customerRole == null)
{
//new role (save it)
customerRole = new CustomerRole
{
Name = defaultPermission.CustomerRoleSystemName,
Active = true,
SystemName = defaultPermission.CustomerRoleSystemName
};
_customerService.InsertCustomerRole(customerRole);
}
var defaultMappingProvided = (from p in defaultPermission.PermissionRecords
where p.SystemName == permission1.SystemName
select p).Any();
var mappingExists = (from p in customerRole.PermissionRecords
where p.SystemName == permission1.SystemName
select p).Any();
if (defaultMappingProvided && !mappingExists)
{
permission1.CustomerRoles.Add(customerRole);
}
}
//save new permission
InsertPermissionRecord(permission1);
//save localization
permission1.SaveLocalizedPermissionName(_localizationService, _languageService);
}
}
}