Exemple #1
0
        /// <summary>
        /// Updates a customized product collection by adding a new customized product to it
        /// </summary>
        /// <param name="modelView">model view with the necessary update information</param>
        /// <returns>Updated customized product collection or throws an exception if an error occurs</returns>
        public static CustomizedProductCollection update(AddCustomizedProductToCustomizedProductCollectionModelView 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.addCustomizedProduct(customizedProduct);

            CustomizedProductCollection updatedCustomizedProductCollection =
                customizedProductCollectionRepository.update(customizedProductCollection);

            checkIfUpdatedCustomizedProductCollectionWasSaved(
                updatedCustomizedProductCollection, modelView.customizedProductCollectionId
                );

            return(updatedCustomizedProductCollection);
        }
Exemple #2
0
        /// <summary>
        /// Adds a customized product to the customized product collection
        /// </summary>
        /// <param name="modelView">UpdateCustomizedProductCollectionDTO with the customized product collection information</param>
        /// <returns>boolean true if the customized product was successfully added, false if not</returns>
        public GetCustomizedProductCollectionModelView addCustomizedProductToCustomizedProductCollection(AddCustomizedProductToCustomizedProductCollectionModelView modelView)
        {
            CustomizedProductCollection updatedCustomizedProductCollection = UpdateCustomizedProductCollectionService.update(modelView);

            return(CustomizedProductCollectionModelViewService.fromEntity(updatedCustomizedProductCollection));
        }
Exemple #3
0
        public ActionResult addCustomizedProductsToCustomizedProductCollection(long id, [FromBody] AddCustomizedProductToCustomizedProductCollectionModelView addCustomizedProductToCustomizedProductCollectionModelView)
        {
            if (addCustomizedProductToCustomizedProductCollectionModelView == null)
            {
                return(BadRequest(new SimpleJSONMessageService(INVALID_REQUEST_BODY_MESSAGE)));
            }

            try
            {
                addCustomizedProductToCustomizedProductCollectionModelView.customizedProductCollectionId = id;
                GetCustomizedProductCollectionModelView updatedCustomizedProductCollectionModelView = new core.application.CustomizedProductCollectionController().addCustomizedProductToCustomizedProductCollection(addCustomizedProductToCustomizedProductCollectionModelView);

                return(Created(Request.Path, updatedCustomizedProductCollectionModelView));
            }
            catch (ResourceNotFoundException resourceNotFoundException)
            {
                return(NotFound(new SimpleJSONMessageService(resourceNotFoundException.Message)));
            }
            catch (InvalidOperationException invalidOperationException)
            {
                return(BadRequest(new SimpleJSONMessageService(invalidOperationException.Message)));
            }
            catch (ArgumentException argumentException)
            {
                return(BadRequest(new SimpleJSONMessageService(argumentException.Message)));
            }
            catch (Exception)
            {
                return(StatusCode(500, new SimpleJSONMessageService(UNEXPECTED_ERROR)));
            }
        }