예제 #1
0
        public async Task <CampingTripFull> Get(string campingTripId)
        {
            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.GetUserRegisteredTripAsync(campingTripId));
            }
            else
            {
                var userIdClaim = claims.Where(claim => claim.Type == "user_id").First();

                if (userIdClaim == null)
                {
                    throw new Exception("user_id claim not found");
                }

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

                return(await campingTripRepository.GetUserRegisteredTripsForUserAsync(campingTripId, userId));
            }
        }