public IActionResult GetAccommodations(int groupId, int subgroupId, int attendeeId)
        {
            var userIdentifier = _registrationAuthorizationService.GetCurrentUserIdentifier(User);

            if (userIdentifier == null)
            {
                return(BadRequest());
            }

            if (!_registrationAuthorizationService.IsAuthorized(userIdentifier, subgroupId))
            {
                return(Unauthorized());
            }

            var attendeeEntity = _registrationRepository.GetAttendee(subgroupId, attendeeId);

            if (attendeeEntity == null)
            {
                return(NotFound());
            }

            var accommodationDto = new List <AccommodationDto>();

            foreach (var attendeeAccommodation in attendeeEntity.AttendeeAccommodations)
            {
                var accommodation = _registrationRepository.GetAccommodations().FirstOrDefault(a => a.Id == attendeeAccommodation.AccommodationId);
                accommodationDto.Add(Mapper.Map <AccommodationDto>(accommodation));
            }

            return(Ok(accommodationDto));
        }
        public IActionResult GetMeritBadges(int groupId, int subgroupId, int attendeeId)
        {
            var userIdentifier = _registrationAuthorizationService.GetCurrentUserIdentifier(User);

            if (userIdentifier == null)
            {
                return(BadRequest());
            }

            if (!_registrationAuthorizationService.IsAuthorized(userIdentifier, subgroupId))
            {
                return(Unauthorized());
            }

            var attendeeEntity = _registrationRepository.GetAttendee(subgroupId, attendeeId);

            if (attendeeEntity == null)
            {
                return(NotFound());
            }

            var meritBadgeDtos = new List <MeritBadgeDto>();

            foreach (var attendeeMeritBadge in attendeeEntity.AttendeeMeritBadges)
            {
                var meritBadge    = _registrationRepository.GetMeritBadges().FirstOrDefault(mb => mb.Id == attendeeMeritBadge.MeritBadgeId);
                var meritBadgeDto = Mapper.Map <MeritBadgeDto>(meritBadge);
                meritBadgeDto.SortOrder = attendeeMeritBadge.SortOrder;
                meritBadgeDtos.Add(meritBadgeDto);
            }

            return(Ok(meritBadgeDtos));
        }
Esempio n. 3
0
        public IActionResult GetAssignment()
        {
            try
            {
                var userIdentifier = _registrationAuthorizationService.GetCurrentUserIdentifier(User);
                if (userIdentifier == null)
                {
                    return(BadRequest());
                }

                var user = _registrationRepository.GetUser(userIdentifier, includeRoles: false, includeSubgroups: true);

                if (user == null)
                {
                    return(NotFound());
                }

                var userWithSubgroupsResult = Mapper.Map <UserWithSubgroupsDto>(user);
                return(Ok(userWithSubgroupsResult));
            }
            catch (Exception)
            {
                return(StatusCode(500, "A problem happened while handling your request."));
            }
        }
        public IActionResult GetAttendeeStubs(int groupId, int subgroupId)
        {
            var userIdentifier = _registrationAuthorizationService.GetCurrentUserIdentifier(User);

            if (userIdentifier == null)
            {
                return(BadRequest());
            }

            if (!_registrationAuthorizationService.IsAuthorized(userIdentifier, subgroupId))
            {
                return(Unauthorized());
            }

            var attendeeEntities = _registrationRepository.GetAttendees(subgroupId);
            var attendeeStubDtos = Mapper.Map <IEnumerable <AttendeeStubDto> >(attendeeEntities);

            return(Ok(attendeeStubDtos));
        }