Пример #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
            });
        }
Пример #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
            });
        }
Пример #3
0
        public AnswerOnRequestOutput AnswerOnRequest(AnswerOnRequestInput input)
        {
            TeamRequest teamRequestEntity = TeamRequestRepository.Get(input.TeamRequestId);

            if (teamRequestEntity == null)
            {
                throw new CityQuestItemNotFoundException(CityQuestConsts.CityQuestItemNotFoundExceptionMessageBody, "\"TeamRequest\"");
            }

            if (!TeamRequestPolicy.CanAnswerOnRequestFromTeam(teamRequestEntity))
            {
                throw new CityQuestPolicyException(CityQuestConsts.CQPolicyExceptionUpdateDenied, "\"TeamRequest\"");
            }

            DateTime currentDT = DateTime.Now;

            teamRequestEntity.InvitedUserResponse         = input.Answer;
            teamRequestEntity.InvitedUserResponseDateTime = currentDT;
            TeamRequestRepository.Update(teamRequestEntity);

            #region Creating new career if joined new team

            if (teamRequestEntity.InvitedUserResponse == true)
            {
                CreateNewPlayerCareer(teamRequestEntity.InvitedUserId, teamRequestEntity.TeamId, currentDT);
            }

            #endregion

            return(new AnswerOnRequestOutput()
            {
                TeamRequest = teamRequestEntity.MapTo <TeamRequestDto>(),
            });
        }
Пример #4
0
        public DeleteOutput <long> Delete(DeleteInput <long> input)
        {
            TeamRequest teamRequestEntityForDelete = TeamRequestRepository.Get(input.EntityId);

            if (teamRequestEntityForDelete == null)
            {
                throw new CityQuestItemNotFoundException(CityQuestConsts.CityQuestItemNotFoundExceptionMessageBody, "\"TeamRequest\"");
            }

            if (!TeamRequestPolicy.CanDeleteEntity(teamRequestEntityForDelete))
            {
                throw new CityQuestPolicyException(CityQuestConsts.CQPolicyExceptionDeleteDenied, "\"TeamRequest\"");
            }

            TeamRequestRepository.Delete(teamRequestEntityForDelete);

            return(new DeleteOutput <long>()
            {
                DeletedEntityId = input.EntityId
            });
        }
Пример #5
0
        public CreateOutput <TeamRequestDto, long> Create(CreateTeamRequestInput input)
        {
            TeamRequest newTeamRequestEntity;

            try
            {
                long teamId = PlayerCareerRepository
                              .Single(r => r.UserId == (Session.UserId ?? 0) && r.CareerDateEnd == null).TeamId;

                newTeamRequestEntity = new TeamRequest()
                {
                    InvitedUserId = input.InvitedUserId,
                    TeamId        = teamId
                };

                if (!TeamRequestPolicy.CanCreateEntity(newTeamRequestEntity))
                {
                    throw new Exception();
                }
            }
            catch
            {
                throw new CityQuestPolicyException(CityQuestConsts.CQPolicyExceptionCreateDenied, "\"TeamRequest\"");
            }

            TeamRequestRepository.Includes.Add(r => r.LastModifierUser);
            TeamRequestRepository.Includes.Add(r => r.CreatorUser);
            TeamRequestRepository.Includes.Add(r => r.InvitedUser);
            TeamRequestRepository.Includes.Add(r => r.Team);

            TeamRequestDto newTeamRequestDto = (TeamRequestRepository.Insert(newTeamRequestEntity)).MapTo <TeamRequestDto>();

            TeamRequestRepository.Includes.Clear();

            return(new CreateOutput <TeamRequestDto, long>()
            {
                CreatedEntity = newTeamRequestDto
            });
        }
Пример #6
0
        public DenyRequestOutput DenyRequest(DenyRequestInput input)
        {
            TeamRequest teamRequestEntity = TeamRequestRepository.Get(input.TeamRequestId);

            if (teamRequestEntity == null)
            {
                throw new CityQuestItemNotFoundException(CityQuestConsts.CityQuestItemNotFoundExceptionMessageBody, "\"TeamRequest\"");
            }

            if (!TeamRequestPolicy.CanDenyRequestToPlayer(teamRequestEntity))
            {
                throw new CityQuestPolicyException(CityQuestConsts.CQPolicyExceptionUpdateDenied, "\"TeamRequest\"");
            }

            DateTime currentDT = DateTime.Now;

            teamRequestEntity.DeclinedByInviter         = true;
            teamRequestEntity.DeclinedByInviterDateTime = currentDT;
            TeamRequestRepository.Update(teamRequestEntity);

            return(new DenyRequestOutput()
            {
            });
        }