public List <Finition> getByModeleDeGamme(ModeleDeGamme modele) { List <Finition> dtos = new List <Finition>(); using (var db = new maderaEntities()) { var lierFinition = from a in db.LIER_FINITION where a.MODELE_GAMME_ID.Equals(modele.Id) select a; foreach (var item in lierFinition) { var query = from a in db.FINITION where a.FINITION_ID.Equals(item.FINITION_ID) select a; Finition finition = new Finition(); finition.Id = query.First().FINITION_ID; finition.Nom = query.First().FINITION_NOM; finition.Description = query.First().FINITION_DESCRIPTION; finition.TypeFinition = typeFinitionRepository.GetOne(query.First().TYPE_FINITION_ID); var fichier = from a in db.FINITION_IMAGE where a.FINITION_ID.Equals(finition.Id) select a; if (fichier.Count() > 0) { finition.Image = fichierRepository.GetOne(fichier.First().FICHIER_ID); } dtos.Add(finition); } } return(dtos); }
public List <ModeleDeGamme> GetByGamme(Gamme gamme) { List <ModeleDeGamme> dtos = new List <ModeleDeGamme>(); using (var db = new maderaEntities()) { var query = from a in db.MODELE_DE_GAMME where a.GAMME_ID.Equals(gamme.Id) select a; foreach (var item in query) { ModeleDeGamme dto = new ModeleDeGamme(); dto.Id = (int)item.MODELE_GAMME_ID; dto.Nom = item.MODELE_GAMME_NOM; dto.Description = item.MODELE_GAMME_DESCRIPTION; dto.EstParDefaut = item.EST_PAR_DEFAUT; dto.NbPieces = item.MODELE_GAMME_NB_PIECES; dto.Surface = item.MODELE_GAMME_SURFACE; dto.TypeModeleGamme = typeModeleGammeRepository.GetOne(item.TYPE_MODELE_GAMME_ID); dto.Gamme = gammeRepository.GetOne(item.GAMME_ID); var image = from a in db.MODELE_GAMME_IMAGE where a.MODELE_GAMME_ID.Equals(dto.Id) select a; if (image.Count() != 0) { //TODO : Plante quand il n'y a pas d'image dto.Image = fichierRepository.GetOne(image.First().FICHIER_ID); } var queryFinitions = from a in db.LIER_FINITION where a.MODELE_GAMME_ID.Equals(dto.Id) select a; List <Finition> finitions = new List <Finition>(); foreach (var itemFin in queryFinitions) { finitions.Add(finitionRepository.getOne(itemFin.FINITION_ID)); } dto.Finitions = finitions; dtos.Add(dto); } } return(dtos); }