/// <summary>
        /// Creates a new instance of CommercialCatalogue with the data in the given instance of AddCommercialCatalogueModelView.
        /// </summary>
        /// <param name="addCommercialCatalogueModelView">AddCommercialCatalogueModelView with the CommercialCatalogue's data.</param>
        /// <returns>An instance of CommercialCatalogue.</returns>
        /// <exception cref="System.ArgumentException">
        /// Thrown when no CustomizedProductCollection or CustomizedProduct could be found with the provided identifiers.
        /// </exception>
        public static CommercialCatalogue create(AddCommercialCatalogueModelView addCommercialCatalogueModelView)
        {
            string reference   = addCommercialCatalogueModelView.reference;
            string designation = addCommercialCatalogueModelView.designation;

            //check if catalogue collections were specified
            if (!addCommercialCatalogueModelView.catalogueCollections.Any())
            {
                return(new CommercialCatalogue(reference, designation));
            }
            else
            {
                //create repositories so that customized products and collections can be fetched
                CustomizedProductCollectionRepository customizedProductCollectionRepository = PersistenceContext
                                                                                              .repositories().createCustomizedProductCollectionRepository();

                CustomizedProductRepository customizedProductRepository = PersistenceContext.repositories()
                                                                          .createCustomizedProductRepository();

                List <CatalogueCollection> catalogueCollections = new List <CatalogueCollection>();

                foreach (AddCatalogueCollectionModelView addCatalogueCollectionModelView in addCommercialCatalogueModelView.catalogueCollections)
                {
                    CatalogueCollection catalogueCollection = CreateCatalogueCollectionService.create(addCatalogueCollectionModelView);

                    catalogueCollections.Add(catalogueCollection);
                }

                return(new CommercialCatalogue(reference, designation, catalogueCollections));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds a CommercialCatalogue.
        /// </summary>
        /// <param name="addCommercialCatalogueModelView">AddCommercialCatalogueModelView with the data used for creating the CommercialCatalogue.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentException">
        /// Thrown when no CustomizedProductCollection or CustomizedProduct could be found with the provided identifiers or when the CommercialCatalogue can't be saved.
        /// </exception>
        public GetCommercialCatalogueModelView addCommercialCatalogue(AddCommercialCatalogueModelView addCommercialCatalogueModelView)
        {
            CommercialCatalogue commercialCatalogue = CreateCommercialCatalogueService.create(addCommercialCatalogueModelView);

            CommercialCatalogueRepository catalogueRepository = PersistenceContext.repositories().createCommercialCatalogueRepository();

            commercialCatalogue = catalogueRepository.save(commercialCatalogue);

            //an error occurred while saving the catalogue
            if (commercialCatalogue == null)
            {
                throw new ArgumentException(UNABLE_TO_SAVE_CATALOGUE);
            }

            return(CommercialCatalogueModelViewService.fromEntity(commercialCatalogue));
        }
Ejemplo n.º 3
0
        public ActionResult addCommercialCatalogue([FromBody] AddCommercialCatalogueModelView addCommercialCatalogueModelView)
        {
            if (addCommercialCatalogueModelView == null)
            {
                return(BadRequest(new SimpleJSONMessageService(INVALID_REQUEST_BODY_MESSAGE)));
            }

            try
            {
                GetCommercialCatalogueModelView getCommercialCatalogueModelView = new core.application.CommercialCatalogueController()
                                                                                  .addCommercialCatalogue(addCommercialCatalogueModelView);

                return(CreatedAtRoute("GetCommercialCatalogue", new { id = getCommercialCatalogueModelView.commercialCatalogueId }, getCommercialCatalogueModelView));
            }
            catch (ArgumentException e)
            {
                return(BadRequest(new SimpleJSONMessageService(e.Message)));
            }
            catch (Exception)
            {
                return(StatusCode(500, new SimpleJSONMessageService(UNEXPECTED_ERROR)));
            }
        }