예제 #1
0
        public (Guid?Guid, Response Response) GeneratePlayerReportCard(GenerateReportCardRequest request)
        {
            var evaluationResult = generateRequestValidator.Validate(request);

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

            var response = CheckReportCardRequestIntegrity(request.ClubId, request.SquadId, request.TermId, request.PlayerId);

            if (!response.RequestIsFulfilled)
            {
                return(null, response);
            }

            var reportDesign = reportDesignerQuery.GetReportCardDesign(request.ClubId, request.ReportDesignId);

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

            var reportCard = evaluationQuery.GetPlayerReportCard(request.ClubId, request.TermId, request.SquadId, request.PlayerId);

            if (reportCard != null && reportCard.ReportCardExists)
            {
                return(null, Response.CreateResponse(new IllegalOperationException("There is already a report card for this player for the specified term")));
            }

            try {
                Guid reportGuid = evaluationRepository.GeneratePlayerReportCard(request);
                return(reportGuid, Response.CreateSuccessResponse());
            }catch (Exception ex) {
                return(null, Response.CreateResponse(ex));
            }
        }