public Task <IActionResult> FetchAvailableAssociationsForShooter(ShooterRequest request)
        {
            var associationIds = BasicLayer.FetchAllShooterAssociationInfos(request.ShooterId)
                                 .Select(x => x.AssociationId)
                                 .ToList();
            //Recupero la lista dal layer
            var entities = BasicLayer.FetchAssociationsByIds(associationIds);

            //Ritorno i contratti
            return(Reply(entities.As(x => ContractUtils.GenerateContract(x))));
        }
        public Task <IActionResult> FetchAssociationsNotAssignedForShooter(ShooterRequest request)
        {
            var associationIds = BasicLayer.FetchAllShooterAssociationInfos(request.ShooterId)
                                 .Select(x => x.AssociationId)
                                 .ToList();
            //Recupero la lista dal layer
            var entities = BasicLayer.FetchAllAssociations();

            //Ritorno i contratti
            return(Reply(entities.Where(x => !associationIds.Contains(x.Id)).As(ContractUtils.GenerateContract)));
        }
        public Task <IActionResult> UpsertShooterAssociation(ShooterAssociationCreateRequest request)
        {
            var availableAssociationIds = BasicLayer.FetchAllShooterAssociationInfos(request.ShooterId).Select(x => x.AssociationId);

            IList <ValidationResult> validations = new List <ValidationResult>();

            if (!availableAssociationIds.Contains(request.AssociationId))
            {
                validations.Add(new ValidationResult("User is not registered for the selected association"));
                return(BadRequestTask(validations));
            }

            var entity = this.BasicLayer.GetActiveShooterAssociationByShooterAndAssociationAndDivision(request.ShooterId, request.AssociationId, request.Division);


            if (entity != null)
            {
                entity.ExpireDate = entity.RegistrationDate.AddDays(-1);
                validations       = BasicLayer.UpsertShooterAssociation(entity);

                if (validations.Count > 0)
                {
                    return(BadRequestTask(validations));
                }
            }

            entity                  = new ShooterAssociation();
            entity.ShooterId        = request.ShooterId;
            entity.AssociationId    = request.AssociationId;
            entity.Classification   = request.Classification;
            entity.Division         = request.Division;
            entity.RegistrationDate = request.RegistrationDate;

            //Invocazione del service layer
            validations = BasicLayer.UpsertShooterAssociation(entity);

            if (validations.Count > 0)
            {
                return(BadRequestTask(validations));
            }

            //Return contract
            return(Reply(new OkResponse {
                Status = true
            }));
        }