コード例 #1
0
        public IActionResult Universities()
        {
            ConfigureListBreadcrumbs();

            if (User.IsInRole(Roles.MainModeratorRole))
            {
                var identityUserId          = User.FindFirstValue(ClaimTypes.NameIdentifier);
                var appUser                 = _userservice.FindByIdentityUserId(identityUserId);
                var mainModeratorUniversity = _mainModeratorService.GetUniversityMainModerator(appUser.UserId);
                var university              = _traversalService.GetUniversity(mainModeratorUniversity.UniversityId);

                var universityViewModel = new List <UniversityViewModel>
                {
                    new UniversityViewModel
                    {
                        Id = university.UniversityId,
                        TitleOrFullName        = university.Name,
                        SubtitleOrAbbreviation = university.Abbreviation
                    }
                };

                var vm = new ListViewModel <UniversityViewModel>
                {
                    Items           = universityViewModel,
                    IsWithSubtitles = true
                };

                return(View(vm));
            }
            else
            {
                var universities = _traversalService.GetUniversities();

                var universityViewModels = universities.Select(u =>
                                                               new UniversityViewModel
                {
                    Id = u.UniversityId,
                    TitleOrFullName        = u.Name,
                    SubtitleOrAbbreviation = u.Abbreviation,
                }
                                                               ).ToList();

                var vm = new ListViewModel <UniversityViewModel>
                {
                    Items           = universityViewModels,
                    IsWithSubtitles = true
                };

                return(View(vm));
            }
        }
コード例 #2
0
        public async Task <IActionResult> DemoteToMember(string userId)
        {
            var userToDemote = await _roleService.FindByIdAsync(userId);

            if (userToDemote == null)
            {
                return(RedirectToAction("ResourceNotFound", "Error", new { error = "użytkownik o podanym Id nie istnieje." }));
            }

            var userRoles = (await _roleService.GetRolesAsync(userToDemote)).ToArray();
            await _roleService.RemoveFromRolesAsync(userToDemote, userRoles);

            await _roleService.AddToRoleAsync(userToDemote, Roles.MemberRole);

            var appUser = _userService.FindByIdentityUserId(userId);
            var moderatorInUniversity = _mainModeratorService.GetUniversityMainModerator(appUser.UserId);

            if (moderatorInUniversity != null)
            {
                _mainModeratorService.UnassignMainModeratorFromUniversity(moderatorInUniversity);
            }

            return(RedirectToAction("Home"));
        }