Exemplo n.º 1
0
        public Response DeleteCoach(DeleteCoachRequest request)
        {
            var coach = memberQuery.GetCoach(request.CoachId);

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

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

            try {
                coachRepository.DeleteCoach(coach);
                var members = memberQuery.GetMembersByEmail(request.ClubId, coach.Email);
                if (members.Count() == 0)
                {
                    var result = identityManager.RemoveUser(coach.Email).Result;
                }
                else if (!members.Any(m => m.Membership == Membership.Coach))
                {
                    var result = identityManager.RemoveUserRole(coach.Email, Membership.Coach).Result;
                }

                return(Response.CreateSuccessResponse());
            } catch (Exception ex) {
                return(Response.CreateResponse(ex));
            }
        }
Exemplo 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));
            }
        }
Exemplo n.º 3
0
        public Response AssignCoach(Guid squadId, Guid coachId)
        {
            var squad = squadQuery.GetSquad(squadId);

            if (squad == null)
            {
                return(Response.CreateResponse(new List <string> {
                    "The specified squad does not exist"
                }));
            }

            var coach = memberQuery.GetCoach(coachId);

            if (coach == null)
            {
                return(Response.CreateResponse(new List <string> {
                    "The specified coach does not exist"
                }));
            }
            else if (squad.ClubId != coach.ClubId)
            {
                return(Response.CreateResponse(new IllegalOperationException("The squad and coach belong to different clubs")));
            }

            squadRepository.AssignCoach(squadId, coachId);
            return(Response.CreateSuccessResponse());
        }
Exemplo n.º 4
0
        protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, MembershipRequirement requirement)
        {
            if (context.Resource is AuthorizationFilterContext mvcContext)
            {
                // Examine MVC-specific things like routing data.
                if (mvcContext.RouteData.Values.ContainsKey("memberid"))
                {
                    string memberid = mvcContext.RouteData.Values["memberid"] as string;

                    if (!requirement.Membership.IsEmpty())
                    {
                        if (requirement.Membership.Equals("Player"))
                        {
                            var member = memberQuery.GetPlayer(Guid.Parse(memberid));
                            if (member != null)
                            {
                                context.Succeed(requirement);
                            }
                        }
                        else if (requirement.Membership.Equals("Coach"))
                        {
                            var member = memberQuery.GetCoach(Guid.Parse(memberid));
                            if (member != null)
                            {
                                context.Succeed(requirement);
                            }
                        }
                    }
                }
            }
            return(Task.CompletedTask);
        }
Exemplo n.º 5
0
        private Member GetCoach(Guid memberId)
        {
            //var email = User.Identity.Name;
            //var members = memberQuery.GetMembersByEmail(club.Guid, email);
            //return members?.FirstOrDefault(m => m.Membership == Membership.Coach);
            var member = memberQuery.GetCoach(memberId);

            return(member);
        }
Exemplo n.º 6
0
        public Response AddEventReview(NewEventReviewRequest request)
        {
            var validationResult = newEventReviewValidator.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 @event = eventQuery.GetEvent(request.EventId);

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

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

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

            var unreviewedSquads = eventQuery.GetUnReviewedSquads(request.EventId);

            if (request.Squads.Except(unreviewedSquads.Select(s => s.Guid)).Any())
            {
                return(Response.CreateResponse(new IllegalOperationException("The specified squads are not associated with this event")));
            }

            try {
                eventRepository.AddEventReview(request);
                return(Response.CreateSuccessResponse());
            } catch (Exception ex) {
                return(Response.CreateResponse(ex));
            }
        }
Exemplo n.º 7
0
        public IEnumerable <EventReview> GetEventReviews(Guid eventId)
        {
            string sql = @" SELECT E.Guid AS EventGuid, ER.Guid AS EventReviewGuid, CO.Guid AS CoachGuid,
								ER.LastReviewedDate, ER.Successes, ER.Opportunities, ER.DifferentNextTime
							FROM EventReviews ER
							INNER JOIN Events E ON E.EventId = ER.EventId
							INNER JOIN Coaches CO ON ER.CoachId = CO.CoachId							
							WHERE E.Guid = @EventGuid AND (E.Deleted IS NULL OR E.Deleted = 0)

							SELECT ER.Guid AS EventReviewGuid, S.Guid AS SquadGuid
							FROM EventReviews ER
							INNER JOIN Events E ON E.EventId = ER.EventId
							INNER JOIN EventReviewSquads ERS ON ER.EventReviewId = ERS.EventReviewId
							INNER JOIN Squads S ON ERS.SquadId = S.SquadId
							WHERE E.Guid = @EventGuid AND (E.Deleted IS NULL OR E.Deleted = 0)"                            ;

            DynamicParameters p = new DynamicParameters();

            p.Add("@EventGuid", eventId.ToString());
            using (var connection = connectionFactory.Connect()) {
                connection.Open();
                var reader       = connection.QueryMultiple(sql, p);
                var eventReviews = reader.Read().Cast <IDictionary <string, object> >().Select <dynamic, EventReview>(
                    row => new EventReview(Guid.Parse(row.EventGuid.ToString()), Guid.Parse(row.EventReviewGuid.ToString()))
                {
                    Coach             = memberQuery.GetCoach(Guid.Parse(row.CoachGuid.ToString())),
                    DifferentNextTime = row.DifferentNextTime,
                    LastReviewedOn    = row.LastReviewedDate, Opportunities = row.Opportunities, Successes = row.Successes
                }).ToList();

                var squads = reader.Read().Cast <dynamic>().ToList();

                foreach (var review in eventReviews)
                {
                    var squadGuids = squads.Where(r => r.EventReviewGuid == review.EventReviewId)
                                     .Select <dynamic, Guid>(row => Guid.Parse(row.SquadGuid.ToString())).ToList();

                    foreach (var guid in squadGuids)
                    {
                        review.Squads.Add(squadQuery.GetSquad(guid));
                    }
                }

                return(eventReviews);
            }
        }
Exemplo 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));
            }
        }