当前位置: 首页>>代码示例>>C#>>正文


C# DomainModel.MembershipRole类代码示例

本文整理汇总了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();
 }
开发者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: 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();
        }
开发者ID:kangjh0815,项目名称:test,代码行数:11,代码来源:HomeController.cs

示例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();
        }
开发者ID:R3MUSDevPack,项目名称:Forums,代码行数:11,代码来源:UploadController.cs


注:本文中的MVCForum.Domain.DomainModel.MembershipRole类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。