Ejemplo n.º 1
0
        public RetrieveOutput <TeamRequestDto, long> Retrieve(RetrieveTeamRequestInput input)
        {
            TeamRequestRepository.Includes.Add(r => r.LastModifierUser);
            TeamRequestRepository.Includes.Add(r => r.CreatorUser);
            TeamRequestRepository.Includes.Add(r => r.InvitedUser);
            TeamRequestRepository.Includes.Add(r => r.Team);

            IList <TeamRequest> teamRequestEntities = TeamRequestRepository.GetAll()
                                                      .WhereIf(input.Id != null, r => r.Id == input.Id)
                                                      .WhereIf(input.TeamId != null, r => r.TeamId == input.TeamId)
                                                      .WhereIf(input.UserId != null, r => r.InvitedUserId == input.UserId)
                                                      .ToList();

            if (teamRequestEntities.Count != 1)
            {
                throw new CityQuestItemNotFoundException(CityQuestConsts.CityQuestItemNotFoundExceptionMessageBody, "\"TeamRequest\"");
            }

            if (!TeamRequestPolicy.CanRetrieveEntity(teamRequestEntities.Single()))
            {
                throw new CityQuestPolicyException(CityQuestConsts.CQPolicyExceptionRetrieveDenied, "\"TeamRequest\"");
            }

            TeamRequestDto teamRequestEntity = teamRequestEntities.Single().MapTo <TeamRequestDto>();

            TeamRequestRepository.Includes.Clear();

            return(new RetrieveOutput <TeamRequestDto, long>()
            {
                RetrievedEntity = teamRequestEntity
            });
        }
Ejemplo n.º 2
0
        public RetrieveAllOutput <TeamRequestDto, long> RetrieveAll(RetrieveAllTeamRequestsInput input)
        {
            TeamRequestRepository.Includes.Add(r => r.LastModifierUser);
            TeamRequestRepository.Includes.Add(r => r.CreatorUser);
            TeamRequestRepository.Includes.Add(r => r.InvitedUser);
            TeamRequestRepository.Includes.Add(r => r.Team);
            TeamRequestRepository.Includes.Add(r => r.Team.PlayerCareers);

            IQueryable <TeamRequest> teamRequestsQuery = TeamRequestPolicy.CanRetrieveManyEntities(
                TeamRequestRepository.GetAll()
                .Where(r => r.DeclinedByInviter != true)
                .Where(r => r.InvitedUserResponse == null)
                .WhereIf(input.TeamId != null, r => r.TeamId == input.TeamId)
                .WhereIf(input.CaptainId != null, r => r.Team.PlayerCareers.Any(e =>
                                                                                e.CareerDateEnd == null && e.UserId == input.CaptainId && e.IsCaptain && e.IsActive))
                .WhereIf(input.UserId != null, r => r.InvitedUserId == input.UserId))
                                                         .OrderBy(r => r.CreationTime);

            IList <TeamRequestDto> result = teamRequestsQuery.ToList().MapIList <TeamRequest, TeamRequestDto>();

            TeamRequestRepository.Includes.Clear();

            return(new RetrieveAllOutput <TeamRequestDto, long>()
            {
                RetrievedEntities = result
            });
        }