Beispiel #1
0
        public Response DeleteReportCard(DeleteReportCardRequest request)
        {
            var response = CheckReportCardRequestIntegrity(request.ClubId, request.SquadId, request.TermId, request.PlayerId);

            if (response.Errors.Any())
            {
                return(response);
            }

            var reportCard = evaluationQuery.GetPlayerReportCard(request.ClubId, request.ReportCardId);

            if (reportCard == null || !reportCard.ReportCardExists)
            {
                return(Response.CreateResponse(new EntityNotFoundException("The specified report card does not exist")));
            }
            else if (reportCard.PlayerId != request.PlayerId)
            {
                return(Response.CreateResponse(new IllegalOperationException("The specified report card does not belong to this player")));
            }

            try
            {
                evaluationRepository.DeletePlayerReportCard(request);
                return(Response.CreateSuccessResponse());
            }
            catch (Exception ex)
            {
                return(Response.CreateResponse(ex));
            }
        }
Beispiel #2
0
        public void DeletePlayerReportCard(DeleteReportCardRequest request)
        {
            var sql = @"DECLARE @PlayerReportCardId BIGINT, @PlayerId BIGINT;
                        
                        SELECT @PlayerId = PlayerId 
                        FROM Players P
                        INNER JOIN Squads S ON S.SquadId = P.SquadId
                        INNER JOIN Clubs C ON S.ClubId = C.ClubId
                        WHERE P.Guid = @PlayerGuid AND C.Guid = @ClubGuid AND S.Guid = @SquadGuid;
                        
                        SELECT @PlayerReportCardId = PlayerReportCardId FROM PlayerReportCards WHERE Guid = @PlayerReportCardGuid AND PlayerId = @PlayerId;

                        DELETE PlayerReportCardFacets WHERE PlayerReportCardId = @PlayerReportCardId;
                        DELETE PlayerReportCardGrades WHERE PlayerReportCardId = @PlayerReportCardId;
                        DELETE PlayerReportCards WHERE PlayerReportCardId = @PlayerReportCardId;";

            DynamicParameters parameters = new DynamicParameters();

            parameters.Add("@ClubGuid", request.ClubId.ToString());
            parameters.Add("@SquadGuid", request.SquadId.ToString());
            parameters.Add("@PlayerGuid", request.PlayerId.ToString());
            parameters.Add("@PlayerReportCardGuid", request.ReportCardId.ToString());

            using (var connection = connectionFactory.Connect())
            {
                connection.Open();
                using (var transaction = connection.BeginTransaction())
                {
                    try
                    {
                        connection.Execute(sql, parameters, transaction);
                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }
                }
            }
        }