Beispiel #1
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());
        }
Beispiel #2
0
        public Response RegisterPlayer(PlayerRequest request)
        {
            var validationResult = validator.Validate(request);

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

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

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

            Player player = MapPlayer(request);

            try {
                playerRepository.AddPlayer(player);
                return(Response.CreateSuccessResponse());
            } catch (Exception ex) {
                return(Response.CreateResponse(ex));
            }
        }
Beispiel #3
0
        private void SetupTitle(string squadId, string title)
        {
            var squad = squadQuery.GetSquad(System.Guid.Parse(squadId));

            ViewData["SquadId"]  = squad.Guid;
            ViewData["Title"]    = title;
            ViewData["SubTitle"] = squad.Name;
        }
Beispiel #4
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);
            }
        }
Beispiel #5
0
        public Response UpdateEventAttendance(EventAttendanceRequest request)
        {
            var validationResult = eventAttendanceRequestValidator.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 squad = squadQuery.GetSquad(request.SquadId);

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

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

            if (@event == null || [email protected](s => s.Guid == squad.Guid))
            {
                return(Response.CreateResponse(new IllegalOperationException("The specified squad is not bound to this event")));
            }

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

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

            try {
                eventRepository.UpdateAttendance(request.SquadId, request.EventId, request.PlayerId, request.Attendance);
            } catch (Exception ex) {
                return(Response.CreateResponse(ex));
            }
            return(Response.CreateSuccessResponse());
        }
Beispiel #6
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));
            }
        }
Beispiel #7
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());
        }