コード例 #1
0
        private async Task <(ApplicationUser, IList <Startechs> startechs, bool isLeader)> GetStartechsToStudyForUser(int userId)
        {
            if (userId == ThisUser.Id)
            {
                var user = await GetThisUser(returnOnlyStartechWhereUserIsLeader : false);

                return(user, FromUserToHisStartechs(user), false);
            }
            else
            {
                if (!(await authorizationService.AuthorizeAsync(httpContextAccessor.HttpContext.User, StartechPolicyHelper.AllStartechLeader)).Succeeded)
                {
                    throw new UnauthorizedAccessException("you should be a startech leader!");
                }

                var user = await dbContext.Users.Include(x => x.Startechs).FirstOrDefaultAsync(x => x.Id == userId);

                if (user is null)
                {
                    throw new StarpointManagerException("user not found");
                }

                return(user, user.Startechs.Select(x => x.Startech).Where(x => IsStartechLeader(x)).ToArray(), true);
            }
        }
コード例 #2
0
        public async Task <bool> IsMemberOrLeaderOf(Startechs startech, bool mustBeLeader = true)
        {
            if (!Enum.IsDefined(typeof(Startechs), startech))
            {
                return(false);
            }

            var authentificationState = await authentificationProvider.GetAuthenticationStateAsync();

            return((await authorizationService.AuthorizeAsync(authentificationState.User, StartechPolicyHelper.GetPolicyName(startech, mustBeLeader))).Succeeded);
        }
コード例 #3
0
 public async Task <IList <UserObject> > GetLeaders([FromRoute] string startechType)
 {
     if (startechType == Roles.Admin)
     {
         return((await UserManager.GetUsersInRoleAsync(Roles.Admin))
                .Select(x => new UserObject {
             Id = x.Id, UserName = x.UserName, NumberOfpoints = x.NumberOfPoints
         }).ToList());
     }
     else
     {
         Startechs startech = GetStarttechAsEnum(startechType);
         return(await DbContext.Users.Include(x => x.Startechs)
                .Where(x => x.Startechs.Any(y => y.Startech == startech && y.IsLeader))
                .Select(x => new UserObject {
             Id = x.Id, UserName = x.UserName, NumberOfpoints = x.NumberOfPoints
         }).ToListAsync());
     }
 }
コード例 #4
0
        private StarpointsItem CreateItemToUpdate(ValidationState state = ValidationState.InStudy, Startechs startech = Startechs.Dotnet, int userId = 5)
        {
            var starpoint = new StarpointsItem
            {
                Id = WorkingStarpointItemId,
                ApplicationUserId = userId,
                Startech          = startech,
                Type            = BlogArticle,
                NumberOfPoints  = 15,
                ValidationState = state,
                Date            = DateTime.Now
            };

            DbContext.Add(starpoint);
            DbContext.SaveChanges();

            return(starpoint);
        }
コード例 #5
0
 public static string GetStartechClaimType(Startechs startech)
 {
     return($"StartechMember::{startech}");
 }
コード例 #6
0
 public static string GetPolicyName(Startechs startech, bool MustBeLeader = false)
 {
     return($"Startech::{startech}::{(MustBeLeader ? StartechClaimHelper.Leader : StartechClaimHelper.Member) }");
 }
コード例 #7
0
 private bool IsStartechLeader(Startechs x)
 {
     return(authorizationService.AuthorizeAsync(httpContextAccessor.HttpContext.User, StartechPolicyHelper.GetPolicyName(x, MustBeLeader: true)).GetAwaiter().GetResult().Succeeded);
 }
コード例 #8
0
        private StarpointsItem CreateItemToUpdateStatus(ValidationState state = ValidationState.InStudy, Startechs startech = Startechs.Dotnet)
        {
            var starpoint = new StarpointsItem
            {
                Id = WorkingStarpointItemId,
                ApplicationUserId = MemberDotnet.Id,
                Startech          = startech,
                NumberOfPoints    = NumberOfPointOfWorkingStapointItem,
                ValidationState   = state,
                Date = DateTime.Now
            };

            DbContext.Add(starpoint);
            DbContext.SaveChanges();

            return(starpoint);
        }