Пример #1
0
        public void Track(EventTrainingMaterialViewRequest request)
        {
            string sql = @" INSERT INTO EventTrainingMaterialViews (EventId, TrainingMaterialId, PlayerId, CoachId, ViewedOn)
                            VALUES(
                                (SELECT EventId FROM Events WHERE Guid = @EventGuid),
                                (SELECT TrainingMaterialId FROM TrainingMaterials WHERE Guid = @TrainingMaterialGuid),
                                (SELECT PlayerId FROM Players WHERE Guid = @PlayerGuid AND (Deleted IS NULL OR Deleted = 0)),
                                (SELECT CoachId FROM Coaches WHERE Guid = @CoachGuid),
                                GetDate()
                        )";

            var parameters = new DynamicParameters();

            parameters.Add("@EventGuid", request.EventId.ToString());
            parameters.Add("@TrainingMaterialGuid", request.TrainingMaterialId.ToString());
            parameters.Add("@PlayerGuid", request.Membership == Core.Membership.Player ? request.MemberId.ToString() : null);
            parameters.Add("@CoachGuid", request.Membership == Core.Membership.Coach ? request.MemberId.ToString() : null);

            using (var connection = connectionFactory.Connect())
            {
                connection.Open();
                connection.Execute(sql, parameters);
            }
        }
Пример #2
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));
            }
        }