コード例 #1
0
        public Task <IActionResult> GetGroup(GroupRequest request)
        {
            var entity = BasicLayer.GetGroup(request.GroupId);

            //verifico validità dell'entità
            if (entity == null)
            {
                return(Task.FromResult <IActionResult>(NotFound()));
            }

            //var shooters = BasicLayer.FetchShootersByGroupId(entity.Id);
            var shooterGroup = BasicLayer.FetchGroupShootersByGroupId(entity.Id);

            var shooterIds = shooterGroup.Select(x => x.ShooterId).ToList();
            var shooters   = BasicLayer.FetchShootersByIds(shooterIds);

            var match       = BasicLayer.GetMatch(entity.MatchId);
            var association = BasicLayer.GetAssociation(match.AssociationId);

            var shooterAssociation = BasicLayer.FetchShooterAssociationByShooterIds(shooterIds, entity.MatchId);
            var shooterTeams       = BasicLayer.FetchTeamsFromShooterIds(shooterIds);

            var teamsIds = shooterTeams.Select(x => x.TeamId).ToList();
            var teams    = BasicLayer.FetchTeamsByIds(teamsIds);

            var result = ContractUtils.GenerateContract(entity, match, association, null, shooterGroup, shooters,
                                                        shooterAssociation, shooterTeams, teams);

            //Serializzazione e conferma
            return(Reply(result));
        }
コード例 #2
0
        public Task <IActionResult> FetchAvailableGroupShooter(GroupRequest request)
        {
            //Recupero l'elemento dal business layer
            var entity = BasicLayer.GetGroup(request.GroupId);

            //modifica solo se admin o se utente richiedente è lo stesso che ha creato
            if (entity == null)
            {
                return(Task.FromResult <IActionResult>(NotFound()));
            }

            //Invocazione del service layer
            var shooters = BasicLayer.FetchAvailableShooters(entity);

            var shooterIds = shooters.Select(s => s.Id).ToList();

            var shooterAssociation = BasicLayer.FetchShooterAssociationByShooterIds(shooterIds, entity.MatchId);
            var shooterTeams       = BasicLayer.FetchTeamsFromShooterIds(shooterIds);

            var teamsIds = shooterTeams.Select(x => x.TeamId).ToList();
            var teams    = BasicLayer.FetchTeamsByIds(teamsIds);

            var result = shooters.As(x => ContractUtils.GenerateContract(x,
                                                                         shooterAssociation.Where(s => s.ShooterId == x.Id).ToList(),
                                                                         teams.Where(s => shooterTeams.Where(st => st.ShooterId == x.Id).Select(st => st.TeamId).Contains(s.Id))
                                                                         .ToList()));

            //Return contract
            return(Reply(result));
        }