Esempio n. 1
0
        public Response RegisterSquad(SquadRequest request)
        {
            var errors = Validate(request);

            if (errors.Count() > 0)
            {
                return(Response.CreateResponse(errors));
            }

            var club = clubQuery.GetClub(request.ClubId);

            if (club == null)
            {
                return(Response.CreateResponse(new EntityNotFoundException("The specified club does not exist")));
            }

            try {
                squadRepository.AddSquad(new Squad(club.Guid)
                {
                    Name = request.SquadName, YearBorn = request.YearBorn
                });
            } catch (Exception ex) {
                return(Response.CreateResponse(ex));
            }

            return(Response.CreateSuccessResponse());
        }
Esempio n. 2
0
        public Response AddPlayerToAssignment(PlayerAssignmentRequest request)
        {
            var club = clubQuery.GetClub(request.ClubId);

            if (club == null)
            {
                return(Response.CreateResponse(new EntityNotFoundException("The specified club does not exist")));
            }
            else if (request.PlayerId.IsEmpty())
            {
                return(Response.CreateResponse(new IllegalOperationException("PlayerId is required")));
            }
            else if (request.CoachId.IsEmpty())
            {
                return(Response.CreateResponse(new IllegalOperationException("CoachId is required")));
            }

            var playerAssignment = assignmentQuery.GetPlayerAssignment(new Core.Queries.PlayerAssignmentQuery {
                ClubId = request.ClubId, AssignmentId = request.AssignmentId, PlayerId = request.PlayerId
            });

            if (playerAssignment != null)
            {
                return(Response.CreateResponse(new IllegalOperationException("This assignment has already been allocated to the specified player")));
            }

            var assignment = assignmentQuery.GetAssignment(request.ClubId, request.AssignmentId);

            if (assignment.ClubId != request.ClubId)
            {
                return(Response.CreateResponse(new IllegalOperationException("The specified assignment does not belong to this club")));
            }

            var coach = memberQuery.GetCoach(request.CoachId.Value);

            if (coach == null)
            {
                return(Response.CreateResponse(new EntityNotFoundException("The specified coach does not exist")));
            }
            else if (coach.ClubId != club.Guid)
            {
                return(Response.CreateResponse(new IllegalOperationException("The specified coach does not belong to this club")));
            }

            try {
                assignmentRepository.AddPlayerToAssignment(request);
                return(Response.CreateSuccessResponse());
            } catch (Exception ex) {
                return(Response.CreateResponse(ex));
            }
        }
Esempio n. 3
0
        public (Guid Guid, Response Response) CreateReportCardDesign(NewReportDesignRequest request)
        {
            var validationResult = newReportCardDesignValidator.Validate(request);

            if (!validationResult.IsValid)
            {
                return(Guid.Empty, Response.CreateResponse(validationResult.Messages));
            }

            var club = clubQuery.GetClub(request.ClubId);

            if (club == null)
            {
                return(Guid.Empty, Response.CreateResponse(new EntityNotFoundException("The specified club does not exist")));
            }

            var designs = reportDesignerQuery.GetReportCardDesigns(request.ClubId, request.Name);

            if (designs.Count() > 0)
            {
                return(Guid.Empty, Response.CreateResponse(new IllegalOperationException("There is already a report design with this name")));
            }

            try {
                var design = new ReportCardDesign(request.ClubId)
                {
                    DesignName = request.Name
                };
                reportDesignerRepository.AddReportDesign(design);
                return(design.Guid.Value, Response.CreateSuccessResponse());
            } catch (Exception ex) {
                return(Guid.Empty, Response.CreateResponse(ex));
            }
        }
Esempio n. 4
0
        public Response RegisterCoach(CoachRequest request)
        {
            var validationResult = validator.Validate(request);

            if (!validationResult.IsValid)
            {
                return(Response.CreateResponse(validationResult.Messages));
            }

            var club = clubQuery.GetClub(request.ClubId);

            if (club == null)
            {
                return(Response.CreateResponse(new EntityNotFoundException("The specified club does not exist")));
            }

            try {
                coachRepository.AddCoach(MapCoach(request, null));
            } catch (Exception ex) {
                return(Response.CreateResponse(ex));
            }
            return(Response.CreateSuccessResponse());
        }
Esempio n. 5
0
        public Response AddAvailability(NewAvailabilityRequest request)
        {
            var validationResult = newAvailabilityValidator.Validate(request);

            if (!validationResult.IsValid)
            {
                return(Response.CreateResponse(validationResult.Messages));
            }

            var club = clubQuery.GetClub(request.ClubId);

            if (club == null)
            {
                return(Response.CreateResponse(new EntityNotFoundException("The specified club does not exist")));
            }

            var player = memberQuery.GetPlayer(request.PlayerId);

            if (player == null)
            {
                return(Response.CreateResponse(new EntityNotFoundException("The specified player does not exist")));
            }

            var squad = squadQuery.GetSquad(player.SquadId);

            if (squad == null || squad.ClubId != club.Guid)
            {
                return(Response.CreateResponse(new IllegalOperationException("The specified player does not belong to this club")));
            }

            try {
                repository.AddAvailability(request);
                return(Response.CreateSuccessResponse());
            } catch (Exception ex) {
                return(Response.CreateResponse(ex));
            }
        }
Esempio n. 6
0
        private Response CheckReportCardRequestIntegrity(Guid clubId, Guid squadId, Guid termId, Guid playerId)
        {
            var club = clubQuery.GetClub(clubId);

            if (club == null)
            {
                return(Response.CreateResponse(new EntityNotFoundException("The specified club does not exist")));
            }

            var squad = squadQuery.GetSquad(squadId);

            if (squad == null)
            {
                return(Response.CreateResponse(new EntityNotFoundException("The specified squad does not exist")));
            }
            else if (club.Guid != squad.ClubId)
            {
                return(Response.CreateResponse(new IllegalOperationException("The specified squad does not belong to this club")));
            }

            var term = evaluationQuery.GetTerm(termId);

            if (term == null)
            {
                return(Response.CreateResponse(new EntityNotFoundException("The specified term does not exist")));
            }
            else if (term.ClubId != club.Guid)
            {
                return(Response.CreateResponse(new IllegalOperationException("The specified term does not belong to this club")));
            }
            else if (term.TermStatus == TermStatus.Closed)
            {
                return(Response.CreateResponse(new IllegalOperationException("Report cards cannot be generated for closed terms")));
            }

            var player = memberQuery.GetPlayer(playerId);

            if (player == null)
            {
                return(Response.CreateResponse(new EntityNotFoundException("The specified player does not exist")));
            }
            else if (player.SquadId != squad.Guid)
            {
                return(Response.CreateResponse(new IllegalOperationException("The specified player does not belong to this squad")));
            }

            return(Response.CreateSuccessResponse());
        }
Esempio n. 7
0
        private (bool isValid, IEnumerable <Squad> squads, IEnumerable <TrainingMaterial> trainingMaterials, Response response) Validate(EventSetupRequest request)
        {
            var validationResult = setUpRequestValidator.Validate(request);

            if (!validationResult.IsValid)
            {
                return(false, null, null, Response.CreateResponse(validationResult.Messages));
            }

            var club = clubQuery.GetClub(request.ClubId);

            if (club == null)
            {
                return(false, null, null, Response.CreateResponse(new EntityNotFoundException("The specified club doesn not exist")));
            }

            var clubSquads = squadQuery.GetSquads(club.Guid);
            var allOfRequestedSquadsBelongToClub = !request.Squads.Except(clubSquads.Select(s => s.Guid)).Any();

            if (!allOfRequestedSquadsBelongToClub)
            {
                return(false, null, null, Response.CreateResponse(new IllegalOperationException("Not all of specified squads belong to this club")));
            }

            List <TrainingMaterial> trainingMaterials = null;

            if (request.TrainingMaterials != null && request.TrainingMaterials.Any())
            {
                var clubTrainingMaterials = libraryQuery.GetTrainingMaterials(club.Guid);
                var allOfRequestedMaterialsBelongToClub = !request.TrainingMaterials.Except(clubTrainingMaterials.Select(t => t.Guid)).Any();
                if (!allOfRequestedMaterialsBelongToClub)
                {
                    return(false, null, null, Response.CreateResponse(new IllegalOperationException("Not all of specified materials belong to this club")));
                }

                trainingMaterials = request.TrainingMaterials.Join(clubTrainingMaterials, t1 => t1, t2 => t2.Guid, (guid, trainignMaterial) => trainignMaterial).ToList();
            }

            var squads = request.Squads.Join(clubSquads, s1 => s1, s2 => s2.Guid, (guid, squad) => squad).ToList();

            return(true, squads, trainingMaterials, Response.CreateSuccessResponse());
        }
Esempio n. 8
0
        public Response Track(EventTrainingMaterialViewRequest request)
        {
            var validationResult = eventTrainingMaterialViewValidator.Validate(request);

            if (!validationResult.IsValid)
            {
                return(Response.CreateResponse(validationResult.Messages));
            }

            var club = clubQuery.GetClub(request.ClubId);

            if (club == null)
            {
                return(Response.CreateResponse(new EntityNotFoundException("The specified club doesn not exist")));
            }

            var @event = eventQuery.GetEvent(request.EventId);

            if (@event == null)
            {
                return(Response.CreateResponse(new EntityNotFoundException("The specified event was not found")));
            }
            else if (@event.ClubId != request.ClubId)
            {
                return(Response.CreateResponse(new IllegalOperationException("The specified event does not belong to this club")));
            }
            else if ([email protected]())
            {
                return(Response.CreateResponse(new IllegalOperationException("The specified event is not attributed to any squad")));
            }

            var trainingMaterial = libraryQuery.GetTrainingMaterial(request.TrainingMaterialId);

            if (trainingMaterial == null)
            {
                return(Response.CreateResponse(new EntityNotFoundException("The specified training material does not exist")));
            }
            else if ([email protected](t => t.Guid == request.TrainingMaterialId))
            {
                return(Response.CreateResponse(new IllegalOperationException("The specified training material does not belong to this event")));
            }

            var    clubSquads = squadQuery.GetSquads(request.ClubId);
            Member member     = request.Membership == Core.Membership.Coach ? memberQuery.GetCoach(request.MemberId) as Member : memberQuery.GetPlayer(request.MemberId) as Member;
            var    l1         = member.Squads.Intersect(clubSquads.Select(s => s.Guid)).ToList();
            var    l2         = clubSquads.Select(s => s.Guid).Intersect(member.Squads).ToList();

            if (member == null)
            {
                return(Response.CreateResponse(new EntityNotFoundException("The specified member does not exist")));
            }
            else if (clubSquads == null || !member.Squads.Intersect(clubSquads.Select(s => s.Guid)).Any())
            {
                return(Response.CreateResponse(new IllegalOperationException("The specified member does not belong to any squad")));
            }
            else if ([email protected](s => s.Guid).Intersect(member.Squads).Any())
            {
                return(Response.CreateResponse(new IllegalOperationException("This member is not concerned by this event")));
            }

            try
            {
                trackerRepository.Track(request);
                return(Response.CreateSuccessResponse());
            }
            catch (Exception ex)
            {
                return(Response.CreateResponse(ex));
            }
        }