Ejemplo n.º 1
0
        public async Task <IEnumerable <CampingTripFull> > Get()
        {
            var identity = (ClaimsIdentity)User.Identity;
            IEnumerable <Claim> claims = identity.Claims;

            var role = claims.Where(claim => claim.Type == "role").First();

            if (role.Value == "Admin")
            {
                return(await campingTripRepository.GetAllUserRegisteredCompletedTripsAsync());
            }
            else
            {
                var userIdClaim = claims.Where(claim => claim.Type == "user_id")?.FirstOrDefault();

                if (!int.TryParse(userIdClaim.Value, out int userId))
                {
                    throw new System.Exception("Invalid value for claim user_id");
                }

                return(await campingTripRepository.GetAllUserRegisteredCompletedTripsForUserAsync(userId));
            }
        }