本文整理汇总了C#中MVCForum.Domain.DomainModel.MembershipRole类的典型用法代码示例。如果您正苦于以下问题:C# MembershipRole类的具体用法?C# MembershipRole怎么用?C# MembershipRole使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MembershipRole类属于MVCForum.Domain.DomainModel命名空间,在下文中一共展示了MembershipRole类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例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);
}
示例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());
}
}
示例4: RoleViewModelToRole
public static MembershipRole RoleViewModelToRole(RoleViewModel roleViewModel)
{
var viewModel = new MembershipRole
{
RoleName = roleViewModel.RoleName
};
return viewModel;
}
示例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;
}
示例6: RoleToRoleViewModel
public static RoleViewModel RoleToRoleViewModel(MembershipRole role)
{
var viewModel = new RoleViewModel
{
Id = role.Id,
RoleName = role.RoleName
};
return viewModel;
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
}
示例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;
}
示例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;
}
示例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);
}
示例14: HomeController
public HomeController(ILoggingService loggingService, IUnitOfWorkManager unitOfWorkManager, IActivityService activityService, IMembershipService membershipService,
ITopicService topicService, ILocalizationService localizationService, IRoleService roleService,
ISettingsService settingsService)
: base(loggingService, unitOfWorkManager, membershipService, localizationService, roleService, settingsService)
{
_topicService = topicService;
_activityService = activityService;
LoggedOnUser = UserIsAuthenticated ? MembershipService.GetUser(Username) : null;
UsersRole = LoggedOnUser == null ? RoleService.GetRole(AppConstants.GuestRoleName) : LoggedOnUser.Roles.FirstOrDefault();
}
示例15: UploadController
public UploadController(ILoggingService loggingService, IUnitOfWorkManager unitOfWorkManager,
IMembershipService membershipService, ILocalizationService localizationService, IRoleService roleService, ISettingsService settingsService,
IPostService postService, IUploadedFileService uploadedFileService)
: base(loggingService, unitOfWorkManager, membershipService, localizationService, roleService, settingsService)
{
_postService = postService;
_uploadedFileService = uploadedFileService;
LoggedOnUser = UserIsAuthenticated ? MembershipService.GetUser(Username) : null;
UsersRole = LoggedOnUser == null ? RoleService.GetRole(AppConstants.GuestRoleName) : LoggedOnUser.Roles.FirstOrDefault();
}