本文整理汇总了C#中MVCForum.Domain.DomainModel.MembershipRole类的典型用法代码示例。如果您正苦于以下问题:C# MembershipRole类的具体用法?C# MembershipRole怎么用?C# MembershipRole使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MembershipRole类属于MVCForum.Domain.DomainModel命名空间,在下文中一共展示了MembershipRole类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetCategoryRow
public IList<CategoryPermissionForRole> GetCategoryRow(MembershipRole role, Category cat)
{
return _context.CategoryPermissionForRole
.Where(x => x.Category.Id == cat.Id &&
x.MembershipRole.Id == role.Id)
.ToList();
}
开发者ID:kangjh0815,项目名称:test,代码行数:7,代码来源:CategoryPermissionForRoleRepository.cs
示例2: AddPost
public void AddPost()
{
var postRepository = Substitute.For<IPostRepository>();
var topicRepository = Substitute.For<ITopicRepository>();
var roleService = Substitute.For<IRoleService>();
var membershipUserPointsService = Substitute.For<IMembershipUserPointsService>();
var settingsService = Substitute.For<ISettingsService>();
settingsService.GetSettings().Returns(new Settings { PointsAddedPerPost = 20 });
var localisationService = Substitute.For<ILocalizationService>();
var postService = new PostService(membershipUserPointsService, settingsService, roleService, postRepository, topicRepository, localisationService, _api);
var category = new Category();
var role = new MembershipRole{RoleName = "TestRole"};
var categoryPermissionForRoleSet = new List<CategoryPermissionForRole>
{
new CategoryPermissionForRole { Permission = new Permission { Name = AppConstants.PermissionEditPosts }, IsTicked = true},
new CategoryPermissionForRole { Permission = new Permission { Name = AppConstants.PermissionDenyAccess }, IsTicked = false},
new CategoryPermissionForRole { Permission = new Permission { Name = AppConstants.PermissionReadOnly }, IsTicked = false}
};
var permissionSet = new PermissionSet(categoryPermissionForRoleSet);
roleService.GetPermissions(category, role).Returns(permissionSet);
var topic = new Topic { Name = "Captain America", Category = category};
var user = new MembershipUser {
UserName = "SpongeBob",
Roles = new List<MembershipRole>{role}
};
var newPost = postService.AddNewPost("A test post", topic, user, out permissionSet);
Assert.AreEqual(newPost.User, user);
Assert.AreEqual(newPost.Topic, topic);
}
开发者ID:kangjh0815,项目名称:test,代码行数:35,代码来源:PostServiceTests.cs
示例3: Delete_Check_In_Use_By
public void Delete_Check_In_Use_By()
{
var roleRepository = Substitute.For<IRoleRepository>();
var categoryPermissionForRoleRepository = Substitute.For<ICategoryPermissionForRoleRepository>();
var permissionRepository = Substitute.For<IPermissionRepository>();
var roleService = new RoleService(roleRepository, categoryPermissionForRoleRepository, permissionRepository);
var role = new MembershipRole
{
Users = new List<MembershipUser>
{
new MembershipUser {UserName = "Hawkeye"},
new MembershipUser {UserName = "Blackwidow"}
},
RoleName = "Role Name"
};
try
{
roleService.Delete(role);
}
catch (InUseUnableToDeleteException ex)
{
Assert.IsTrue(ex.BlockingEntities.Any());
}
}
开发者ID:kangjh0815,项目名称:test,代码行数:26,代码来源:RoleServiceTests.cs
示例4: RoleViewModelToRole
public static MembershipRole RoleViewModelToRole(RoleViewModel roleViewModel)
{
var viewModel = new MembershipRole
{
RoleName = roleViewModel.RoleName
};
return viewModel;
}
开发者ID:ivanchen52,项目名称:mvcforum,代码行数:8,代码来源:ViewModelMapping.cs
示例5: Update
public void Update(MembershipRole item)
{
// Check there's not an object with same identifier already in context
if (_context.MembershipRole.Local.Select(x => x.Id == item.Id).Any())
{
throw new ApplicationException("Object already exists in context - you do not need to call Update. Save occurs on Commit");
}
_context.Entry(item).State = EntityState.Modified;
}
开发者ID:huchao007,项目名称:mvcforum,代码行数:9,代码来源:RoleRepository.cs
示例6: RoleToRoleViewModel
public static RoleViewModel RoleToRoleViewModel(MembershipRole role)
{
var viewModel = new RoleViewModel
{
Id = role.Id,
RoleName = role.RoleName
};
return viewModel;
}
开发者ID:ivanchen52,项目名称:mvcforum,代码行数:9,代码来源:ViewModelMapping.cs
示例7: GetCategoryRow
/// <summary>
/// Returns a row with the permission and CPFR
/// </summary>
/// <param name="role"></param>
/// <param name="cat"></param>
/// <returns></returns>
public Dictionary<Permission, CategoryPermissionForRole> GetCategoryRow(MembershipRole role, Category cat)
{
var catRowList = _context.CategoryPermissionForRole
.Include(x => x.MembershipRole)
.Include(x => x.Category)
.AsNoTracking()
.Where(x => x.Category.Id == cat.Id &&
x.MembershipRole.Id == role.Id)
.ToList();
return catRowList.ToDictionary(catRow => catRow.Permission);
}
开发者ID:ivanchen52,项目名称:mvcforum,代码行数:17,代码来源:CategoryPermissionForRoleService.cs
示例8: GetAllowedCategories
/// <summary>
/// Return allowed categories based on the users role
/// </summary>
/// <param name="role"></param>
/// <returns></returns>
public IEnumerable<Category> GetAllowedCategories(MembershipRole role)
{
var filteredCats = new List<Category>();
var allCats = _categoryRepository.GetAll().ToList();
foreach (var category in allCats)
{
var permissionSet = _roleService.GetPermissions(category, role);
if (!permissionSet[AppConstants.PermissionDenyAccess].IsTicked)
{
filteredCats.Add(category);
}
}
return filteredCats;
}
开发者ID:StefanoPireddu,项目名称:mvcforum,代码行数:19,代码来源:CategoryService.cs
示例9: Delete_Exception_If_Role_Has_Multiple_Users
public void Delete_Exception_If_Role_Has_Multiple_Users()
{
var roleRepository = Substitute.For<IRoleRepository>();
var categoryPermissionForRoleRepository = Substitute.For<ICategoryPermissionForRoleRepository>();
var permissionRepository = Substitute.For<IPermissionRepository>();
var roleService = new RoleService(roleRepository, categoryPermissionForRoleRepository, permissionRepository);
var role = new MembershipRole
{
Users = new List<MembershipUser>
{
new MembershipUser {UserName = "Hawkeye"},
new MembershipUser {UserName = "Blackwidow"}
},
RoleName = "Role Name"
};
roleService.Delete(role);
}
开发者ID:kangjh0815,项目名称:test,代码行数:19,代码来源:RoleServiceTests.cs
示例10: Delete
/// <summary>
/// Delete a role
/// </summary>
/// <param name="role"></param>
public void Delete(MembershipRole role)
{
// Check if anyone else if using this role
var okToDelete = role.Users.Count == 0;
if (okToDelete)
{
// Get any categorypermissionforoles and delete these first
var rolesToDelete = _categoryPermissionForRoleRepository.GetByRole(role.Id);
foreach (var categoryPermissionForRole in rolesToDelete)
{
_categoryPermissionForRoleRepository.Delete(categoryPermissionForRole);
}
_roleRepository.Delete(role);
}
else
{
var inUseBy = new List<Entity>();
inUseBy.AddRange(role.Users);
throw new InUseUnableToDeleteException(inUseBy);
}
}
开发者ID:kangjh0815,项目名称:test,代码行数:28,代码来源:RoleService.cs
示例11: GetOtherPermissions
/// <summary>
/// Get permissions for roles other than those specially treated in this class
/// </summary>
/// <param name="category"></param>
/// <param name="role"></param>
/// <returns></returns>
private PermissionSet GetOtherPermissions(Category category, MembershipRole role)
{
// Get all permissions
var permissionList = _permissionRepository.GetAll();
// Get the known permissions for this role and category
var categoryRow = _categoryPermissionForRoleRepository.GetCategoryRow(role, category);
var categoryRowPermissions = categoryRow.ToDictionary(catRow => catRow.Permission);
// Load up the results with the permisions for this role / cartegory. A null entry for a permissions results in a new
// record with a false value
var permissions = new List<CategoryPermissionForRole>();
foreach (var permission in permissionList)
{
permissions.Add(categoryRowPermissions.ContainsKey(permission)
? categoryRowPermissions[permission]
: new CategoryPermissionForRole { Category = category, MembershipRole = role, IsTicked = false, Permission = permission });
}
var permissionSet = new PermissionSet(permissions);
return permissionSet;
}
开发者ID:kangjh0815,项目名称:test,代码行数:29,代码来源:RoleService.cs
示例12: GetAllowedCategoriesCode
private List<Category> GetAllowedCategoriesCode(MembershipRole role, string actionType)
{
var filteredCats = new List<Category>();
var allCats = GetAll();
foreach (var category in allCats)
{
var permissionSet = _roleService.GetPermissions(category, role);
if (!permissionSet[actionType].IsTicked)
{
filteredCats.Add(category);
}
}
return filteredCats;
}
开发者ID:huchao007,项目名称:mvcforum,代码行数:14,代码来源:CategoryService.cs
示例13: GetAllowedCategories
public List<Category> GetAllowedCategories(MembershipRole role, string actionType)
{
if (HttpContext.Current != null)
{
// Store per request
var key = string.Concat("allowed-categories", role.Id, actionType);
if (!HttpContext.Current.Items.Contains(key))
{
HttpContext.Current.Items.Add(key, GetAllowedCategoriesCode(role, actionType));
}
return (List<Category>)HttpContext.Current.Items[key];
}
return GetAllowedCategoriesCode(role, actionType);
}
开发者ID:huchao007,项目名称:mvcforum,代码行数:14,代码来源:CategoryService.cs
示例14: CreateInitialData
private InstallerResult CreateInitialData()
{
var installerResult = new InstallerResult { Successful = true, Message = "Congratulations, MVC Forum has installed successfully" };
// I think this is all I need to call to kick EF into life
//EFCachingProviderConfiguration.DefaultCache = new AspNetCache();
//EFCachingProviderConfiguration.DefaultCachingPolicy = CachingPolicy.CacheAll;
// Now setup the services as we can't do it in the constructor
InitialiseServices();
// First UOW to create the data needed for other saves
using (var unitOfWork = _UnitOfWorkManager.NewUnitOfWork())
{
try
{
// Check if category exists or not, we only do a single check for the first object within this
// UOW because, if anything failed inside. Everything else would be rolled back to because of the
// transaction
const string exampleCatName = "Example Category";
if (_categoryService.GetAll().FirstOrDefault(x => x.Name == exampleCatName) == null)
{
// Doesn't exist so add the example category
var exampleCat = new Category { Name = exampleCatName, ModeratePosts = false, ModerateTopics = false};
_categoryService.Add(exampleCat);
// Add the default roles
var standardRole = new MembershipRole { RoleName = "Standard Members" };
var guestRole = new MembershipRole { RoleName = "Guest" };
var moderatorRole = new MembershipRole { RoleName = "Moderator" };
var adminRole = new MembershipRole { RoleName = "Admin" };
_roleService.CreateRole(standardRole);
_roleService.CreateRole(guestRole);
_roleService.CreateRole(moderatorRole);
_roleService.CreateRole(adminRole);
unitOfWork.Commit();
}
}
catch (Exception ex)
{
unitOfWork.Rollback();
installerResult.Exception = ex.InnerException;
installerResult.Message = "Error creating the initial data >> Category & Roles";
installerResult.Successful = false;
return installerResult;
}
}
// Add / Update the default language strings
installerResult = AddOrUpdateTheDefaultLanguageStrings(installerResult);
if (!installerResult.Successful)
{
return installerResult;
}
// Now we have saved the above we can create the rest of the data
using (var unitOfWork = _UnitOfWorkManager.NewUnitOfWork())
{
try
{
// if the settings already exist then do nothing
if (_settingsService.GetSettings(false) == null)
{
// Get the default language
var startingLanguage = _localizationService.GetLanguageByName("en-GB");
// Get the Standard Members role
var startingRole = _roleService.GetRole("Standard Members");
// create the settings
var settings = new Settings
{
ForumName = "MVC Forum",
ForumUrl = "http://www.mydomain.com",
IsClosed = false,
EnableRSSFeeds = true,
DisplayEditedBy = true,
EnablePostFileAttachments = false,
EnableMarkAsSolution = true,
EnableSpamReporting = true,
EnableMemberReporting = true,
EnableEmailSubscriptions = true,
ManuallyAuthoriseNewMembers = false,
EmailAdminOnNewMemberSignUp = true,
TopicsPerPage = 20,
PostsPerPage = 20,
EnablePrivateMessages = true,
MaxPrivateMessagesPerMember = 50,
PrivateMessageFloodControl = 1,
EnableSignatures = false,
EnablePoints = true,
PointsAllowedToVoteAmount = 1,
PointsAddedPerPost = 1,
PointsAddedForSolution = 4,
PointsDeductedNagativeVote = 2,
AdminEmailAddress = "[email protected]",
NotificationReplyEmail = "[email protected]",
SMTPEnableSSL = false,
//.........这里部分代码省略.........
开发者ID:StefanoPireddu,项目名称:mvcforum,代码行数:101,代码来源:InstallController.cs
示例15: GetPermissions
/// <summary>
/// Returns permission set based on category and role
/// </summary>
/// <param name="category"></param>
/// <param name="role"></param>
/// <returns></returns>
public PermissionSet GetPermissions(Category category, MembershipRole role)
{
// Pass the role in to see select which permissions to apply
// Going to cache this per request, just to help with performance
var objectContextKey = string.Concat(HttpContext.Current.GetHashCode().ToString("x"), "-", category.Id, "-", role.Id);
if (!HttpContext.Current.Items.Contains(objectContextKey))
{
switch (role.RoleName)
{
case AppConstants.AdminRoleName:
_permissions = GetAdminPermissions(category, role);
break;
case AppConstants.GuestRoleName:
_permissions = GetGuestPermissions(category, role);
break;
default:
_permissions = GetOtherPermissions(category, role);
break;
}
HttpContext.Current.Items.Add(objectContextKey, _permissions);
}
return HttpContext.Current.Items[objectContextKey] as PermissionSet;
}
开发者ID:kangjh0815,项目名称:test,代码行数:31,代码来源:RoleService.cs
示例16: BeforePostMadeCancel
public void BeforePostMadeCancel()
{
var postRepository = Substitute.For<IPostRepository>();
var topicRepository = Substitute.For<ITopicRepository>();
var roleService = Substitute.For<IRoleService>();
var membershipUserPointsService = Substitute.For<IMembershipUserPointsService>();
var settingsService = Substitute.For<ISettingsService>();
var localisationService = Substitute.For<ILocalizationService>();
var postService = new PostService(membershipUserPointsService, settingsService, roleService, postRepository, topicRepository, localisationService, _api);
var category = new Category();
var role = new MembershipRole { RoleName = "TestRole" };
var categoryPermissionForRoleSet = new List<CategoryPermissionForRole>
{
new CategoryPermissionForRole { Permission = new Permission { Name = AppConstants.PermissionEditPosts }, IsTicked = true},
new CategoryPermissionForRole { Permission = new Permission { Name = AppConstants.PermissionDenyAccess }, IsTicked = false},
new CategoryPermissionForRole { Permission = new Permission { Name = AppConstants.PermissionReadOnly }, IsTicked = false}
};
var permissionSet = new PermissionSet(categoryPermissionForRoleSet);
roleService.GetPermissions(category, role).Returns(permissionSet);
var topic = new Topic { Name = "Captain America", Category = category };
var user = new MembershipUser
{
UserName = "SpongeBob",
Roles = new List<MembershipRole>() { role }
};
EventManager.Instance.BeforePostMade += eventsService_BeforePostMadeCancel;
postService.AddNewPost("A test post", topic, user, out permissionSet);
membershipUserPointsService.DidNotReceive().Add(Arg.Is<MembershipUserPoints>(x => x.User == user));
EventManager.Instance.BeforePostMade -= eventsService_BeforePostMadeCancel;
}
开发者ID:StefanoPireddu,项目名称:mvcforum,代码行数:37,代码来源:EventManagerTests.cs
示例17: GetCategoryRow
/// <summary>
/// Returns a row with the permission and CPFR
/// </summary>
/// <param name="role"></param>
/// <param name="cat"></param>
/// <returns></returns>
public Dictionary<Permission, CategoryPermissionForRole> GetCategoryRow(MembershipRole role, Category cat)
{
var catRowList = _categoryPermissionForRoleService.GetCategoryRow(role, cat);
return catRowList.ToDictionary(catRow => catRow.Permission);
}
开发者ID:kangjh0815,项目名称:test,代码行数:11,代码来源:CategoryPermissionForRoleService.cs
示例18: GetGuestPermissions
/// <summary>
/// Guest = Not logged in, so only need to check the access permission
/// </summary>
/// <param name="category"></param>
/// <param name="role"></param>
private PermissionSet GetGuestPermissions(Category category, MembershipRole role)
{
// Get all the permissions
var permissionList = _permissionRepository.GetAll();
// Make a CategoryPermissionForRole for each permission that exists,
// but only set the read-only permission to true for this role / category. All others false
var permissions = permissionList.Select(permission => new CategoryPermissionForRole
{
Category = category,
IsTicked = permission.Name == AppConstants.PermissionReadOnly,
MembershipRole = role,
Permission = permission
}).ToList();
// Deny Access may have been set (or left null) for guest for the category, so need to read for it
var denyAccessPermission = role.CategoryPermissionForRole
.FirstOrDefault(x => x.Category == category &&
x.Permission.Name == AppConstants.PermissionDenyAccess &&
x.MembershipRole == role);
// Set the Deny Access value in the results. If it's null for this role/category, record it as false in the results
var categoryPermissionForRole = permissions.FirstOrDefault(x => x.Permission.Name == AppConstants.PermissionDenyAccess);
if (categoryPermissionForRole != null)
{
categoryPermissionForRole.IsTicked = denyAccessPermission != null && denyAccessPermission.IsTicked;
}
var permissionSet = new PermissionSet(permissions);
return permissionSet;
}
开发者ID:kangjh0815,项目名称:test,代码行数:37,代码来源:RoleService.cs
示例19: Save
/// <summary>
/// Save a role
/// </summary>
/// <param name="role"></param>
public void Save(MembershipRole role)
{
role.RoleName = StringUtils.SafePlainText(role.RoleName);
_roleRepository.Update(role);
}
开发者ID:kangjh0815,项目名称:test,代码行数:9,代码来源:RoleService.cs
示例20: CreateRole
/// <summary>
/// Create a new role
/// </summary>
/// <param name="role"></param>
public void CreateRole(MembershipRole role)
{
role.RoleName = StringUtils.SafePlainText(role.RoleName);
_roleRepository.Add(role);
}
开发者ID:kangjh0815,项目名称:test,代码行数:9,代码来源:RoleService.cs
注:本文中的MVCForum.Domain.DomainModel.MembershipRole类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论