Beispiel #1
0
        /// <summary>
        /// Updates a customized product collection's basic information
        /// </summary>
        /// <param name="modelView">model view with the updates for a customized product collection</param>
        /// <returns>Updated customized product collection or throws an exception if an error occurs</returns>
        public static CustomizedProductCollection update(UpdateCustomizedProductCollectionModelView modelView)
        {
            CustomizedProductCollectionRepository customizedProductCollectionRepository =
                PersistenceContext.repositories()
                .createCustomizedProductCollectionRepository();


            CustomizedProductCollection customizedProductCollection =
                customizedProductCollectionRepository.find(modelView.customizedProductCollectionId);

            checkIfCustomizedProductCollectionWasFound(
                customizedProductCollection, modelView.customizedProductCollectionId
                );

            customizedProductCollection.changeName(modelView.name);

            CustomizedProductCollection updatedCustomizedProductCollection =
                customizedProductCollectionRepository.update(customizedProductCollection);

            checkIfUpdatedCustomizedProductCollectionWasSaved(
                updatedCustomizedProductCollection, modelView.customizedProductCollectionId
                );

            return(updatedCustomizedProductCollection);
        }
        /// <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));
            }
        }
Beispiel #3
0
        /// <summary>
        /// Deletes a customized product from a customized product collection
        /// </summary>
        /// <param name="modelView"> model view with the necessary information to perform the request</param>
        public static void delete(DeleteCustomizedProductFromCustomizedProductCollectionModelView modelView)
        {
            CustomizedProductCollectionRepository customizedProductCollectionRepository =
                PersistenceContext.repositories()
                .createCustomizedProductCollectionRepository();

            CustomizedProductCollection customizedProductCollection =
                customizedProductCollectionRepository.find(modelView.customizedProductCollectionId);

            checkIfCustomizedProductCollectionWasFound(customizedProductCollection, modelView.customizedProductCollectionId);

            CustomizedProduct customizedProduct =
                PersistenceContext.repositories()
                .createCustomizedProductRepository()
                .find(modelView.customizedProductId);

            if (customizedProduct == null)
            {
                throw new ArgumentException(
                          string.Format(
                              UNABLE_TO_FIND_CUSTOMIZED_PRODUCT,
                              modelView.customizedProductId)
                          );
            }

            customizedProductCollection.removeCustomizedProduct(customizedProduct);

            customizedProductCollectionRepository.update(customizedProductCollection);
        }
Beispiel #4
0
        /// <summary>
        /// Deactivates a customized product collection
        /// </summary>
        /// <param name="modelView"> model view with the necessary information to deactivate a customized product collection</param>
        public static void deactivate(DeleteCustomizedProductCollectionModelView modelView)
        {
            CustomizedProductCollectionRepository customizedProductCollectionRepository =
                PersistenceContext.repositories()
                .createCustomizedProductCollectionRepository();

            CustomizedProductCollection customizedProductCollection =
                customizedProductCollectionRepository.find(modelView.customizedProductCollectionId);

            checkIfCustomizedProductCollectionWasFound(customizedProductCollection, modelView.customizedProductCollectionId);

            customizedProductCollectionRepository.remove(customizedProductCollection);
        }
        /// <summary>
        /// Creates an instance of CatalogueCollection with the data in the given AddCatalogueCollectionModelView.
        /// </summary>
        /// <param name="addCatalogueCollectionModelView">AddCatalogueCollectionModelView with the CatalogueCollection's data.</param>
        /// <returns>An instance of CatalogueCollection.</returns>
        /// <exception cref="System.ArgumentException">
        /// Thrown when no CustomizedProductCollection or CustomizedProduct could be found with the provided identifiers.
        /// </exception>
        public static CatalogueCollection create(AddCatalogueCollectionModelView addCatalogueCollectionModelView)
        {
            CustomizedProductCollectionRepository collectionRepository = PersistenceContext.repositories().createCustomizedProductCollectionRepository();

            CustomizedProductCollection customizedProductCollection = collectionRepository.find(addCatalogueCollectionModelView.customizedProductCollectionId);

            if (customizedProductCollection == null)
            {
                throw new ArgumentException(string.Format(CUSTOMIZED_PRODUCT_COLLECTION_NOT_FOUND, addCatalogueCollectionModelView.customizedProductCollectionId));
            }

            CatalogueCollection catalogueCollection = null;

            //check if any customized product was defined
            if (addCatalogueCollectionModelView.customizedProductIds.Any())
            {
                IEnumerable <long> customizedProductIds = addCatalogueCollectionModelView.customizedProductIds.Select(cp => cp.customizedProductId).ToList();

                List <CustomizedProduct> customizedProducts = new List <CustomizedProduct>();

                foreach (long customizedProductId in customizedProductIds)
                {
                    CustomizedProduct customizedProduct = customizedProductCollection.collectionProducts
                                                          .Where(cp => cp.customizedProductId == customizedProductId)
                                                          .Select(cp => cp.customizedProduct).SingleOrDefault();

                    if (customizedProduct == null)
                    {
                        throw new ArgumentException(string.Format(
                                                        CUSTOMIZED_PRODUCT_NOT_FOUND_IN_COLLECTION, customizedProductId, addCatalogueCollectionModelView.customizedProductCollectionId)
                                                    );
                    }

                    customizedProducts.Add(customizedProduct);
                }

                catalogueCollection = new CatalogueCollection(customizedProductCollection, customizedProducts);
            }
            else
            {
                catalogueCollection = new CatalogueCollection(customizedProductCollection);
            }

            return(catalogueCollection);
        }
Beispiel #6
0
 /// <summary>
 /// This constructor is only here due to entity framework injection
 /// </summary>
 /// <param name="customizedProductCollectionRepository">Injected repository of customized products collections</param>
 /// <param name="customizedProductRepository">Injected repository of customized products</param>
 public CustomizedProductCollectionController(CustomizedProductCollectionRepository customizedProductCollectionRepository,
                                              CustomizedProductRepository customizedProductRepository)
 {
     this.customizedProductCollectionRepository = customizedProductCollectionRepository;
     this.customizedProductRepository           = customizedProductRepository;
 }
Beispiel #7
0
        /// <summary>
        /// Transforms a CommercialCatalogueDTO into a CommercialCatalogue.
        /// </summary>
        /// <param name="commercialCatalogueDTO">CommercialCatalogueDTO with the CommercialCatalogue data.</param>
        /// <returns>Transformed CommercialCatalogue built with CommercialCatalogueDTO info.</returns>
        public static CommercialCatalogue transform(CommercialCatalogueDTO commercialCatalogueDTO)
        {
            string reference   = commercialCatalogueDTO.reference;
            string designation = commercialCatalogueDTO.designation;

            CommercialCatalogue newComCatalogue = null;

            //if no collections are specified, build a catalogue with just the given reference and designation.
            if (commercialCatalogueDTO.catalogueCollectionDTOs != null)
            {
                CustomizedProductCollectionRepository collectionRepository = PersistenceContext.repositories().createCustomizedProductCollectionRepository();

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

                //the specified collections should have id's and not the whole collection information

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

                foreach (CatalogueCollectionDTO collectionDTO in commercialCatalogueDTO.catalogueCollectionDTOs)
                {
                    CatalogueCollection         catalogueCollection = null;
                    CustomizedProductCollection collection          = collectionRepository.find(collectionDTO.customizedProductCollectionDTO.id);

                    //the collection was not found
                    if (collection == null)
                    {
                        throw new ArgumentException(ERROR_CUSTOMIZED_PRODUCT_COLLECTION_NOT_FOUND);
                    }

                    //if no products are specified, then add all contained in the collection
                    if (collectionDTO.customizedProductDTOs == null)
                    {
                        catalogueCollection = new CatalogueCollection(collection);
                    }
                    else
                    {
                        List <CustomizedProduct> customizedProducts = new List <CustomizedProduct>();

                        foreach (CustomizedProductDTO customizedProductDTO in collectionDTO.customizedProductDTOs)
                        {
                            CustomizedProduct customizedProduct = customizedProductRepository.find(customizedProductDTO.id);

                            //the product was not found
                            if (customizedProduct == null)
                            {
                                throw new ArgumentException(ERROR_CUSTOMIZED_PRODUCT_NOT_FOUND);
                            }

                            customizedProducts.Add(customizedProduct);
                        }

                        catalogueCollection = new CatalogueCollection(collection, customizedProducts);
                    }

                    catalogueCollections.Add(catalogueCollection);
                }

                newComCatalogue = new CommercialCatalogue(reference, designation, catalogueCollections);
            }
            else
            {
                newComCatalogue = new CommercialCatalogue(reference, designation);
            }

            return(newComCatalogue);
        }