/// <summary> /// Retrieves the CommercialCatalogue's CatalogueCollections. /// </summary> /// <param name="findCommercialCatalogueModelView">FindCommercialCatalogueModelView with the identifier.</param> /// <returns>Instance of GetAllCatalogueCollectionsModelView representing the IEnumerable of CatalogueCollection.</returns> /// <exception cref="ResourceNotFoundException"> /// Thrown when no instance of CommercialCatalogue is found with a matching identifier of when the CommercialCatalogue has no CatalogueCollections. /// </exception> public GetAllCatalogueCollectionsModelView findCatalogueCollections(FindCommercialCatalogueModelView findCommercialCatalogueModelView) { CommercialCatalogueRepository catalogueRepository = PersistenceContext.repositories().createCommercialCatalogueRepository(); CommercialCatalogue commercialCatalogue = catalogueRepository.find(findCommercialCatalogueModelView.commercialCatalogueId); if (commercialCatalogue == null) { throw new ResourceNotFoundException(string.Format(CATALOGUE_NOT_FOUND_BY_ID, findCommercialCatalogueModelView.commercialCatalogueId)); } if (!commercialCatalogue.catalogueCollectionList.Any()) { throw new ResourceNotFoundException(CATALOGUE_COLLECTIONS_NOT_FOUND); } return(CatalogueCollectionModelViewService.fromCollection(commercialCatalogue.catalogueCollectionList)); }
/// <summary> /// Builds an instance of GetCommercialCatalogueModelView from an instance of CommercialCatalogue. /// </summary> /// <param name="commercialCatalogue">Instance of CommercialCatalogue from which the ModelView will be built.</param> /// <returns>An instance of GetCommercialCatalogueModelView.</returns> /// <exception cref="System.ArgumentNullException">Thrown when the provided instance of CommercialCatalogue is null.</exception> public static GetCommercialCatalogueModelView fromEntity(CommercialCatalogue commercialCatalogue) { if (commercialCatalogue == null) { throw new ArgumentNullException(ERROR_NULL_CATALOGUE); } GetCommercialCatalogueModelView commercialCatalogueView = new GetCommercialCatalogueModelView(); commercialCatalogueView.commercialCatalogueId = commercialCatalogue.Id; commercialCatalogueView.reference = commercialCatalogue.reference; commercialCatalogueView.designation = commercialCatalogue.designation; if (commercialCatalogue.catalogueCollectionList.Any()) { commercialCatalogueView.commercialCatalogueCollections = CatalogueCollectionModelViewService.fromCollection(commercialCatalogue.catalogueCollectionList); } return(commercialCatalogueView); }