Esempio n. 1
0
        public async static void ConfigureRoles()
        {
            var identityManager = new IdentityManager();

            const string superAdminRole = "SuperAdmin";
            const string adminUser = "******";

            var roles = new List<string>() {superAdminRole, "Admin", "Moderator", "Member", "Guest"};

            foreach (var role in roles)
            {
                if (!identityManager.RoleExists(role))
                {
                    identityManager.CreateRole(role);
                }
            }

            if (!await identityManager.UserExistsAsync(adminUser))
            {
                await identityManager.CreateUserAsync(new ApplicationUser()
                {
                    UserName = adminUser
                },
                "jk/2eRb296#{1=m");
            }

            if (!identityManager.IsUserInRole(identityManager.GetUserIdByName(adminUser), superAdminRole))
                await
                    identityManager.AddUserToRoleAsync(await identityManager.GetUserIdByNameAsync(adminUser),
                        superAdminRole);

            if (!identityManager.IsUserInRole(identityManager.GetUserIdByName(adminUser), "Admin"))
                await
                    identityManager.AddUserToRoleAsync(await identityManager.GetUserIdByNameAsync(adminUser),
                        "Admin");
        }
Esempio n. 2
0
        public async Task<ActionResult> ViewThread(int threadId, int page = 1, ViewSortOrder sortOrder = ViewSortOrder.DateAscending )
        {
            var identityManager = new IdentityManager();
            var thread = await this.db.Threads.SingleOrDefaultAsync(t => t.ThreadId == threadId);

            ForumPostsViewModel model =
                ForumMapping.ForumPostsToForumPostsViewModel(
                    new ForumItems().WithThreadId(threadId).WithPageSize(
                        this.pageSize).WithSortOrder(sortOrder).Posts(page),
                        thread,
                        sortOrder,
                        page,
                        this.pageSize);

            foreach (var post in model.ForumPosts)
            {
                var userId = await identityManager.GetUserIdByNameAsync(post.Username);
                var tag = "Guest";

                if (!string.IsNullOrEmpty(userId))
                {
                    if (identityManager.IsUserInRole(userId, "Member"))
                    {
                        tag = "Member";
                    }
                    else if (identityManager.IsUserInRole(userId, "Moderator"))
                    {
                        tag = "Moderator";
                    }
                    else if (identityManager.IsUserInRole(userId, "Admin"))
                    {
                        tag = "Admin";
                    }
                }

                post.UserTag = tag;

                var post1 = post;
                post.UserPosts = User.Identity.IsAuthenticated
                    ? await db.ForumPosts.CountAsync(p => p.Username == post1.Username)
                    : 0;

            }

            this.UpdateCategoryList();

            model.ParentThread.CategoryName =
                CategoryList.SingleOrDefault(c => thread != null && c.Key == thread.CategoryId).Value;
            
            return this.View(model);
        }