Example #1
0
        /// <summary>
        /// Retrieves an instance of CommercialCatalogue stored in the repository with a matching identifier.
        /// </summary>
        /// <param name="findCommercialCatalogueModelView">FindCommercialCatalogueModelView with the identifier.</param>
        /// <returns>Instance of GetCommercialCatalogueModelView representing the instance of CommercialCatalogue.</returns>
        /// <exception cref="ResourceNotFoundException">Thrown when no instance of CommercialCatalogue is found with a matching identifier.</exception>
        public GetCommercialCatalogueModelView findCommercialCatalogue(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));
            }

            return(CommercialCatalogueModelViewService.fromEntity(commercialCatalogue));
        }
Example #2
0
        /// <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));
        }
Example #3
0
        public ActionResult findById(long id)
        {
            try
            {
                FindCommercialCatalogueModelView findCommercialCatalogueModelView = new FindCommercialCatalogueModelView();
                findCommercialCatalogueModelView.commercialCatalogueId = id;

                GetCommercialCatalogueModelView getCommercialCatalogueModelView = new core.application.CommercialCatalogueController().findCommercialCatalogue(findCommercialCatalogueModelView);

                return(Ok(getCommercialCatalogueModelView));
            }
            catch (ResourceNotFoundException e)
            {
                return(NotFound(new SimpleJSONMessageService(e.Message)));
            }
            catch (Exception)
            {
                return(StatusCode(500, new SimpleJSONMessageService(UNEXPECTED_ERROR)));
            }
        }