/// <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); }
public ActionResult removeCustomizedProductFromCustomizedProductCollection(long collectionID, long customizedProductID) { try { DeleteCustomizedProductFromCustomizedProductCollectionModelView modelView = new DeleteCustomizedProductFromCustomizedProductCollectionModelView(); modelView.customizedProductCollectionId = collectionID; modelView.customizedProductId = customizedProductID; new core.application.CustomizedProductCollectionController().removeCustomizedProductFromCustomizedProductCollection(modelView); return(NoContent()); } catch (ArgumentException argumentException) { return(NotFound(new SimpleJSONMessageService(argumentException.Message))); } catch (ResourceNotFoundException resourceNotFoundException) { return(NotFound(new SimpleJSONMessageService(resourceNotFoundException.Message))); } catch (Exception) { return(StatusCode(500, new SimpleJSONMessageService(UNEXPECTED_ERROR))); } }
/// <summary> /// Removes a customized product from a customized product collection /// </summary> /// <param name="collectionID">ID of the customized product collection to update</param> /// <param name="customizedProductID">ID of the customized product to remove</param> /// <returns>boolean true if the customized product was successfully removed, false if not</returns> public void removeCustomizedProductFromCustomizedProductCollection(DeleteCustomizedProductFromCustomizedProductCollectionModelView modelView) { DeleteCustomizedProductCollectionService.delete(modelView); }