コード例 #1
0
        public async Task <IActionResult> GetTours()
        {
            IEnumerable <Entities.Tour> toursFromRepo = new List <Entities.Tour>();

            if (_userInfoService.Role == "Administrator")
            {
                toursFromRepo = await _tourManagementRepository.GetTours();
            }
            else
            {
                var userId = Int32.Parse(_userInfoService.UserId);

                // work around for int
                if (!(userId > 0))
                {
                    return(Forbid());
                }

                toursFromRepo = await _tourManagementRepository.GetToursForManager(userId);
            }

            var tours = Mapper.Map <IEnumerable <Tour> >(toursFromRepo);

            return(Ok(tours));
        }
コード例 #2
0
        public async Task <IActionResult> GetTours()
        {
            IEnumerable <Entities.Tour> toursFromRepo = new List <Entities.Tour>();

            if (_userInfoService.Role == "Administrator")
            {
                toursFromRepo = await _tourManagementRepository.GetTours();
            }
            else
            {
                if (!Guid.TryParse(_userInfoService.UserId, out Guid userIdAsGuid))
                {
                    return(Forbid());
                }

                toursFromRepo = await _tourManagementRepository.GetToursForManager(userIdAsGuid);
            }

            var tours = Mapper.Map <IEnumerable <Tour> >(toursFromRepo);

            return(Ok(tours));
        }