Exemple #1
0
        public ActionResult addCustomizedProductCollection([FromBody] AddCustomizedProductCollectionModelView addCustomizedProductCollectionModelView)
        {
            if (addCustomizedProductCollectionModelView == null)
            {
                return(BadRequest(new SimpleJSONMessageService(INVALID_REQUEST_BODY_MESSAGE)));
            }

            try
            {
                GetCustomizedProductCollectionModelView createdCustomizedProductCollection = new core.application.CustomizedProductCollectionController().addCollection(addCustomizedProductCollectionModelView);
                return(Created(Request.Path, createdCustomizedProductCollection));
            }
            catch (InvalidOperationException invalidOperationException)
            {
                return(BadRequest(new SimpleJSONMessageService(invalidOperationException.Message)));
            }
            catch (ArgumentException invalidArgumentsException)
            {
                return(BadRequest(new SimpleJSONMessageService(invalidArgumentsException.Message)));
            }
            catch (Exception)
            {
                return(StatusCode(500, new SimpleJSONMessageService(UNEXPECTED_ERROR)));
            }
        }
        /// <summary>
        /// Creates a customized product collection
        /// </summary>
        /// <param name="modelView"> model view with the information about the customized product collection to create</param>
        /// <returns>newly created customized product collection or throws exceptions if an error occurs</returns>
        public static CustomizedProductCollection create(AddCustomizedProductCollectionModelView modelView)
        {
            if (Collections.isEnumerableNullOrEmpty(modelView.customizedProducts))
            {
                CustomizedProductCollection customizedProductCollection =
                    new CustomizedProductCollection(modelView.name);

                return(PersistenceContext.repositories()
                       .createCustomizedProductCollectionRepository()
                       .save(customizedProductCollection));
            }
            else
            {
                List <CustomizedProduct> customizedProducts =
                    new List <CustomizedProduct>();

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

                foreach (GetBasicCustomizedProductModelView customizedProductModelView in modelView.customizedProducts)
                {
                    CustomizedProduct customizedProduct =
                        customizedProductRepository.find(customizedProductModelView.customizedProductId);

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

                    customizedProducts.Add(customizedProduct);
                }

                CustomizedProductCollection customizedProductCollection =
                    new CustomizedProductCollection(modelView.name, customizedProducts);

                return(PersistenceContext.repositories()
                       .createCustomizedProductCollectionRepository()
                       .save(customizedProductCollection));
            }
        }
Exemple #3
0
        /// <summary>
        /// Adds a new customized products collection
        /// </summary>
        /// <param name="modelView">CustomizedProductCollectionDTO with the customized product collection information</param>
        /// <returns>CustomizedProductCollectionDTO with the created customized product collection information</returns>
        public GetCustomizedProductCollectionModelView addCollection(AddCustomizedProductCollectionModelView modelView)
        {
            CustomizedProductCollection customizedProductCollection = CreateCustomizedProductCollectionService.create(modelView);

            return(CustomizedProductCollectionModelViewService.fromEntity(customizedProductCollection));
        }