コード例 #1
0
        public async Task <bool> HasAccessAsync(DatabaseEntities.User user)
        {
            var roles = await _userManager.GetRolesAsync(user);

            foreach (var role in roles)
            {
                if (Roles.HeadsAndHeadDeputiesAndAdmin.Contains(role))
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #2
0
ファイル: ClubAccessService.cs プロジェクト: Toxa2202/plast
        public async Task <IEnumerable <ClubDTO> > GetClubsAsync(DatabaseEntities.User user)
        {
            var roles = await _userManager.GetRolesAsync(user);

            foreach (var key in _clubAccessGetters.Keys)
            {
                if (roles.Contains(key))
                {
                    var cities = await _clubAccessGetters[key].GetClubs(user.Id);
                    return(_mapper.Map <IEnumerable <DatabaseEntities.Club>, IEnumerable <ClubDTO> >(cities));
                }
            }
            return(Enumerable.Empty <ClubDTO>());
        }
コード例 #3
0
ファイル: RegionAccessService.cs プロジェクト: Toxa2202/plast
        public async Task <IEnumerable <RegionDTO> > GetRegionsAsync(DatabaseEntities.User claimsPrincipal)
        {
            var roles = await _userManager.GetRolesAsync(claimsPrincipal);

            foreach (var key in _regionAccessGetters.Keys)
            {
                if (roles.Contains(key))
                {
                    var regions = await _regionAccessGetters[key].GetRegionAsync(claimsPrincipal.Id);
                    return(_mapper.Map <IEnumerable <DatabaseEntities.Region>, IEnumerable <RegionDTO> >(regions));
                }
            }
            return(Enumerable.Empty <RegionDTO>());
        }
コード例 #4
0
ファイル: CityService.cs プロジェクト: Toxa2202/plast
        /// <inheritdoc />
        public async Task <CityProfileDTO> GetCityProfileAsync(int cityId, DataAccessCity.User user)
        {
            var cityProfileDto = await GetCityProfileAsync(cityId);

            var userId = await _userManager.GetUserIdAsync(user);

            var userRoles = await _userManager.GetRolesAsync(user);

            cityProfileDto.City.CanCreate = userRoles.Contains("Admin");
            cityProfileDto.City.CanEdit   = await _cityAccessService.HasAccessAsync(user, cityId);

            cityProfileDto.City.CanJoin = (await _repoWrapper.CityMembers
                                           .GetFirstOrDefaultAsync(u => u.User.Id == userId && u.CityId == cityId)) == null;

            return(cityProfileDto);
        }
コード例 #5
0
ファイル: ClubService.cs プロジェクト: Toxa2202/plast
        /// <inheritdoc />
        public async Task <ClubProfileDTO> GetClubProfileAsync(int ClubId, DataAccessClub.User user)
        {
            var ClubProfileDto = await GetClubProfileAsync(ClubId);

            var userId = await _userManager.GetUserIdAsync(user);

            var userRoles = await _userManager.GetRolesAsync(user);

            ClubProfileDto.Club.CanCreate = userRoles.Contains("Admin");
            ClubProfileDto.Club.CanEdit   = await _clubAccessService.HasAccessAsync(user, ClubId);

            ClubProfileDto.Club.CanJoin = (await _repoWrapper.ClubMembers
                                           .GetFirstOrDefaultAsync(u => u.User.Id == userId && u.ClubId == ClubId)) == null;

            return(ClubProfileDto);
        }
コード例 #6
0
ファイル: ClubAccessService.cs プロジェクト: Toxa2202/plast
        public async Task <bool> HasAccessAsync(DatabaseEntities.User user, int ClubId)
        {
            var cities = await this.GetClubsAsync(user);

            return(cities.Any(c => c.ID == ClubId));
        }
コード例 #7
0
ファイル: RegionAccessService.cs プロジェクト: Toxa2202/plast
        public async Task <bool> HasAccessAsync(DatabaseEntities.User claimsPrincipal, int regionId)
        {
            var regions = await GetRegionsAsync(claimsPrincipal);

            return(regions.Any(c => c.ID == regionId));
        }
コード例 #8
0
        public async Task <IEnumerable <CityForAdministrationDTO> > GetAllCitiesIdAndName(DatabaseEntities.User user)
        {
            IEnumerable <CityForAdministrationDTO> options = Enumerable.Empty <CityForAdministrationDTO>();
            var roles = await _userManager.GetRolesAsync(user);

            var citiesId =
                (await _repositoryWrapper.AnnualReports.GetAllAsync(predicate: x => x.Date.Year == DateTime.Now.Year))
                .Select(x => x.CityId).ToList();

            if (roles.Contains(Roles.Admin))
            {
                options = _mapper.Map <IEnumerable <DatabaseEntities.City>, IEnumerable <CityForAdministrationDTO> >(
                    await _cityAccessGetters[Roles.Admin].GetCities(user.Id));
            }
            else if (roles.Contains(Roles.CityHead) || roles.Contains(Roles.CityHeadDeputy))
            {
                options = _mapper.Map <IEnumerable <DatabaseEntities.City>, IEnumerable <CityForAdministrationDTO> >(
                    await _cityAccessGetters[Roles.CityHead].GetCities(user.Id));
            }
            foreach (var item in options)
            {
                item.HasReport = citiesId.Any(x => x == item.ID);
            }

            return(options);
        }
コード例 #9
0
        public async Task <IEnumerable <RegionForAdministrationDTO> > GetAllRegionsIdAndName(DatabaseEntities.User user)
        {
            IEnumerable <RegionForAdministrationDTO> options = Enumerable.Empty <RegionForAdministrationDTO>();
            var roles = await _userManager.GetRolesAsync(user);

            var reports = await _repositoryWrapper.RegionAnnualReports.GetAllAsync();

            IEnumerable <(int regionId, int year)> regionsId = reports.Select(x => (x.RegionId, x.Date.Year)).ToList();

            foreach (var key in _regionAccessGetters.Keys)
            {
                if (roles.Contains(key))
                {
                    options = _mapper.Map <IEnumerable <DatabaseEntities.Region>, IEnumerable <RegionForAdministrationDTO> >(
                        await _regionAccessGetters[key].GetRegionAsync(user.Id));
                    break;
                }
            }
            foreach (var item in options)
            {
                item.YearsHasReport = regionsId.Where(x => x.regionId == item.ID).Select(x => x.year).ToList();
            }

            return(options);
        }
コード例 #10
0
        public async Task <IEnumerable <ClubForAdministrationDTO> > GetAllClubsIdAndName(DatabaseEntities.User user)
        {
            IEnumerable <ClubForAdministrationDTO> options = Enumerable.Empty <ClubForAdministrationDTO>();
            var roles = await _userManager.GetRolesAsync(user);

            var clubsId =
                (await _repositoryWrapper.ClubAnnualReports.GetAllAsync(predicate: x => x.Date.Year == DateTime.Now.Year))
                .Select(x => x.ClubId).ToList();

            foreach (var key in _clubAccessGetters.Keys)
            {
                if (roles.Contains(key))
                {
                    options = _mapper.Map <IEnumerable <DatabaseEntities.Club>, IEnumerable <ClubForAdministrationDTO> >(
                        await _clubAccessGetters[key].GetClubs(user.Id));
                    break;
                }
            }
            foreach (var item in options)
            {
                item.HasReport = clubsId.Any(x => x == item.ID);
            }

            return(options);
        }