/// <summary> /// Retrieves all the CustomizedProducts added to the CatalogueCollection. /// </summary> /// <param name="findCatalogueCollectionModelView">FindCatalogueCollectionModelView with the CommercialCatalogue's and CatalogueCollection's identifiers.</param> /// <returns>Instance of GetAllCustomizedProductsModelView representing all of the CatalogueCollectionProduct's.</returns> /// <exception cref="ResourceNotFoundException"> /// Thrown when no CommercialCatalogue or CatalogueCollection could be found with the provided identifiers or when the IEnumerable of CatalogueCollectionProduct is empty. /// </exception> public GetAllCustomizedProductsModelView findCatalogueCollectionProducts(FindCatalogueCollectionModelView findCatalogueCollectionModelView) { CommercialCatalogueRepository catalogueRepository = PersistenceContext.repositories().createCommercialCatalogueRepository(); CommercialCatalogue commercialCatalogue = catalogueRepository.find(findCatalogueCollectionModelView.commercialCatalogueId); if (commercialCatalogue == null) { throw new ResourceNotFoundException(string.Format(CATALOGUE_NOT_FOUND_BY_ID, findCatalogueCollectionModelView.commercialCatalogueId)); } CatalogueCollection catalogueCollection = commercialCatalogue.catalogueCollectionList .Where(cc => cc.customizedProductCollectionId == findCatalogueCollectionModelView.customizedProductCollectionId).SingleOrDefault(); if (catalogueCollection == null) { throw new ResourceNotFoundException(string.Format( CATALOGUE_COLLECTION_NOT_FOUND_BY_ID, findCatalogueCollectionModelView.customizedProductCollectionId, findCatalogueCollectionModelView.commercialCatalogueId) ); } IEnumerable <CustomizedProduct> customizedProducts = catalogueCollection.catalogueCollectionProducts.Select(ccp => ccp.customizedProduct).ToList(); if (!customizedProducts.Any()) { throw new ResourceNotFoundException(CATALOGUE_COLLECTION_PRODUCTS_NOT_FOUND); } return(CustomizedProductModelViewService.fromCollection(customizedProducts)); }
public ActionResult findCatalogueCollectionProducts(long commercialCatalogueId, long customizedProductCollectionId) { try { FindCatalogueCollectionModelView findCatalogueCollectionModelView = new FindCatalogueCollectionModelView(); findCatalogueCollectionModelView.commercialCatalogueId = commercialCatalogueId; findCatalogueCollectionModelView.customizedProductCollectionId = customizedProductCollectionId; GetAllCustomizedProductsModelView getCustomizedProductsModelView = new core.application.CommercialCatalogueController().findCatalogueCollectionProducts(findCatalogueCollectionModelView); return(Ok(getCustomizedProductsModelView)); } catch (ResourceNotFoundException e) { return(NotFound(new SimpleJSONMessageService(e.Message))); } catch (Exception) { return(StatusCode(500, new SimpleJSONMessageService(UNEXPECTED_ERROR))); } }
/// <summary> /// Retrieves a specific CatalogueCollection from the CommercialCatalogue. /// </summary> /// <param name="findCatalogueCollectionModelView">FindCatalogueCollectionModelView with the CommercialCatalogue's and CatalogueCollection's identifiers.</param> /// <returns>An instance of GetCatalogueCollectionModelView representing the CatalogueCollection.</returns> /// <exception cref="ResourceNotFoundException"> /// Thrown when no instance of CommercialCatalogue or CatalogueCollection are found with the given identifiers. /// </exception> public GetCatalogueCollectionModelView findCatalogueCollection(FindCatalogueCollectionModelView findCatalogueCollectionModelView) { CommercialCatalogueRepository catalogueRepository = PersistenceContext.repositories().createCommercialCatalogueRepository(); CommercialCatalogue commercialCatalogue = catalogueRepository.find(findCatalogueCollectionModelView.commercialCatalogueId); if (commercialCatalogue == null) { throw new ResourceNotFoundException(string.Format(CATALOGUE_NOT_FOUND_BY_ID, findCatalogueCollectionModelView.commercialCatalogueId)); } CatalogueCollection catalogueCollection = commercialCatalogue.catalogueCollectionList .Where(cc => cc.customizedProductCollectionId == findCatalogueCollectionModelView.customizedProductCollectionId).SingleOrDefault(); if (catalogueCollection == null) { throw new ResourceNotFoundException(string.Format( CATALOGUE_COLLECTION_NOT_FOUND_BY_ID, findCatalogueCollectionModelView.commercialCatalogueId, findCatalogueCollectionModelView.customizedProductCollectionId) ); } return(CatalogueCollectionModelViewService.fromEntity(catalogueCollection)); }