예제 #1
0
        public IActionResult GetTrainingMaterialViews(Guid eventId)
        {
            var evnt   = eventsQuery.GetEvent(eventId);
            var views  = eventsQuery.GetTrainingMaterialViews(eventId);
            var squads = memberQuery.GetMembers(evnt.Squads.Select(s => s.Guid));

            return(new JsonResult(new { results = new { squads, trainingMaterialViews = views } }));
        }
예제 #2
0
        private string GetSelectedPlayerList(IEnumerable <Guid> selectedPlayers)
        {
            if (selectedPlayers == null || !selectedPlayers.Any())
            {
                return(null);
            }

            var clubSquads = squadQuery.GetSquads(club.Guid);
            var members    = memberQuery.GetMembers(clubSquads.Select(s => s.Guid));
            var players    = members.SelectMany(m => m.Members)
                             .Where(m => m.Membership.Equals("Player") && selectedPlayers.Contains(m.Guid))
                             .Select(m => new { Text = $"{m.Name}", id = m.Guid.ToString() })
                             .OrderBy(s => s.Text)
                             .ToList();

            return(JsonConvert.SerializeObject(players,
                                               new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            }
                                               ));
        }
예제 #3
0
        public Response CreateAssignment(AssignmentRequest request)
        {
            var result = assignementRequestValidator.Validate(request);

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

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

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

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

            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")));
            }

            var clubSquads = squadQuery.GetSquads(club.Guid);

            if (request.Squads?.Count() > 0)
            {
                var allOfRequestedSquadsBelongToClub = !request.Squads.Except(clubSquads.Select(s => s.Guid)).Any();
                if (!allOfRequestedSquadsBelongToClub)
                {
                    return(Response.CreateResponse(new IllegalOperationException("Not all of specified squads belong to this club")));
                }
            }

            if (request.Players?.Count() > 0)
            {
                var members = memberQuery.GetMembers(clubSquads.Select(s => s.Guid));
                var players = members.SelectMany(s => s.Members)?.Where(m => m.Membership.Equals("Player"));

                var allOfRequestedPlayersBelongToClub = !request.Players.Except(players.Select(p => p.Guid)).Any();
                if (!allOfRequestedPlayersBelongToClub)
                {
                    return(Response.CreateResponse(new IllegalOperationException("Not all of specified players belong to this club")));
                }
            }

            if (request.TrainingMaterials?.Count() > 0)
            {
                var clubLibrary = libraryQuery.GetTrainingMaterials(request.ClubId);
                var allOfRequestedMaterialsBelongToClub = !request.TrainingMaterials.Except(request.TrainingMaterials).Any();
                if (!allOfRequestedMaterialsBelongToClub)
                {
                    return(Response.CreateResponse(new IllegalOperationException("Not all of specified training materials belong to this club")));
                }
            }

            try
            {
                assignmentRepository.CreateAssignment(request);
                return(Response.CreateSuccessResponse());
            }catch (Exception ex)
            {
                return(Response.CreateResponse(ex));
            }
        }